var CurrentIndex = 0;
var SrcCurrent;
var Waiting;
var CurrentImage;
var LoadingID;
var Hor;
var SlideShowID = 0;
var PictCount = 0;
var ShowRunning = false;
var Duration = 4000;
var PreImage;
var Size = 0;
var waitID;
var Resizing = false;
var InitialStartID = 0;
var SizeLow = 480;
var SizeHigh = 640;

function LoadPictures()
	{CurrentIndex = 0;
	SrcCurrent = Pictures[CurrentIndex]
	PictCount = Pictures.length;
	
	//Size and align image
	if (Sizes[CurrentIndex] == "thumbnailv") {
		document.picture.style.marginLeft = "80px";
		document.picture.style.marginTop = "0";}
	else {
		document.picture.style.marginTop = "80px";
		document.picture.style.marginLeft = "0";}
		
	//Present the first one
	document.picture.src = Pictures[CurrentIndex];
	document.title = Titles[CurrentIndex];
	
	//Start the show with a delay
	InitialStartID = setInterval("InitialStart()", Duration);
	}

function InitialStart() {
	if (InitialStartID != 0) {
		ToggleSlideShow();
		InitialStartID = 0;
		}
	else {
		clearInterval(InitialStartID);
		}
	}
	
function Close() {
	window.close();
	return true;
	InitialStartID = 0;
		}
	
function NewIndex(next) {
	var pIndexReturn = CurrentIndex;
	var end;
	if (next)
		if (pIndexReturn == (PictCount - 1))
			if (SlideShowID != 0) {
				clearTimeout(SlideShowID);
				SlideShowID = 0;
				ShowRunning = false;
				end = document.getElementById('end');
				window.setTimeout("ShowDiv(end)", Duration);
				}
			else
				pIndexReturn = 0;
		else {
		    end = document.getElementById('end');
			HideDiv(end);
			pIndexReturn++;
			}
	else {
	    end = document.getElementById('end');
		HideDiv(end);
		if (pIndexReturn == 0) 
			pIndexReturn = (PictCount - 1);
		else
			pIndexReturn--;
		}
	return pIndexReturn;
	}

function SlideShow() {
	if (!Waiting) {
		CurrentIndex = NewIndex(true);
		SrcCurrent = Pictures[CurrentIndex];
		}
	
	if (LoadImage()) {
		Waiting = false;
		ShowPicture();
		PreLoadNext();
		if (ShowRunning)
			SlideShowID = window.setTimeout("SlideShow()", Duration);
		}
	else {
		// Make a delayed call to this function to evaluate LoadImage again
		Waiting = true;
		LoadingID = window.setTimeout("SlideShow()", 250);
		}
	}
	
function LoadImage() {
	if (!Waiting) {
		//New call to this function, start loading the new image
		//First see if it's a horizontal picture or not
		if (Sizes[CurrentIndex] == 'thumbnailh') {
			Hor = true;	//We want to evaluate this only once for each picture
			CurrentImage = new Image(SizeHigh, SizeLow);
			CurrentImage.src = SrcCurrent;
			}
		else {
			Hor = false;
			CurrentImage = new Image(SizeLow, SizeHigh);
			CurrentImage.src = SrcCurrent;
			}
		if (CurrentImage.complete) {
			//Almost impossible but you never know
			return true;
			}
		else {
			return false;
			}
		}
	else {
		if (CurrentImage.complete) {
			return true;
			}
		else {
			return false;
			}
		}
	}
	
function ShowPicture() {	
	var pTitle = "";
	pTitle = Titles[CurrentIndex];
	if (Hor) {
	    document.picture.style.marginTop = "80px";
	    document.picture.style.marginLeft = "0"
		}
	else {
	    document.picture.style.marginLeft = "80px";
	    document.picture.style.marginTop = "0"
		}
	document.picture.src = CurrentImage.src;
	document.title = pTitle;
	}

function GetTitle() {
	var pTitle = "";
	if (Titles) {
		pTitle = Titles[CurrentIndex];
		}
	else {
		//Extract the title from the file name
		pTitle = SrcCurrent.substring(SrcCurrent.indexOf("/") + 1, SrcCurrent.length);
		pTitle = pTitle.substring(0, pTitle.indexOf("_"));
		//We use pTitle when it's not an empty string
		if (pTitle.length == 0) {
			pTitle = SrcCurrent;
			}
		}
	return pTitle;
	}
	
function PreLoadNext() {
	//When showing a picture, we start downloading the possible next
	if (!PreImage) {
		PreImage = new Image(1, 1);
		}
	PreImage.src = Pictures[NewIndex(true)];
	}

function ShowPrevious() {
	InitialStartID = 0;
	//Stop the slideshow when it's running
	if (ShowRunning) {
		EndShow();
		}
	//Stop loading the next image when it's running
	if (Waiting) {
		window.clearTimeout(LoadingID);
		Waiting = false;
		}
	//Present the picture
	CurrentIndex = NewIndex(false);
	SrcCurrent = Pictures[CurrentIndex];
	if (Sizes[CurrentIndex] == 'thumbnailh') {
		Hor = true;	//We want to evaluate this only once for each picture
		CurrentImage = new Image(SizeHigh, SizeLow);
		CurrentImage.src = SrcCurrent;
		}
	else {
		Hor = false;
		CurrentImage = new Image(SizeLow, SizeHigh);
		CurrentImage.src = SrcCurrent;
		}
	ShowPicture();
	}
	
function ShowNext() {
	InitialStartID = 0;
	//Stop the slideshow when it's running
	if (ShowRunning) {
		EndShow();
		}
	//Stop loading the next image when it's running
	if (Waiting) {
		window.clearTimeout(LoadingID);
		Waiting = false;
		}
	//Present the picture
	CurrentIndex = NewIndex(true);
	SrcCurrent = Pictures[CurrentIndex];
	if (Sizes[CurrentIndex] == 'thumbnailh') {
		Hor = true;	//We want to evaluate this only once for each picture
		CurrentImage = new Image(SizeHigh, SizeLow);
		CurrentImage.src = SrcCurrent;
		}
	else {
		Hor = false;
		CurrentImage = new Image(SizeLow, SizeHigh);
		CurrentImage.src = SrcCurrent;
		}
	ShowPicture();
	PreLoadNext();
	}
	
function ToggleSlideShow() {
	if (ShowRunning) {
		EndShow();
		}
	else {
		document.ShowShow.src="Images/Pause.gif";
		ShowRunning = true;
		SlideShow();}
	}
	
function AdjustFrequency(TimeDiff) {
    var quick = document.getElementById('quicker');
	Duration += TimeDiff;
	if (Duration <= 0) {
		Duration = 0;
		HideLink(quick);
		}
	else {
		ShowLink(quick);
		}
	}

function EndShow() {	
	if (SlideShowID != 0) {
		window.clearTimeout(SlideShowID);
		SlideShowID = 0;
		}
	ShowRunning = false;
	document.ShowShow.src="Images/Projector.gif";
	}


function ShowDiv(obj) {
	   obj.style.display='block';
	   Resizing = true;
	   Size = 0;
	   ResizeImg();
	 }

function ResizeImg() {
	if (Resizing) {
		if (Size < 50) {
			Size += 1;
			var p = document.getElementById('plaatje');
			p.width = 2 * Size;
			p.height = Size;
			waitID = setInterval("ResizeImg()", 100);		
			}
		else {
			clearInterval(waitID);
			waitID = 0;
			Resizing = false;
			document.ShowShow.src="Images/Projector.gif";
			}
		}
	}
	
function HideDiv(obj) {
	if (obj.style.display == 'block') {
		obj.style.display='none';
		if (waitID != 0) {
			clearInterval(waitID);
			waitID = 0;
			}
		Size = 0;		
		}
	}

function HideLink(Link) {
	if (Link.id == "quicker") {
		Link.innerHTML = "Sneller";
		}
	}
	
function ShowLink(Link) {
	if (Link.id == "quicker") {
		//Link.innerHTML = "<a href='javascript:AdjustFrequency(-500)' title='Laat foto&#8217;s korter zien (- &#189; sek. per klik)'>Sneller</A>";
//		Link.innerHTML = "<a style='text-decoration:none; margin-top:20px;' href='javascript:AdjustFrequency(-500);' title='Laat foto&#8217;s korter zien (- &#189; sek. per klik)'>Sneller</a>";
		Link.innerHTML = "<a class='smallcommandlink' href='javascript:AdjustFrequency(-500);' title='Laat foto&#8217;s korter zien (- &#189; sek. per klik)'>Sneller</a>";
		}
	}
	
function newwindow(image, width, height)
{
//To position the new window in the centre of the screen we first find out window size
var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  	{
    //Non-IE
   myWidth = window.innerWidth;
   myHeight = window.innerHeight;
  	} 
  	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  	}
if( myWidth > 0 )
	myLeft = (myWidth - width) / 2;
if( myHeight > 0 )
	myTop = (myHeight - height) / 2;
window.open(image,'jav','width=' + width + ',height=' + height + ',top=' + myTop + ',left=' + myLeft);
//window.open(image,'jav','width=' + width + ',height=' + height + ',top=0,left=0');
} 

//for the menu
function navHover() {
    var lis = document.getElementById("navBar").getElementsByTagName("LI");
    for (var i = 0; i<lis.length; i++) {
        lis[i].onmouseover=function() {
            this.className += " iehover";            
        }
        lis[i].onmouseout=function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");            
        }
    }
}
