var Gallery = {
	Current : null,

	init : function(){
		if(!document.getElementsByTagName) return;

		var args = Gallery.init.arguments;
		var b;
		args[0] ? b = args[0] : b = "gallery";

		divs = document.getElementsByTagName("div");
		anhors = document.getElementsByTagName('a');
		Board = divs[b];
		allFoto = Array();
		if(!Board) return;

		for(var i = 0; i < Board.childNodes.length; i++){
			var tmpdiv = Board.childNodes[i];
			if(tmpdiv.href){
				tmpdiv.qid = allFoto.length;
				tmpdiv.onclick = function(){
					
					Gallery.Current = this.qid;
					
					return Gallery.showImage(this.href);
				}
				allFoto[allFoto.length] = tmpdiv.href;
			}
		}

	},
		
	showImage : function(path){
		if(!document.getElementsByTagName) return true;
		var bg = divs["fotobg"];
		//var frame = divs["fotoframe"];

		psize = Gallery.getPageSize();
		if(navigator.appName == "Netscape") psize[0] -= 17;
		bg.style.width = psize[0] + "px";

		psize[1] = divs["bvs_content"].offsetHeight + divs["bvs_show_lighting_container"].offsetHeight;

		bg.style.height = psize[1] + "px";
		bg.style.visibility = "visible";
		
		Gallery.loadFoto(path);

		
		
		return false;

	},

	loadFoto : function(path){
		if(document.images){

			imgPreloader = new Image();
			
			imgPreloader.onload = function(){
				Gallery.setFrame(this.width, this.height);
				document.images.fotoObj.src = this.src;
				document.images.fotoObj.onclick = function(){
					return Gallery.hideFoto();
				}
			}
			imgPreloader.src = path;
			//document.images["fotoObj"].src = path;
		}
	},

	setFrame : function(width, height){
		var frame = divs["fotoframe"];
		var menu = divs["framemenu"];
		
		menu.style.width = (width + 20) + "px";
		frame.style.width = width + "px";
		frame.style.height = height + "px";
		frame.style.left = (psize[0] / 2) - (width / 2) + "px";
		var ns6 = document.getElementById && !document.all;
		if(document.documentElement && document.documentElement.scrollTop){
			var myoff = document.documentElement.scrollTop;
		}else if(document.body){
			var myoff = document.body.scrollTop;
		}else{
			var myoff = pageYOffset;
		}
		
		frame.style.top = (myoff + ((psize[3] - height) / 2) - 20) + "px";
		frame.style.visibility = "visible";

		anhors["foto_close"].onclick = function(){
			return Gallery.hideFoto();
		}
		
		if(Gallery.Current >= 0 && allFoto.length > 0){
			
			if(Gallery.Current - 1 >= 0 && allFoto.length > 1){
				anhors["foto_prev"].style.visibility = "visible";
				anhors["foto_prev"].onclick = function(){
					Gallery.Current -= 1;
					return Gallery.showImage(allFoto[Gallery.Current]);
				}
			}else{
				anhors["foto_prev"].style.visibility = "hidden";
			}

			if(Gallery.Current + 1 < allFoto.length){
				anhors["foto_next"].style.visibility = "visible";
				anhors["foto_next"].onclick = function(){
					Gallery.Current += 1;
					return Gallery.showImage(allFoto[Gallery.Current]);
				}
			}else{
				anhors["foto_next"].style.visibility = "hidden";
			}
		}else{
			anhors["foto_next"].style.visibility = "hidden";
			anhors["foto_prev"].style.visibility = "hidden";
		}
	
	},

	hideFoto : function(){
		var frame = divs["fotoframe"];
		var bg = divs["fotobg"];
		frame.style.visibility = "hidden";
		bg.style.visibility = "hidden";
		anhors["foto_next"].style.visibility = "hidden";
		anhors["foto_prev"].style.visibility = "hidden";

		return false;
	},

	getPageSize : function(){
   
	   var xScroll, yScroll;
	   
	   if (window.innerHeight && window.scrollMaxY) {   
		  xScroll = document.body.scrollWidth;
		  yScroll = window.innerHeight + window.scrollMaxY;
	   } else 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;
	   }
	   
	   var windowWidth, windowHeight;
	   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;
	   }


	   arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll,yScroll)
	   return arrayPageSize;
	}
}


/*function showImage(path, title, width, height) {

	var div = document.getElementById('FotoViewer');
	var loader = document.getElementById('FotoLoader');
	var name = document.getElementById('FotoName');
	var viewer = document.getElementById('FotoSrc');
	var bg = document.getElementById('FotoBg');

	psize = getPageSize();

	if(navigator.appName != "Netscape"){
		bg.style.width = psize[0] + "px";
	}
	
	div.style.display = 'block';
	div.style.width = "100%";
	div.style.height = psize[1] + "px";

	loader.style.display = 'block';
	loader.style.top = (document.body.scrollTop + (psize[3] / 2)) + "px";
	loader.style.left = (psize[0] / 2) + "px";

	var viewerTop = (document.body.scrollTop + (psize[3] / 2)) - (height / 2);


	viewer.style.top = viewerTop + "px";
	viewer.style.left = (psize[0] / 2) - (width / 2) + "px";
	
	name.style.display = 'none';
	name.innerHTML = title;
	name.style.top = viewerTop + height + "px";
	name.style.left = (psize[0] / 2) - (width / 2) + "px";
	name.style.width = (width + 2) +"px";
		
	document.getElementById('FotoName')
	document.getElementById('fotoview_img').src = path;
}

*/