var footerPadding = 22;

$(document).ready(function() {
	$("a.product-gallery").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'imageScale': true,
		'overlayShow': true,
		'overlayOpacity': 0.8
	});
	
	$("a.iframe").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'imageScale': true,
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'frameWidth': 800,
		'frameHeight': 343
	});
	
	$("a.video").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'imageScale': true,
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'frameWidth': 425,
		'frameHeight': 344
	});
	
	$(".external").attr("target", "_blank");
});

function init() {
	onresize = resizeHandler;
	resizeHandler();
	initContactForm();
}

function resizeHandler() {
	adjustPaper();
	adjustFooter();
}

function clickFancyboxLink(id) {
	$('#' + id).trigger('click');
}

function adjustPaper() {
	var yOffset = 142;
	
	var paper = $("#paper");
	if(paper.height() == null) return;
	
	var paperHeight = $(window).height() - yOffset - footerPadding - $("#footer").height() - 4;
	if(paper.height() >= paperHeight) {
		paper.css({ "height": "100%" });
		return;
	}
	
	paper.css({ "height": paperHeight + "px" });
}

function adjustFooter() {
	var yOffset = 69;
	var footer = $("#footer");
	if(footer.height() == null) return;
	
	var pos = "absolute";
	if(isFuckingIE()) {
		pos = "fixed";
	}
	
	footer.css({
		"margin-top" : footerPadding + "px",
		"position" : "static"
	});
	
	if(yOffset + $("#page-i").height() + footer.height() + footerPadding < $(window).height()) {
		footer.css({
			"margin-top" : "0px",
			"position" : pos,
			"top": $(window).height() - footer.height() + "px"
		});
	}
}

function highlightForkBox(box) {
	box.setAttribute("class", "fork-box fork-box-highlight");
	box.setAttribute("className", "fork-box fork-box-highlight");
}

function unhighlightForkBox(box) {
	box.setAttribute("class", "fork-box");
	box.setAttribute("className", "fork-box");
}

function isFuckingIE() {
	if(jQuery.browser.msie) {
		if(jQuery.browser.version == 6 || jQuery.browser.version == 7) {
			return true;
		}
	}
	return false;
}

