var Site = "http://www.photogalleria.nl";	// De Url van deze site

var N = 0;									// Aantal foto's
var C = 0;									// Huidige foto
var Wt = 0;									// Breedte van tegeltje
var Ht = 0;									// Hoogte van tegeltje
var St = Math.floor(2*screen.width/1400);	// Vspace/Hspace bij het "Shrinken" van een tegeltje
var Sr = 2*St;								// Shrinking-waarde van een tegeltje
var currImage = null;						// Het actuele tegeltje

var WebName = null;							// De name van de site
var Lang = null;							// De gebruikte taal
var IncName = null;							// De naam van de serverlocatie

var ShowRunning = false;					// Indicatie of diavoorstelling bezig is
var Timer = null;							// De event-timer
var Timeout = 5000;							// Tijd van het tonen van een "Grote foto"
var Current = 0;							// Huidige array-entry (= huidig getoonde foto)

var Home = "../";							// Variabele voor het adresseren van de mappen (verschil tussen de index en de rest) 
var Extra = null;							// variabele voor het toevoegen van info bij de reload van de page

var mySizes = null;							// De bruikbare schermbreedte en schermhoogte

var LinkCount = 0;							// Het aantal entries onder de "back" knop van IE
var InitialCall = false;					// Indicatie of dit dee eerste aanroep is van deze sessie 

var Xid = null;								// Id van het plus/minus teken in het menu
var ExpandCollapse = null;					// Indicatie of er op een plus/minus teken is geklikt en de uit te voeren actie

function FillPage(Param, Show)
	{

	onerror=ErrHandler;

	if (Param == "slideshow")
		{return true;}
		
	LinkCount = document.getElementById("LinkCount").innerHTML;
		
	if (LinkCount < 0)
		{
		InitialCall = true;
		LinkCount = window.history.length;
		}

	if (Param == "exit")
		{
		if (InitialCall)
			{
			window.history.go(LinkCount-1);
			return true;
			}
		if (LinkCount == 0)
			{
			window.close();
			}
		else
			{	
			window.history.go(LinkCount-window.history.length-1);
			}
		return true;
		}

	if (Param == "index")
		{
		Home = "";
		}
	else
		{
		Home = "../";
		}

	var currSizes = [document.getElementById("MaxWidth").innerHTML, document.getElementById("MaxHeight").innerHTML, document.getElementById("ScreenWidth").innerHTML, document.getElementById("ScreenHeight").innerHTML];
//	window.alert( '(Current sizes from the page): ' + currSizes[0] + ", " + currSizes[1] + ", " + currSizes[2] + ", " + currSizes[3]);
	mySizes = getScreenSizes(document.getElementById("ScreenWidth").innerHTML, document.getElementById("ScreenHeight").innerHTML);
//	window.alert( '(After getScreenSizes) ' + mySizes[0] + "::" + document.getElementById("MaxWidth").innerHTML + "; " +  mySizes[1] + "::" + document.getElementById("MaxHeight").innerHTML + "; " + screen.width + "::" + document.getElementById("ScreenWidth").innerHTML + "; " + screen.height + "::" + document.getElementById("ScreenHeight").innerHTML);

	if (mySizes[0] != currSizes[0] || mySizes[1] != currSizes[1] || mySizes[2] != currSizes[2] || mySizes[3] != currSizes[3])
			{
//		window.alert( '(OnLoad) ' + mySizes[0] + "::" + currSizes[0] + "; " +  mySizes[1] + "::" + currSizes[1] + "; " + screen.width + "::" + currSizes[2] + "; " + screen.height + "::" + currSizes[3]);
		var F = (window.location.search.indexOf("reload="));
		var L = (window.location.search.lastIndexOf("reload="));
//		window.alert("F="+F+", L="+L);
		if (F!=L) {
			return true;
			}
		if (window.location.search.length > 0)
			{
			Extra = "&";
			}
		else
			{
			Extra = "?";
			}
		window.location.replace(window.location+Extra+"reload="+mySizes[0]+","+mySizes[1]+","+mySizes[2]+","+mySizes[3]+","+LinkCount);
		}
	else
		{
		if (InitialCall)
			{
			if (window.location.search.indexOf("linkcount=")==-1)
				{
				if (window.location.search.length > 0)
					{
					Extra = "&";
					}
				else
					{
					Extra = "?";
					}
				window.location.replace(window.location+Extra+"linkcount="+LinkCount);
				}
			}
		}

	if (Param == "fotos")
		{
		ShowRunning = (Show == "on");
		N = document.getElementById("N").innerHTML;
		C = document.getElementById("C").innerHTML;
		SetCurrFoto(C);
		}
	}

function ErrHandler(msg,url,l)
	{
	alert(msg+" "+url);
	window.location = Site;
	return true;
	}

function MouseHandler(event)
	{
	if (event.button==2)
		{	
		alert(document.getElementById("msgMouseEvent").innerHTML);
		}
	}

function fotoMouseHandler(event)
	{
	if (event.button==2)
		{
		}
	else
		{
		nextImage();
		}
	}

function ResizeHandler()
	{
	var newSizes = getScreenSizes(document.getElementById("ScreenWidth").innerHTML, document.getElementById("ScreenHeight").innerHTML);
	if (mySizes[0] != newSizes[0] || mySizes[1] != newSizes[1])
		{	
		var F = (window.location.search.indexOf("reload="));
		if (F!=-1) {
			F = F-1;
			L = window.location.protocol+"//"+window.location.hostname+window.location.pathname+window.location.search.substr(0,F);
			window.location.replace(L);
			return true;
			}
		window.location.reload();
		}
	return true;
	}

function SetLanguage(Language)
	{
	setCookie("language", Language, 365);
	window.location.replace(window.location);
	}
	
function SetCurrFoto(CurrFoto)
	{
	Current = CurrFoto-0;

	if (ShowRunning)
		{
		Timer=setTimeout("SlideShow()",Timeout);
		}
	}

function SelectFoto(CurrFoto)
	{
	Current = CurrFoto-0;
	StopSlideShow();
	}
		
function ShowFoto(CurrFoto)
	{
	if (ShowRunning)
		{
		window.location = "http://"+window.location.hostname+window.location.pathname+"?foto="+CurrFoto+"&show=on";
		}
	else
		{
		if (Xid == null)
			{
			window.location = "http://"+window.location.hostname+window.location.pathname+"?foto="+CurrFoto;
			}
		else
			{
			window.location = "http://"+window.location.hostname+window.location.pathname+"?foto="+CurrFoto+"&"+ExpandCollapse+"="+Xid;
			}
		}		
	}
 
function Shrink(CurrFoto)
	{
	currImage = document.getElementsByName(CurrFoto)[0];
	Ht = currImage.height;
	Wt = currImage.width;
	currImage.height=Ht-Sr;
	currImage.width=Wt-Sr;
	currImage.vspace=St;
	currImage.hspace=St;
	}

function Expand(CurrFoto)
	{
	currImage.height=Ht;
	currImage.width=Wt;
	currImage.vspace="0";
	currImage.hspace="0";
	}

function SwapShow()
	{
	if (ShowRunning)
		{
		StopSlideShow();
		}
	else
		{
		ShowRunning = true;
		ShowFoto(Current);		
		}
	}

function SlideShow()
	{
	Current = (Current+1);
	SetCurrent();
	ShowFoto(Current);
	}

function StopSlideShow()
	{
	ShowRunning = false;
	clearTimeout(Timer);
	ShowFoto(Current);
	}
	
function Dim(DezeFoto)
	{
	WebName = document.getElementById("WebName").innerHTML;
	if (DezeFoto != "play")
		{
		document.images[DezeFoto].src=Home+"global/"+WebName+"/"+DezeFoto+"d.gif";
		}
	else if (ShowRunning)
			{
			document.images["play"].src=Home+"global/"+WebName+"/stopd.gif";
			}
		else
			{
			document.images["play"].src=Home+"global/"+WebName+"/playd.gif";
			}
	}

function Light(DezeFoto)
	{
	WebName = document.getElementById("WebName").innerHTML;
	if (DezeFoto != "play")
		{
		document.images[DezeFoto].src=Home+"global/"+WebName+"/"+DezeFoto+".gif";
		}
	else if (ShowRunning)
			{
			document.images["play"].src=Home+"global/"+WebName+"/stop.gif";
			}
		else
			{
			document.images["play"].src=Home+"global/"+WebName+"/play.gif";
			}
	}

function PrevFoto()
	{
	StopSlideShow();
	Current = (Current-1);
	SetCurrent();
	ShowFoto(Current);
	}
	
function NextFoto()
	{
	StopSlideShow();
	Current = (Current+1);
	SetCurrent();
	ShowFoto(Current);
	}

function SetCurrent()
	{
	if (Current < 0)
		{
		Current = (N-1);
		}
	if (Current >= N)
		{
		Current = 0;
		}
	}

function ExpandMenu(Id)
	{
	ExpandCollapse = "expand";
	Xid = Id;
	StopSlideShow();
	}
	
function CollapseMenu(Id)
	{
	ExpandCollapse = "collapse";
	Xid = Id;
	StopSlideShow();
	}

function setCookie(name, value, expiredays)
	{
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
function isSetCookie(name)
	{
	if (document.cookie.length>0)
		{
		if (document.cookie.indexOf(name + "=") != -1)
			{ 
			return true;
			} 
		}
	return false;
	}
