<!--

var lightbox = 
{
	n : "lightbox",
	images : new Array(),
	rel : 'lightbox',
	prefix : 'sdfhjl893_',
	
	imgLoadSrc : 'lightbox/loading.gif',
	imgLeftSrc : 'lightbox/pic_arr_left.png',
	imgRightSrc : 'lightbox/pic_arr_right.png',
	imgClose : 'lightbox/pic_close.png',

	useGraphics : 1,	//grafiki do za³adowania szablonu ramki, false, lub 1,2,3....
	graphicsDir : "lightbox/graphics/",
	
	actImage : 0,
	isInit : false,
	
	cssName : {
		table : "lightbox_table",
		image : "lightbox_image",
		title : "lightbox_title",
		info : "lightbox_info",
		bg : "lightbox_bg"
	},

	textInfo : "zdjÄ™cie #1 z #2",
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	show : function(n)
	{
		this.tryShow(this.images[n-1].url);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	onArrowClick : function(n)
	{
		var _prev, _next;

		this.closeLightbox(1);

		if(n == 1)
		{
			_next = (this.actImage + 1 == this.images.length)? 0 : this.actImage + 1;
			this.tryShow(this.images[_next].url);
		}
		else if(n == -1)
		{
			_prev = (this.actImage - 1 == -1)? this.images.length-1 :  this.actImage - 1;
			this.tryShow(this.images[_prev].url);
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	tryShow : function(url)
	{
		var ps = this.pageSize();
		var that = this;

		$("#"+this.prefix+"bg").css({width:ps.pageWidth, height:ps.pageHeight, display:'block'});
		$("#"+this.prefix+"loader").css({display:'block', left:ps.windowWidth/2 - 20, top:ps.windowHeight/2 + that.scroll()});
		
		var obj = this.getObjByUrl(url);
		
		$("#"+this.prefix+"table td."+this.cssName.title).html(obj.title);

		$("#"+this.prefix+"image").css("opacity", 0);
		$("#"+this.prefix+"image").attr("src", url);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	onLoadImg : function(hrefObj)
	{

		var src = hrefObj.src;
		var that = this;
		
		$("#"+this.prefix+"loader").css("display", "none");
		
		if (navigator.appVersion.indexOf("MSIE")!=-1)
			this.pause(300);
		
		var ps = this.pageSize();
		var tSize = {width : $("#"+this.prefix+"table").width(), height : $("#"+this.prefix+"table").height()};
		
		$("#"+this.prefix+"table").css({
			display:'block',
			left : Math.round(ps.pageWidth/2 - tSize.width/2),
			top : Math.round(ps.windowHeight/2 - tSize.height/2 + that.scroll())
		});
		
		var a = this.getObjByUrl(src);
		var text;
		
		if(a.i != undefined)
		{
			this.actImage = a.i;
			
			text = this.textInfo.replace("#1", a.i+1);
			text = text.replace("#2", this.images.length);
			
			$("#"+this.prefix+"table td."+this.cssName.info).html(text);
		}

		$("#"+this.prefix+"image").animate({"opacity" : 1});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	closeLightbox : function(x)
	{
		$("#"+this.prefix+"table").css({
			display:'none',
			left : '-10000px',
			top : '-10000px'
		});	
		
		$("#"+this.prefix+"bg").css("display", "none");
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	init : function(n)
	{
		var that = this;
		var href, title;
		//n=1;

		if(this.isInit)
			return;
		else
			this.isInit = true;

		$("a[rel="+this.rel+"]").each(function(){
			
			href = $(this).attr("href");
			title = $(this).attr("title");
			
			that.images.push({url:href, title:title});
			
			$(this).click(function(){
				that.tryShow($(this).attr("href"));
				return false;
			});
		});
			
		
		$("body").prepend('<img id="'+this.prefix+'loader"" src="'+this.imgLoadSrc+'" alt="" style="display:none; position:absolute; left:0, top:0, z-index:1999;">');
		$("body").prepend('<div id="'+this.prefix+'bg" class="'+this.cssName.bg+'" style="display:none; position:absolute; left:0, top:0, z-index:1997; width:100%; height:100%;"></div>');
		
		$("body").prepend(this.getHtmlTable());
		
		$("img#"+this.prefix+"image").load(function(){that.onLoadImg(this)});
		$("img#"+this.prefix+"image").click(function(){that.closeLightbox()});
		
		if(n)
			setTimeout(function(){that.show(1);}, 100);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getObjByUrl : function(url)
	{
		for(var i=0; i<this.images.length; i++)
		{
			if(this.images[i].url == url || this.images[i].url.match(url) || url.match(this.images[i].url))
			{
				var a = this.images[i]
				a.i = i;
				return a;
			}
		}
		return false;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	getHtmlTable : function()
	{
		var tbl = '';
		
		var tblParam = 'id="'+this.prefix+'table" class="'+this.cssName.table+'" cellpadding="0" border="0" cellspacing="0" style="position:absolute; display:none; left:-10000px, top:-10000px; z-index:1998;"';
		
		imgStr = '<a href="#" onclick="return false;"><img src="" id="'+this.prefix+'image" border="0" alt="" class="'+this.cssName.image+'"></a>';
		
		var left = '<a href="#" onclick="'+this.n+'.onArrowClick(-1); return false;"><img src="'+this.imgLeftSrc+'" border="0" id="'+this.prefix+'left"></a>';
		var right = '<a href="#" onclick="'+this.n+'.closeLightbox(); return false;"><img src="'+this.imgClose+'" border="0" id="'+this.prefix+'close"></a>';
		right += '&nbsp;&nbsp;&nbsp;';
		right += '<a href="#" onclick="'+this.n+'.onArrowClick(1); return false;"><img src="'+this.imgRightSrc+'" border="0" id="'+this.prefix+'right"></a>';
		
		if(this.useGraphics)
		{
			var dir = this.graphicsDir + this.useGraphics +'/';
		
			tbl = '<table '+tblParam+'><tr>';
			tbl += '<td><img src="'+dir+'tl.png" alt=""></td>';
			tbl += '<td colspan="4" style="background:url('+dir+'tc.png);"><img src="'+dir+'tc.png" alt=""></td>';
			tbl += '<td><img src="'+dir+'tr.png" alt=""></td>';
			tbl += '</tr><tr>';
			tbl += '<td style="background:url('+dir+'ml.png);"><img src="'+dir+'ml.png" alt=""></td>';
			tbl += '<td colspan="4">'+imgStr+'</td>';
			tbl += '<td style="background:url('+dir+'mr.png);"><img src="'+dir+'mr.png" alt=""></td>';
			tbl += '</tr><tr>';
			tbl += '<td><img src="'+dir+'bl.png" alt=""></td>';
			tbl += '<td align="left" style="background:url('+dir+'bc.png);">'+left+'</td>';
			tbl += '<td style="background:url('+dir+'bc.png);" class="'+this.cssName.title+'"></td>';
			tbl += '<td style="background:url('+dir+'bc.png);" class="'+this.cssName.info+'"></td>';
			tbl += '<td style="background:url('+dir+'bc.png);" align="right">'+right+'</td>';
			tbl += '<td><img src="'+dir+'br.png" alt=""></td>';
			tbl += '</tr></table>';
		}
		else
		{
			tbl += '<table '+tblParam+'><tr>';
			tbl += '<td colspan="4">'+imgStr+'</td>';
			tbl += '</tr><tr>';
			tbl += '<td>'+left+'</td>';
			tbl += '<td class="'+this.cssName.title+'"></td>';
			tbl += '<td class="'+this.cssName.info+'"></td>';
			tbl += '<td align="right">'+right+'</td>';
			tbl += '</tr></table>';
		}
		
		return tbl;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	scroll : function()
	{
		var yScroll;
	
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}
	
		return yScroll;
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	// Core code from - quirksmode.org
	
	pageSize : function()
	{
		var xScroll, yScroll;
		var windowWidth, windowHeight, pageWidth, pageHeight;
	
		if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
		return {pageWidth:pageWidth, pageHeight:pageHeight, windowWidth:windowWidth, windowHeight:windowHeight};
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	//Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602	

	pause : function(numberMillis)
	{
		var now = new Date();
		var exitTime = now.getTime() + numberMillis;
		while (true)
		{
			now = new Date();
			if (now.getTime() > exitTime)
				return;
		}
	}
};

//-->
