// JavaScript Document
function $(id)
{
	return document.getElementById(id);	
}

function initGallery()
{
	window.onload = function()
	{
		gall = new Gallery();
	}
}

function Gallery()
{
	this.container = $("GallContainer");
	this.closeBtn = $("GallCloseBtn");
	this.image = $("GallImage");
	this.pager = $("GallPager");
	this.btnLeft = $("GallBtnLeft");
	this.btnRight = $("GallBtnRight");	
	this.title = $("GallTitle");
	this._images = new Array();
	this._currentImage = 0;
	this._links = new Array();


	this.show = function(title, images)
	{
		w = getwindow();
		
		this.container.style.left = 50 + "px";
		this.container.style.top = (w.t + 50) + "px";

		
		this.container.style.display="block";
		
		this.title.innerHTML = title;
		this._images = images;
		
		this.pager.innerHTML = "";
		//this.btnLeft.style.display = "none";
		//this.btnRight.style.display = "none";
		
		var pagerStr = "";

		var i = 0;
		if(this._images.length > 1)
		{
			pagerStr += "<div class=\"classPagerNr active\" onClick='gall.showImg(0)'>1</div>";
			i++;
		}
		
		if(this._images.length > 2)
		{
			for(i = 1; i < this._images.length - 1; i++)
			{
				pagerStr += "<div class=\"classPagerNr\" onClick='gall.showImg(\""+ i +"\")'>"+ (i + 1) +"</div>";
			}
		}

		pagerStr += "<div class=\"classPagerNr last\" onClick='gall.showImg(\""+ i +"\")'>"+ (i + 1) +"</div>";

		
		
		if(this._images.length < 2)
		{
			this.pager.style.display="none"	;
		}
		else
			this.pager.style.display="inline"	;
		
		
		this.pager.innerHTML = pagerStr;
		
		this._links = this.pager.getElementsByTagName("div");

		
		this._currentImage = 0;
		
		this.showImg(this._currentImage);
		
	}
	
	this.showImg = function(nr)
	{
		if(this._currentImage == this._images.length - 1)
			this._links[this._currentImage].className = "classPagerNr last";
		else
			this._links[this._currentImage].className = "classPagerNr";
		
		this._currentImage = nr;
		
		if(this._currentImage == this._images.length - 1)
			this._links[this._currentImage].className = "classPagerNr active last";
		else
			this._links[this._currentImage].className = "classPagerNr active";
		
		
		this.image.src = this._images[nr];
		
	}
	
	this.close = function()
	{
		this.container.style.display="none";	
	}
}


function getwindow() {
 var d = document, v = window, w, h, l, t;
 if( typeof v.innerWidth==='number' ) {
  w = v.innerWidth;
  h = v.innerHeight;
  l = v.pageXOffset;
  t = v.pageYOffset;
 } else if( ( v = d.documentElement ) &&
   typeof v.clientWidth==='number' &&
   v.clientWidth !== 0 || ( v = d.body ) ) {
  w = v.clientWidth;
  h = v.clientHeight;
  l = v.scrollLeft;
  t = v.scrollTop;
 }
 return {w: w, h: h, l: l, t: t};
}


function testWnd()
{
	
	var w = getwindow();
	
	alert(w.w+":"+w.h+":"+w.l+":"+w.t);
}


