var gblImgWindow;
var intScrollPos;

function $(strInput) {
	try { return document.getElementById(strInput); }
	catch (e) { return false; }
}


function showModal(s,w,h) {
	intScrollPos = $("html").scrollTop;
	var mw = $("modalWindow");
	var mb = $("modalBox");
	mw.style.display = "block";
	mw.style.marginTop = $("mainBody").scrollTop + 10;
	$("wrapper").style.display = "none";
	$("html").scrollTop = 0;
	mb.innerHTML = "<div style=\"margin-top:200px;\"><img src=\"/inc/img/template/loader.gif\" width=\"16\" height=\"16\"/></div>";
	setTimeout("showImg('" + s + "'," + w +"," + h +")",1000)
	return false;
}

function showImg(s,w,h) {
	var mb = $("modalBox");
	mb.innerHTML = "<img id=\"modalImg\" class=\"modalImg\" src=\"" + s + "\" width=\"" + w + "\" height=\"" + h + "\"/>";
}

function hideModal() {
	$("modalWindow").style.display = "none";
	$("wrapper").style.display = "block";
	setTimeout("setScroll()",2);
}

function setScroll() {
	$("html").scrollTop = intScrollPos;
}

	var strCurrentGallery = "indoor";
	var strCurrentPhoto = 1;
	scrollSpeed = 5;
	var timer;
	
	function nextPhoto() {
		
		if (strCurrentGallery == "indoor" && strCurrentPhoto == 8) {
			strCurrentGallery = "outdoor";
			showGalleryPhoto("outdoor",1);
			scroll(1);
		} else if (strCurrentGallery == "indoor") {
			showGalleryPhoto("indoor", parseInt(strCurrentPhoto) + 1);
		} else if (strCurrentGallery == "outdoor" && strCurrentPhoto == 8) {
			strCurrentGallery = "indoor";
			showGalleryPhoto("indoor",1);
			scroll(0);
		} else if (strCurrentGallery == "outdoor") {
			showGalleryPhoto("outdoor", parseInt(strCurrentPhoto) + 1);
		}
	}


	function prevPhoto() {
		
		if (strCurrentGallery == "indoor" && strCurrentPhoto == 1) {
			strCurrentGallery = "outdoor";
			showGalleryPhoto("outdoor",8);
			setTimeout("scroll(1)",1);
		} else if (strCurrentGallery == "indoor") {
			showGalleryPhoto("indoor", parseInt(strCurrentPhoto) - 1);
		} else if (strCurrentGallery == "outdoor" && strCurrentPhoto == 1) {
			strCurrentGallery = "indoor";
			showGalleryPhoto("indoor",8);
			setTimeout("scroll(0)",1);
		} else if (strCurrentGallery == "outdoor") {
			showGalleryPhoto("outdoor", parseInt(strCurrentPhoto) - 1);
		}
	}

	
	function scroll(lnk){
		clearTimeout(timer);
		p=document.getElementById('galleryThumbs');
		c=document.getElementById('galleryThumbs').getElementsByTagName('td')[lnk];

		if (c.offsetLeft < p.scrollLeft-scrollSpeed) {
			p.scrollLeft = p.scrollLeft-scrollSpeed;
			timer = setTimeout('scroll('+lnk+')',1);
		} else if (c.offsetLeft > p.scrollLeft + scrollSpeed) {
			p.scrollLeft = p.scrollLeft+scrollSpeed;
			timer=setTimeout('scroll('+lnk+')',1);
			} else {
				p.scrollLeft = c.offsetLeft;
				clearTimeout(timer);

			}

		if (p.scrollLeft + p.offsetWidth == p.scrollWidth){
			clearTimeout(timer);
		}
		setTimeout("setLinks(" + lnk +")",1);
		
		
	}

function setLinks(lnk) {
			document.getElementById("navTD").innerHTML
				 = (lnk == 1)
				  ? "<a href=\"javascript:scroll(0)\" style=\"color:#999900;\">&lt; Indoor Photos</a>"
				  : "<a href=\"javascript:scroll(1)\" style=\"color:#999900;\">Outdoor Photos &gt;</a>"

}
	
	function showGalleryPhoto(strInput,intInput) {
			document.getElementById("gallery").innerHTML = "<img src=\"/inc/img/template/loader.gif\" style=\"margin-top:100px;\"/>";
			setTimeout("showPhoto('" + strInput + "'," + intInput + ")",1500);
		return false;
	}
	
	function showPhoto(strInput,intInput) {
		document.getElementById("gallery").innerHTML = "<img src=\"/inc/img/gallery/full/" + strInput + intInput +".jpg\" />";
		strCurrentGallery = strInput;
		strCurrentPhoto = intInput;
	}