//-----------------------------------------//
//Autor: Tomasz Czado
//Adres: tomaszczado@gmail.com
//Data: 14.06.2009
//COPYRIGHT
//NIE usuwaj tego komentarza! (Do NOT remove this comment!)
//-----------------------------------------//

function loadClickWindow(picture)
{
	jQuery("#lightboxBackground").fadeTo("fast", 0.0);
	setTimeout( function(){ showWindow(picture);},300);
}

function loadClickWindowPress(picture)
{
	jQuery("#lightboxBackground").fadeTo("fast", 0.0);
	setTimeout( function(){ showWindowPress(picture);},300);
}

// aktualny rozmiar okna
function windowSize()
{
	var b=document.body, e=document.documentElement;
	var esw=0, eow=0, bsw=0, bow=0, esh=0, eoh=0, bsh=0, boh=0, yScroll=0, xScroll=0;
	var scrollTop=0;
	if (e) {
		esw = e.scrollWidth;
		eow = e.offsetWidth;
		esh = e.scrollHeight;
		eoh = e.offsetHeight;
	}
	if (b) {
		bsw = b.scrollWidth;
		bow = b.offsetWidth;
		bsh = b.scrollHeight;
		boh = b.offsetHeight;
	}
	
	if(e.scrollTop>0) scrollTop=e.scrollTop;
	else if(b.scrollTop>0) scrollTop=b.scrollTop;
	
	//sprawdzamy czy zawartosc strony nie jest zbyt mala do poprawnego wyswietlenia lightboxa w calym oknie przegladarki. W przypadku prawdy, jako
	//wysokosc zwracamy rozdzielczosc
	if(esh<screen.height) esh=screen.height;
	
	//1 - szerokosc zawartosci okna
	//2 - wysokosc zawartosci okna
	//3 - odleglosc od top dla IE
	var result = new Array(esw/*1*/,eow,bsw,bow,esh+20/*2*/,eoh,bsh,boh,scrollTop);
	return result;
}

function showWindow(picture)
{
	var size = new Array();
	size = windowSize();
	
	jQuery("#lightboxBackground").css("width",size[0]+"px");
	jQuery("#lightboxBackground").css("height",size[4]+"px");
	jQuery("#lightboxBackground").css("display","block");
	jQuery("#lightboxBackground").fadeTo("fast", 0.7);
	jQuery("#lightboxContent").css("display","block");
	
	setTimeout(function(){
		jQuery("#lightboxContentCert img").load(function(){
			var width = jQuery(this).width();
			var height = jQuery(this).height();
			jQuery("#lightboxContentCert").css({"height": height});
			jQuery("#lightboxContent").css({"height": (height+80)});
			setTimeout(function(){ jQuery("#lightboxContentCert img").animate({opacity: 'show'}, 500)}, 500);
			
			var agent = navigator.userAgent.toLowerCase();
			if(agent.indexOf('msie') != -1){
				var tab1 = agent.split(";");
				var tab2 = tab1[1].split("msie ");
				if (parseInt(tab2[1])<=6){  // Explorer 6 Strict
					setTimeout(function(){
						jQuery("#lightboxContentHead").html("<span onclick=\"closeWindow();\"><img alt=\"\" src=\"/files/framework/zamknij.png\"/></span>").pngFix()
						jQuery("#lightboxContentCert").html("<img alt=\""+picture+"\" src=\"/files/framework/certificate/"+picture+"\"/>").pngFix();
					}, 1000);
				} else {
					setTimeout(function(){ jQuery("#lightboxContentHead").html("<span onclick=\"closeWindow();\"><img alt=\"\" src=\"/files/framework/zamknij.png\"/></span>")}, 1000);
				}
			} else {
				setTimeout(function(){ jQuery("#lightboxContentHead").html("<span onclick=\"closeWindow();\"><img alt=\"\" src=\"/files/framework/zamknij.png\"/></span>")}, 1000);
			}
		}).attr({src: "/files/framework/certificate/"+picture,alt:picture})
	}, 1500);
	updateWindow();
}

function showWindowPress(picture)
{
	var size = new Array();
	size = windowSize();
	
	jQuery("#lightboxBackground").css("width",size[0]+"px");
	jQuery("#lightboxBackground").css("height",size[4]+"px");
	jQuery("#lightboxBackground").css("display","block");
	jQuery("#lightboxBackground").fadeTo("fast", 0.7);
	jQuery("#lightboxContentPress").css({"display":"block","marginTop": (size[8]+200)+"px"});
	
	setTimeout(function(){
		jQuery("#lightboxContentCertPress img").load(function(){
			var width = jQuery(this).width();
			var height = jQuery(this).height();
			setTimeout(function(){ jQuery("#lightboxContentCertPress img").animate({opacity: 'show'}, 500)}, 500);
			
			var agent = navigator.userAgent.toLowerCase();
			if(agent.indexOf('msie') != -1){
				var tab1 = agent.split(";");
				var tab2 = tab1[1].split("msie ");
				if (parseInt(tab2[1])<=6){  // Explorer 6 Strict
					setTimeout(function(){
						jQuery("#lightboxContentHeadPress").html("<span onclick=\"closeWindowPress();\"><img alt=\"\" src=\"/files/framework/zamknij.png\"/></span>").pngFix()
					}, 1000);
				} else {
					setTimeout(function(){ jQuery("#lightboxContentHeadPress").html("<span onclick=\"closeWindowPress();\"><img alt=\"\" src=\"/files/framework/zamknij.png\"/></span>")}, 1000);
				}
			} else {
				setTimeout(function(){ jQuery("#lightboxContentHeadPress").html("<span onclick=\"closeWindowPress();\"><img alt=\"\" src=\"/files/framework/zamknij.png\"/></span>")}, 1000);
			}
		}).attr({src: "/files/framework/press/"+picture,alt:picture})
	}, 1500);
	updateWindow();
}

function updateWindow()
{
	var size = new Array();
	size = windowSize();
	
	setTimeout( function() {
		if(jQuery("#lightboxBackground").width()!=size[0] || jQuery("#lightboxBackground").height()!=size[4])
		jQuery("#lightboxBackground").css("width",size[0]+"px");
		jQuery("#lightboxBackground").css("height",size[4]+"px");
		//updateWindow();
	}, 5000);
}

function closeWindow()
{
	jQuery("#lightboxContent img").stop();
	jQuery("#lightboxContent").stop();
	jQuery("#lightboxBackground").stop();
	
	jQuery("#lightboxContentHead").html("");
	jQuery("#lightboxContent").css("display","none");
	jQuery("#lightboxBackground").fadeTo("fast", 0.0);
	setTimeout( function() {
		jQuery("#lightboxBackground").css("display","none");
		jQuery("#lightboxContentCert").html("<img src=\"\" alt=\"\" />").css({"height": "0px"});
		jQuery("#lightboxContentCert img").css({"display": "none"});
		jQuery("#lightboxContent").css({"height": "200px"});
	}, 200);
}

function closeWindowPress()
{
	jQuery("#lightboxContentPress img").stop();
	jQuery("#lightboxContentPress").stop();
	jQuery("#lightboxBackground").stop();
	
	jQuery("#lightboxContentHeadPress").html("");
	jQuery("#lightboxContentPress").css("display","none");
	jQuery("#lightboxBackground").fadeTo("fast", 0.0);
	setTimeout( function() {
		jQuery("#lightboxBackground").css("display","none");
		jQuery("#lightboxContentCertPress img").css({"display": "none"});
	}, 200);
}
