$(document).ready(function() {
	
	//alert($(document).width());
	
	$("#claudius_bg,#wrapper,#video_bg,#loader").width($(document).width());
	$("#claudius_bg,#wrapper,#video_bg,#loader").height($(document).height());

	$("#video_bg").height($(document).height()+50);
	
	var szer = parseInt(2560-$(document).width())/2;
	var wys = parseInt(1440-$(document).height())/2;
		$("#video_bg div").css("left","-"+szer+"px");
		$("#video_bg div").css("top","-"+wys+"px");
	
		
		
	/*	
	$f("video_bg", {
		src: "lib/flowplayer/flowplayer-3.2.7.swf",
		wmode: "opaque",
		quality: "low"
	}, {
    	playlist: [
        	{
            	url: "bg/sixtpreist_3.f4v",
            	scaling: 'scale',
            	autoPlay: true,
				loop: true,
				bufferLength: 10,
				onStart: function() {
					$("#loader").fadeOut(350);
				},
				onBeforeFinish: function() { 
					return false; 
				} 
        	}
    	],
		plugins: {
			controls: {
			url: 'lib/flowplayer/flowplayer.controls-3.2.5.swf',
			autoHide: 'always',
			hideDelay: 100
		}
		}
	});
	
	$f("sound_bg", {
		src: "lib/flowplayer/flowplayer-3.2.7.swf",
		wmode: "opaque",
		quality: "low"
	}, {
    	playlist: [
        	{
            	url: "bg/sound.mp3",
            	scaling: 'fit',
            	autoPlay: true,
				loop: true,
				bufferLength: 10,
				onStart: function() {
				},
				onBeforeFinish: function() { 
					return false; 
				} 
        	}
    	],
		plugins: {
			controls: {
			url: 'lib/flowplayer/flowplayer.controls-3.2.5.swf',
			autoHide: 'always',
			hideDelay: 100
		}
		}
	});
	
*/	
	
	/*
	Cufon.replace('.cufont', 
	{ 
		hover: true,
		fontFamily: 'FR Hopper 430'
	});
	*/
	
	$("#sitehead").bind("mouseenter",function() {
		
		$("#sitehead nav").stop(true,false).animate({
			height: "170px"
		},250);
		
		$("#content").animate({
			top: "240px"
		}, 350);
		
		
		
		
	}).bind("mouseleave",function() {
		
		$("#sitehead nav").stop(true,false).animate({
			height: "15px"
		},250);
		
		$("#content").animate({
			top: "110px"
		}, 350);
		
	});
	
	$("#sitehead a").click(function() {
		
		var link = $(this).attr("href").replace("#!/","");
		load_content(link);

	});
	
	$("#mainsite img").click(function() {
		
		var link = $(this).attr("id").replace("_","/");
		load_content(link);
		
	});
	
	
	slide();
		
	
});



function load_content(link) {
	
	dzial = link.split('/');
	if(dzial[0] == 'team' && dzial[1]) {
		dzialMargin = "-163px";
		dzialWidth = "267px";
	} else {
		dzialMargin = "-490px";
		dzialWidth = "920px";
	}
	
	$.get(url_base+"claudius/"+link, function(back){
   		
		$("#content").animate({
			top: $(document).height()+"px",
		}, 250, function() {
			$("#content").html("");
		});
		
		
		setTimeout(function() {
			
			$("#content").animate({
				top: "110px",
				width: dzialWidth,
				marginLeft: dzialMargin
			}, 250, function() {
				$("#content").html(back).fadeIn(500);
			});
			
		},250);
		
		

   		
   		/*
   		$("#content").fadeIn(250);
   		$("#mainsite").fadeOut(250);
   		$("#footer").animate({
   			bottom: "-50px"
   		},200);
   		$("#sitehead").animate({
   			top: "10px"
   		},1200);
   		*/
   		
	});
	
}

function clear_overlay() {
	$("#overlay").html("");	
}

function insert_overlay(id) {
	
	//$("#overlay").append('<img src="'+plik+'" />');
	$("#zoom_"+id).clone().appendTo("#overlay");
	var plik = $("#overlay img").attr('src');
	var plik_rozmiar = getImageSize(plik);
				//$("#overlay img").attr('style','width: '+plik_rozmiar[0]+'px; height: '+plik_rozmiar[1]+'px;');
				$("#overlay img").attr('style','width: 10px; height: 10px;');


	var img_wid = plik_rozmiar[0];
	var img_hei = plik_rozmiar[1];
	var ov_wid = parseInt($("#overlay").css("width"));
	var ov_hei = parseInt($("#overlay").css("height"));
	
	new_x = (img_wid)/2;
	new_y = (img_hei)/2;

	/*
	$("#overlay img").css({
		marginLeft: new_x+"px",
		marginTop: new_y+"px"
	});
	*/
	
	if(img_hei > ov_hei) {
		
		$("#overlay img").css({
			height: ov_hei+"px",
			width: (img_wid/(img_hei/ov_hei))+"px",
			marginLeft: "-"+((img_wid/(img_hei/ov_hei))/2)+"px",
			marginTop: "-"+(ov_hei/2)+"px"
		});
		
	} else {
		
	$("#overlay img").css({
		height: plik_rozmiar[1]+"px",
		width: plik_rozmiar[0]+"px",
		marginLeft: "-"+new_x+"px",
		marginTop: "-"+new_y+"px"
	});
		
	}
	
}


function getImageSize(src) {
	
    var imageObject = new Image();
        imageObject.src = src;

    //return  'width: '+imageObject.width+'px; height: '+imageObject.height+'px;';
    var back = new Array(imageObject.width,imageObject.height);
    return back;
    
}



function slide() {
	var akt = parseInt($("#video_bg .on").attr("id").replace("fotobg_",""));
	var next_akt = (akt+1 <= 7) ? akt+1 : 1;
	
	setTimeout(function() {
		
		$("#fotobg_"+akt).animate({
			opacity: 0
		},2500).removeClass("on");
		
		$("#fotobg_"+next_akt).animate({
			opacity: 1			
		},2500).addClass("on");
		
		setTimeout(function() {
			slide();
		},2500);
	},8000);
	
}

