var lining;
var padding = 20;

$(document).ready(function() {
	$("a.gallery-picture").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'imageScale': true,
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'frameWidth': 800,
		'frameHeight': 600
	}); 	
	$("a.iframe").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'imageScale': true,
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'frameWidth': 800,
		'frameHeight': 343
	}); 	
});


function init() {
	onresize = resizeHandler;
	resizeHandler();
}

function resizeHandler() {
	adjustLining();
	adjustSectionPage();
}

function adjustLining() {
	lining = $("#bottom-lining");
	if(!lining) return;
	
	lining.css({
		"margin-top" : "20px",
		"position" : "static"
	});
	
	if($("#page").height() < $(window).height()) {
		lining.css({
			"margin-top" : "0px",
			"position" : "absolute",
			"top": $(window).height() - lining.height() + "px"
		});
	}
	
}

function adjustSectionPage() {
	var paddingTop = 17;
	var paddingBottom = 17;
	
	sectionPage = $("#section-page");
	sectionPage.css("height", $("#section-content").height() - paddingTop - paddingBottom - 2 + "px");
	
	var h;
	
	while($("#page").height() < $(window).height() - lining.height() - padding) {
		h = Number(sectionPage.css("height").substr(0, sectionPage.css("height").length - 2));
		sectionPage.css("height", Number(h + 2) + "px");
	}
}

function number(str) {
	return Number(str.substr(0, str.length - 2));
}
