$(window).resize(function() {
	WindowResize(); 
	if($("#gal_foto img").length) { PozycjaGaleria(); }
	if($("img.main_img").length) { SkalujZdjecie(); }
});	
$(document).ready(function() { 
	WindowResize(); 
	if($("#gal_foto img").length) { PozycjaGaleria(); }
});	
	function WindowResize()
	{
		if($("#kontener").height()<701) { $("#kontener").css("height",701); }
		else { $("#kontener").css("height","100%"); }
		$("#bottom").css("top",$("#kontener").height()-$("#bottom").height());
		$("#bottom_powrot").css("top",$("#kontener").height()-$("#bottom_powrot").height()-1);
		$("#gal_control").css("top",$("#kontener").height()-$("#gal_control").height());
		
		var gal_control_w = $(document).width();
		if($("#fb").length!=0) gal_control_w = gal_control_w - 81;
		$("#gal_control").css("width",gal_control_w);
	}
	
	function SkalujZdjecie()
	{
		w=$("#kontener").outerWidth();
		h=$("#kontener").outerHeight();
		wim=$("img.main_img").width(); 
		him=$("img.main_img").height();
		neww=w;
		newhh=h;
		//oblicz nowa wysokosc
		temph=Math.ceil(him*w/wim);
		if(temph<h)	//brakuje na wysokosci czyli rozciagamy..
		{
			newh=h;
			neww=Math.ceil(wim*h/him);
		}
		else
		{
			newh=temph;
			neww=Math.ceil(wim*temph/him);
		}
		$("img.main_img").css("height",newh).css("width",neww);
	}
	function PozycjaGaleria()
	{
		if($("#gal_foto img").length)
		{
			var top=Math.floor(($("#gal_foto").outerHeight()-65-$("#gal_foto img").height())/2); 
			$("#gal_foto img").css("top",top );
		}
	}
