<!--

var lightbox = 
{
	n : "lightbox",
	images : new Array(),
	rel : 'lightbox',
	prefix : 'sdfhjl893'+this.rel+'_',
	imgLoadSrc : 'lightbox/loading.gif',
	imgLeftSrc : 'lightbox/left.gif',
	imgRightSrc : 'lightbox/right.gif',
	actImage : 0,
	isInit : false,

	textInfo : "zdjęcie #1 z #2",
	
	//tablela
	table : null,
	
	//div gdzie będzie tlo
	bg : null,
	
	//img z loaderem
	loader : null,
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	show : function(n)
	{
		this.tryShow(this.images[n-1]);
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	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]);
		}
		else if(n == -1)
		{
			_prev = (this.actImage - 1 == -1)? this.images.length-1 :  this.actImage - 1;
			this.tryShow(this.images[_prev]);
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	tryShow : function(hrefObj)
	{
		var ps = this.pageSize();

		this.bg.style.width = ps.pageWidth;
		this.bg.style.height = ps.pageHeight;
		this.bg.style.display = 'block';
		this.loader.style.display = 'block';

		this.loader.style.left = Math.round(ps.windowWidth/2 - GetWidth(this.loader)/2);
		this.loader.style.top = Math.round(ps.windowHeight/2 + this.scroll());

		$(this.prefix+"title").innerHTML = (hrefObj.title && hrefObj.title.length > 0)? hrefObj.title : "&nbsp;";

		this.img.style.visibility = "hidden";

		this.img.src = hrefObj.href;

		//SetWidth(this.img, '0');
		//SetHeight(this.img, '0');
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	onLoadImg : function(hrefObj)
	{
		this.loader.style.display = 'none';
		
		var src = hrefObj.src;
		
		if (navigator.appVersion.indexOf("MSIE")!=-1)
			this.pause(300);
		
		var ps = this.pageSize();
		var tSize = GetSize(this.table);
		//var imgSize = GetSize(this.img);
				
		this.table.style.left = Math.round(ps.pageWidth/2 - tSize.width/2);
		this.table.style.top = Math.round(ps.windowHeight/2 - tSize.height/2 + this.scroll());
				
		
		/*
		SetWidth(this.prefix+'td', imgSize.width);
		SetHeight(this.prefix+'td', imgSize.height);
		this.img.style.width = imgSize.width/5;
		this.img.style.height = imgSize.height/5;
		*/
		
		
		this.img.style.visibility = "visible";
		$(this.prefix+"title").focus();
		
		var that = this;
		var text;
		
		for(var i=0; i<this.images.length; i++)
		{
			if(this.images[i].href == src)
			{
				this.actImage = i;
				
				text = this.textInfo.replace("#1", i+1);
				text = text.replace("#2", this.images.length);
				$(this.prefix+'info').innerHTML = text;

				break;
			}
		}	
		mint.fx.Style(this.img, "opacity", 0, 100, 20, 200, null, function(){

			//mint.fx.Size(that.img, imgSize.width, imgSize.height, 25, 100);

		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	closeLightbox : function(x)
	{
		this.table.style.top = '-10000px';
		this.table.style.left = '-10000px';

		if(!x)
		{
			//var that = this;
			//mint.fx.Style(this.bg, "opacity", null, 100, 20, 200);
			this.bg.style.display = 'none';
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	init : function(n)
	{
		var that = this;

		if(this.isInit)
			return;
		else
			this.isInit = true;

		if(!document.getElementsByTagName)
			return;
			
		var links = document.getElementsByTagName("a");
	
		for(var i=0; i<links.length; i++)
		{
			var lnk = links[i];
			var href = lnk.getAttribute("href");
			
			if(href && lnk.getAttribute("rel") == this.rel)
			{
				this.images.push(lnk);

				lnk.onclick = function(){
					that.tryShow(this);
					return false;
				}
			}
		}
		
		this.bg = document.createElement('div');
		this.bg.style.display = 'none';
		this.bg.style.position = 'absolute';
		this.bg.style.top = '0px';
		this.bg.style.left = '0px';
		this.bg.style.zIndex = '99';
 		this.bg.style.width = '100%';
		this.bg.style.height = '100%';
		
		this.loader = document.createElement('img');
		this.loader.src = this.imgLoadSrc;
		this.loader.style.display = 'none';
		this.loader.style.position = 'absolute';
		this.loader.style.top = '0px';
		this.loader.style.left = '0px';
		this.loader.style.zIndex = '101';
	
		this.table = document.createElement('table');
		
		var tr, td;
		
		tr = this.table.insertRow(0);
		td = tr.insertCell(0);
		td.setAttribute('colSpan', '4');
		td.setAttribute('id', this.prefix+'td');
		td.innerHTML = '<a href="#" onclick="return false;"><img src="" id="'+this.prefix+'image" border="0"></a>';
		tr = this.table.insertRow(1);
		td = tr.insertCell(0);
		td.innerHTML = '<a href="#" onclick="'+this.n+'.onArrowClick(-1); return false;"><img src="'+this.imgLeftSrc+'" border="0" id="'+this.prefix+'left"></a>';
		td = tr.insertCell(1);
		td.innerHTML = '';
		td.className = "lightbox_info";
		td.setAttribute('id', this.prefix+'info');
		td = tr.insertCell(2);
		td.innerHTML = '';
		td.className = "lightbox_title";
		td.setAttribute('id', this.prefix+'title');
		td = tr.insertCell(3);
		td.setAttribute('align', 'right');
		td.innerHTML = '<a href="#" onclick="'+this.n+'.onArrowClick(1); return false;"><img src="'+this.imgRightSrc+'" border="0" id="'+this.prefix+'right"></a>';
		
		this.table.style.position = 'absolute';
		this.table.style.top = '-10000px';
		this.table.style.left = '-10000px';
		this.table.style.zIndex = '100';
		this.table.setAttribute('border', 0);
		this.table.setAttribute('bgColor', '#000000');
		this.table.setAttribute('cellPadding', 0);
		this.table.setAttribute('cellSpacing', 0);
		this.table.setAttribute('id', this.prefix+'table');
		this.table.className = 'lightbox_table';
		
		document.body.appendChild(this.bg);
		document.body.appendChild(this.loader);
		document.body.appendChild(this.table);
		this.bg.className = "lightbox_bg";
		
		//mint.fx.Round(this.table, "all", "large");
		
		this.img = $(this.prefix+'image');
		
		var that = this;
		
		AddEvent(this.img, 'load', function(){that.onLoadImg(this)});
		AddEvent(this.img, 'click', function(){that.closeLightbox();});
						
		if(n)
			setTimeout(function(){that.show(1);}, 100);
			
	},
	
	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	
	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;
		}
	}
};

//-->
