// JavaScript Document
	var index = 0;
	var current = (window.opener?window.opener.current:0);
	var nimages = 0;
	var curimg = "";
	var slideaction = "play";
	var rotate_delay = 4000; // delay in milliseconds (1000 = 1 secs)
	var slides;
	var show;
	function firstload()
	{
		try{
			slides  = document.getElementById("slide");
			show = document.getElementById("show");
			//alert(slides.length);
			nimages = slides.length;
			show.src = slides[current].value;
			setD();
			status();
			window.setTimeout(function (){rotate();},rotate_delay);
			
			if (window.location.toString().indexOf("GalleriesFS")<=0)
			{
				window.setTimeout(function ()
				{var pre=0;
					for(var i =0;i< nimages;i++)
					{
						//preload image
						window.setTimeout(function ()
						{
						var div = document.createElement("DIV");
						var img	= new Image();
						img.src	= slides[pre++].value;
						
						div.style.display='none';
						div.appendChild(img);
						document.body.appendChild(div);
						},i*300);
						//end preload
					}
				},1500);
			}
		}catch (e) {}
	}
	function controls(ctrl)
	{
		try
		{
		//slide  = document.getElementById("slide");
		//slide = document.form1.slide;
		//show = document.getElementById("show");
		switch(ctrl)
		{
			case "first":
			current = 0;
			change(); ////////////////////////////////////////////////////////////////
			break;
			case "back":
			if (current > 0)
			{
				current--;
			}
			else
			{
				//alert("You're at beginning of the Slideshow");
				current = nimages - 1; // go to last
			}
			change(); ////////////////////////////////////////////////////////////////
			break;
			case "play":
				if (slideaction != "play")
				{
					slideaction = "play";
					rotate();
				}
			//rotate();
			break;
			case "next":
				if (current < nimages-1)
				{
					if (slideaction != "play")
					{
						current++;
					}
				}
				else
				{
					current = 0;
					//alert("End of this Slideshow. It now starts at first picture.");
				}
				change(); ////////////////////////////////////////////////////////////////
			break;
			case "last":
				current = nimages - 1; //go to last
				change(); ////////////////////////////////////////////////////////////////
			break;
			case "stop":
				slideaction = "stop";
			break;
			case "pause":
				slideaction = "pause";
			break;
			case "close":
				if (window.opener)
				{
					window.opener.current = current-1;
					window.opener.change();
					window.opener.controls('play');
				}
				window.close();
			break;
		}
		playmode();
		}
		catch(e) {}
	}
	function change()
	{
		try
		{
			show 		= document.getElementById("show");
			show.src 	= slides[current].value;
			setD();
			var animation = document.getElementById('animation');
			if (!animation)
			{
				animation 				= document.createElement("DIV");
				animation.id			= 'animation';
				animation.style.position= 'absolute';
				//animation.style.border	= 'solid 1px red';
				document.body.appendChild(animation);
			}
			//start animation
			var previous 			= current-1; if (previous <0) previous = nimages-1; 
			animation.style.height 	= show.offsetHeight;
			animation.style.width	= show.offsetWidth;
			animation.style.top		= Top(show);
			animation.style.left	= Left(show);
			animation.style.background = 'url('+slides[previous].value+') no-repeat';
			animation.style.filter= 'alpha(opacity=90)';
			animation.style.MozOpacity = '.9';
			animation.style.display		= '';
			var ani = 1;
			var t = window.setInterval(function ()
			{
				animation.style.backgroundPosition = '' + Math.round(ani+(show.offsetWidth/10)) + 'px';
				ani = ani + 100;
				if (ani>1000)
					clearInterval(t);
			},ani);
			
			
			window.setTimeout(function ()
			{
				show.src = slides[current].value;
				animation.style.display='none';
			},1000);
			//end animate
		}
		catch (e) {}
		status();
	}

	function rotate()
	{
		status();
		if (slideaction == "play")
		{
			try
			{
				getScreen();
				slide  			= document.getElementById("slide");
				show 			=  document.getElementById("show");
				show.src 		= slides[current].value;									
				setD();	
				
				
				current = (current == nimages - 1) ? 0 : (current+1*1);	
									
				change();		
				window.setTimeout(function ()
				{					
					rotate();						
				}, rotate_delay);
			}catch (e) {}
		}
	}
	function playmode()
	{
		var cplay = document.getElementById("cplay");
		var cpause = document.getElementById("cpause");

		if (slideaction == "play")
		{
			cplay.style.display = "none";
			cpause.style.display = "inline";
		}else
		{
			cplay.style.display = "inline";
			cpause.style.display = "none";
		}
	}
	function hover(o)
	{
		src = new String(o.src);
		src = src.replace(".gif", "_h.gif");

		o.src = src;
	}
	function nohover(o)
	{
		src = new String(o.src);
		src = src.replace("_h.gif", ".gif");

		o.src = src;
	}
	function fullscreen(gallery,dir)
	{
		slideaction = "stop";
		playmode();
		var theURL  = "GalleriesFS.php?gallery=" + gallery + "&dir=" + dir;
		window.open(theURL,'','fullscreen=yes, scrollbars=auto');
		/*if (navigator.appName == "Microsoft Internet Explorer")
		{
			window.open(theURL,'','fullscreen=yes, scrollbars=auto');
		}
		else
		{
			window.open(theURL);
		}*/
	}
	function status()
	{
		var lblStatus = document.getElementById("lblStatus");
		var stat  = "";
		stat = (current + 1) + "/" + nimages;
		lblStatus.innerHTML = stat;
	}
	function setD()
	{
		getScreen();
		show = document.getElementById("show");
		var  maxWidth 	= 578;//slide.parentNode.offsetWidth;
		var maxHeight	= aval_height;//pY2 - Top(slide.parentNode);
		var imgWidth	= slides[current].getAttribute('imgWidth');
		var imgHeight	= slides[current].getAttribute('imgHeight');
		
		//document.title = (imgHeight)+'x'+(pY2-Top(show));
		
		if (window.location.toString().indexOf("GalleriesFS")>0)
		{
			if (imgHeight>=maxHeight)
			{
				show.style.height		= maxHeight+'px';
				show.style.marginTop	=0;
			}
			else
			{
				show.style.height			= imgHeight + 'px';
				show.style.marginTop 		= Math.floor((aval_height-imgHeight)/2)+'px'; 
			}
		}
		else
		{
			var ratio = imgWidth/imgHeight;
			if (imgWidth>maxWidth)
			{
				show.style.width	= (maxWidth-10)+'px';
				//show.style.height	= Math.round((maxWidth-10)*ratio)+'px';
			}
			else
			{
				show.style.width	= imgWidth + 'px';
				//show.style.height	= imgHeight+'px';
			}
			
		}
	}
	function oControls(mode)
	{
		var slidectrl = document.getElementById("slidectrl");

		if (mode == "over")
		{
			slidectrl.style.marginTop = Top(show)+'px';//"0px";
			setSlideCtrl();
		}
		else
		{
			slidectrl.style.marginTop = "-999px";
		}
	}
	function setSlideCtrl()
	{
		show = document.getElementById("show");
		var slidectrl = document.getElementById("slidectrl");
		slidectrl.style.marginTop = Top(show)+'px';//"0px";
		var a= slidectrl.getElementsByTagName('a');
		slidectrl.style.marginLeft = (screen.width / 2) - ((a.length + 2) * 15); //move it to center of the screen
	}