var newwin;

function launchwin (winurl,winname,winfeatures){
	newwin = window.open(winurl,winname,winfeatures);
}

function printIt(pageContent) {
pcWindow=window.open('RonWillemsPhoto','printwin',''); 
pcWindow.document.write('<html><head><title>RonWillemsPhoto</title><link rel="stylesheet" type="text/css" href="print.css"></head><body>'); 
pcWindow.document.write(pageContent); 
pcWindow.document.write('</body></html>'); 
pcWindow.document.close(); 
pcWindow.blur(); 
window.focus()
if (window.print) 
pcWindow.print();
pcWindow.close();
} 

var instructions;
var id;
var newid;
var page;
var pagelength; //number of characters in the filename of the detail page including the ?id=
var eof; //number of images in the gallery
var gallery; //gallery detail page including ?id=1&w=1
var resetid;
var resetnewid;
var resetpage;
var directory; //number of characters in the filename of the directory for the current gallery including the trailing /

function watchShow(pagelength,eof,gallery){
	instructions = parent.photo.location.href.substring(46); // 46 is the numbers of characters in the domain up to the php filename
	//alert(instructions);
	if (instructions != "instructions-detail.php") { // So if the instructions are not showing
		id = parent.photo.location.search.substring(1); // The querystring
		//alert(id);
		id = id.substring(3,id.length); // Remove the id= off the front of the querystring
		//alert(id);
		
		if (id != eof) {
			newid = parseInt(id); // Returns the number at the start of the string which should be the current imgorder
			//alert(newid);
		    page = parent.photo.location.href.substring(46); // 46 is the numbers of characters in the domain up to the php filename
			//alert(page);
			page = page.substring(0,pagelength); // Remove the extra querystring values off to leave just id=
			//alert(page);
			page = page + (newid + 1) + "&w=1"; // Add extra querystring values back on with the next imgorder
			//alert(page);
			setTimeout('changeImage()',6000); // Go to changeImage() function after 6 seconds
		} else { restartShow(gallery) } // If the id is equal to the last image then restart the slideshow
	} else { actionShow(gallery); } // If the instructions are showing then start the slideshow with the first image
}

function changeImage() {
	parent.photo.location = page; // Change the location of the iframe to the next image
}

function resetShow(resetpagelength){
	resetid = parent.photo.location.search.substring(1);
	resetid = resetid.substring(3,resetid.length);
	//alert(ID);
	
	resetnewid = parseInt(resetid);
	//alert(NEWID);
	
    resetpage = parent.photo.location.href.substring(46); // 46 is the numbers of characters in the domain up to the php filename
	//alert(PAGE);
	resetpage = resetpage.substring(0,resetpagelength);
	//alert(PAGE);
	resetpage = resetpage + (resetnewid);
	//alert(PAGE);
	resetImage();
}

function resetImage() {
	parent.photo.location = resetpage;
}

function showButton() {
	parent.document.getElementById('watchSlideShow').style.display = "block";
	parent.document.getElementById('watchingSlideShow').style.display = "none";
	parent.document.getElementById("gallery").style.display = "block";
	parent.document.getElementById("galleryShow").style.display = "none";
}

function hideButton() {
	parent.document.getElementById("watchSlideShow").style.display = "none";
	parent.document.getElementById('watchingSlideShow').style.display = "block";
	parent.document.getElementById("gallery").style.display = "none";
	parent.document.getElementById("galleryShow").style.display = "block";
}

function restartShow(gallery) {
	setTimeout('actionShow("' + gallery + '")',6000);
}

function actionShow(gallery) {
	parent.photo.location.href = gallery;
}

/***************************************************************************************************
This function shows or hide the specified div
*****************************************************************************************************/
function togglediv(showdiv,hidediv){
	targetshow = document.getElementById(showdiv);
	targethide = document.getElementById(hidediv);
	targetshow.style.display = "block";
	targethide.style.display = "none";
}