	var timerShow;
	
	function GetImage(ImgId) {
		if (ImgId!="") {
			if (document.getElementById || document.all) {
				Img=document.images[ImgId];
				Picture=document.images["Image"];
				Picture.src=Img.src.replace(ThumbNailDir,ImageDir);
				GetElement("ImageDesc").innerHTML=Img.title;
				ShowImageNo=ImgId.replace("Image","");
			} else {
				ImgNo=ImgId.replace("Image","");
				if (location.href.match(/Image=\d/)) {
					var NewQuery=location.href.replace(/Image=\d/,"Image="+ImgNo);
					location=NewQuery;
				} else {
					location+="&Image="+ImgNo;
				}
			}
		}
	}
	
	function GetElement(sId) {
		if (document.getElementById) {
			return document.getElementById(sId)
		} else if (document.all) {
			return document.all[sId];
		} else if (document.layers) {
			return document.layers[sId];
		}
	}
	
	function NextBatch() {
		if (PageNo<MaxPageNo) {
			location=location.pathname+"?id="+GalleryID+"&Batch="+(++PageNo)+"&StartImageNo="+StartImageNo+"&Delay="+Delay;
		} else {
			location=location.pathname+"?id="+GalleryID+"&Batch=0&StartImageNo="+StartImageNo+"&Delay="+Delay;
		}
	}
	
	function PreviousBatch() {
		if (PageNo>0) {
			location=location.pathname+"?id="+GalleryID+"&Batch="+(--PageNo)+"&Image="+(--BatchSize);
		} else {
			Batch=Math.floor(MaxImageNo/BatchSize);
			ImageNo=MaxImageNo % BatchSize;
			location=location.pathname+"?id="+GalleryID+"&Batch="+Batch+"&ImageNo="+ImageNo;
		}
	}
	
	function NextSlide() {
		ShowImageNo=parseInt(ShowImageNo)+1;
		if (ShowImageNo>LastImageNoOnPage || ShowImageNo==BatchSize) {
			NextBatch();
		} else {
			GetImage("Image"+ShowImageNo);	
		}
	}
	
	function PreviousSlide() {
		ShowImageNo-=1;
		if (ShowImageNo<0) {
			PreviousBatch()
		} else {
			GetImage("Image"+ShowImageNo);
		}
	}
	
	function PreloadPhotos() {
		if (document.getElementById || document.all) {
			for (var i=0; i<=LastImageNoOnPage;i++) {
				Img=document.images("Image"+i);
				eval("NewImage"+i+"=new Image()");
				eval("NewImage"+i+".src=Img.src.replace(ThumbNailDir,ImageDir)"); 
			}
		}
	}
	
	function InitShow() {
		PreloadPhotos();
		if (el=GetElement("selAutoShow")) {
			el.value=Delay;
			StartShow();
		}
	}
	
	function StartShow() {
		if (el=GetElement("selAutoShow")) {
			Delay=el.value;
			if (Delay==0) {
				StopShow();
				return false;
			}
			if (ShowImageNo=="undefine" || parseInt(ShowImageNo)<0 || parseInt(ShowImageNo)>BatchSize) ShowImageNo=0;
			TimerShow=setTimeout("AutoShow()",Delay*1000);
		}	
	}
	
	function StopShow() {
		if (window.TimerShow) clearTimeout(TimerShow);
		sel=GetElement("selAutoShow");
		if (sel && sel.value!=0) sel.value=0;
		StartImageNo=-1;
	}
	
	function ClickSlide() {
		if (window.TimerShow) {
			NextSlide();
			TimerShow=setTimeout("AutoShow()",Delay*1000);		
		} else {
			NextSlide();
		}
	}
	
	function AutoShow() {
		if ((parseInt(PageNo*BatchSize)+parseInt(ShowImageNo))==parseInt(MaxImageNo)) {
			StopShow();
			return;
		}
		NextSlide();
		TimerShow=setTimeout("AutoShow()",Delay*1000);		
	}
