/*
**********************************************
easyALBUM: do not remove copyright information
version 1.1.6 Copyright 2006, Thierry Koblentz
http://www.TJKDesign.com - all rights reserved
**********************************************
*/
var TJK_gallery;
var TJK_anchor;
var TJK_itemNumber;
var TJK_stage;
var TJK_itemTitle;
var TJK_itemDescription;
var TJK_navPrev;
var TJK_navClose;
var TJK_navNext;
var TJK_zCounter;
var TJK_zImage;

/* toegevoegd door Mike: */
function closeTag(tg)
{
	return '<'+'/'+tg+'>';	// omdat "/"-es mijn syntax coloring om zeep helpen...
}

function TJK_Gallery(zElement)
{
	TJK_gallery = zElement;	
	TJK_anchor = document.getElementById(TJK_gallery).getElementsByTagName("a");

	// building the whole thing from scratch starting with the slideshow
	// zDIV_slideShow
	jQuery('body').eq(0).append('<div id="zDIV_slideShow">'+closeTag('div'));
	zDiv_wrapper = document.getElementById('zDIV_slideShow');
// zA_previous
	jQuery('#zDIV_slideShow').append('<a href="#null" id="zA_previous" title="'+altVorige+'"><img src="/images/easyAlbumVorige.gif" alt="'+altVorige+'" class="easyAlbumBtn" />'+closeTag('a'));
// zA_close		
	jQuery('#zDIV_slideShow').append('<a href="#null" id="zA_close" title="'+altSluiten+'"><img src="/images/easyAlbumSluiten.gif" alt="'+altSluiten+'" class="easyAlbumBtn" />'+closeTag('a'));
// zA_next		
	jQuery('#zDIV_slideShow').append('<a href="#null" id="zA_next" title="'+altVolgende+'"><img src="/images/easyAlbumVolgende.gif" alt="'+altVolgende+'" class="easyAlbumBtn" />'+closeTag('a'));
// zA_title		
	jQuery('#zDIV_slideShow').append('<a href="" id="zA_title">Title'+closeTag('a'));
// zA_image		
	jQuery('#zDIV_slideShow').append('<a href="" id="zA_image"><img src="" id="" alt="zIMG" />'+closeTag('a'));
// zDIV_counter
	jQuery('#zDIV_slideShow').append('<div id="zDIV_counter">Teller'+closeTag('div'));
// zA_description		
	jQuery('#zDIV_slideShow').append('<a href="#" id="zA_description">Beschrijving'+closeTag('a'));

	for (var x=0,i=TJK_anchor.length;x<i;x++)
	{
		TJK_anchor[x].onclick = badabingbadaboum;
		// we create fragment identifier to be used to navigate and keep track of the items and we kick start the whole thing
		TJK_anchor[x].href = TJK_anchor[x].href+"#"+x;
		// we create a container to receive the text links
		var zSPAN = document.createElement('span');
		TJK_anchor[x].appendChild(zSPAN);
		var zTextLink = document.createTextNode(TJK_anchor[x].title);
		zSPAN.appendChild(zTextLink);
	}
}	
function goPrevious()
{
	TJK_itemNumber = eval(document.getElementById("zA_title").hash.substring(1));	// waarom dit met eval gebeurt, weet ik niet; voor de snelheid misschien?

	// hiding the button if we are on first slide 
	if(TJK_itemNumber==1)this.className="transparent";
	TJK_navNext.className="nonOpaque";
	if(TJK_itemNumber==0) { return; } // we are at the beginning	

	TJK_zImage.src = TJK_anchor[TJK_itemNumber-1].href;
	TJK_zImage.alt = TJK_itemTitle.firstChild.data;		
	TJK_itemTitle.href = TJK_anchor[TJK_itemNumber-1].href;
	TJK_itemTitle.firstChild.data = TJK_anchor[TJK_itemNumber-1].getElementsByTagName("img")[0].alt;
	TJK_itemDescription.firstChild.data = TJK_anchor[TJK_itemNumber-1].title;

	// special care for this one in case there is no long description set		
	if(TJK_anchor[TJK_itemNumber-1].getElementsByTagName("img")[0].longDesc)
	{
		TJK_itemDescription.href = TJK_anchor[TJK_itemNumber-1].getElementsByTagName("img")[0].longDesc;	
		// appendData() breaks IE5 Win
		TJK_itemDescription.firstChild.data=TJK_anchor[TJK_itemNumber-1].title+" [more info...]";
		TJK_itemDescription.title = linkToMoreInfo; // "Follow this link for more Information";	
		TJK_itemDescription.className="noHand";
		TJK_itemDescription.style.textDecoration ="underline";
	}
	else
	{
		TJK_itemDescription.className="withHand";
		TJK_itemDescription.title="";
		TJK_itemDescription.href="#";
		TJK_itemDescription.style.textDecoration ="none";
	}
	// we update the value of the counter in the DIV
	var current = eval(document.getElementById("zA_title").hash.substring(1)) + 1;
	TJK_zCounter.firstChild.data = "Item #"+current+" out of "+TJK_anchor.length;
}

function goNext()
{
	TJK_itemNumber = eval(document.getElementById("zA_title").hash.substring(1));
	// hiding the button if we are on the last slide 
	if(TJK_itemNumber==TJK_anchor.length-2)this.className="transparent";
	TJK_navPrev.className="nonOpaque";
	if(TJK_anchor.length == TJK_itemNumber+1){return} // we are at the end	

	TJK_zImage.src = TJK_anchor[TJK_itemNumber+1].href;
	TJK_zImage.alt = TJK_itemTitle.firstChild.data;		
	TJK_itemTitle.href = TJK_anchor[TJK_itemNumber+1].href;
	TJK_itemTitle.firstChild.data = TJK_anchor[TJK_itemNumber+1].getElementsByTagName("img")[0].alt;
	TJK_itemDescription.firstChild.data = TJK_anchor[TJK_itemNumber+1].title;
	// special care for this one in case there is no long description set		
	if(TJK_anchor[TJK_itemNumber+1].getElementsByTagName("img")[0].longDesc)
	{
		TJK_itemDescription.href = TJK_anchor[TJK_itemNumber+1].getElementsByTagName("img")[0].longDesc;	
		// appendData() breaks IE5 Win
		TJK_itemDescription.firstChild.nodeValue=TJK_anchor[TJK_itemNumber+1].title+" [more info...]";
		TJK_itemDescription.title = linkToMoreInfo; // "Follow this link for more Information";	
		TJK_itemDescription.className="noHand";
		TJK_itemDescription.style.textDecoration ="underline";
	}
	else
	{
		TJK_itemDescription.className="noHand";
		TJK_itemDescription.title="";
		TJK_itemDescription.href="#";
		TJK_itemDescription.style.textDecoration ="none";
	}
	// we update the value of the counter in the DIV
	var current = eval(document.getElementById("zA_title").hash.substring(1)) + 1;
	TJK_zCounter.firstChild.data = "Item #"+current+" out of "+TJK_anchor.length;	
}

// to make sure users don't follow the link in the title (it is there to be used as a match with the thumbnail that triggered the popup DIV)
function fakeIt()
{
	return false;
}

// hiding the SlideShow
function hideTJK_stage()
{
	document.getElementById("zDIV_slideShow").style.height="0"; // IE5 Mac
	document.getElementById("zDIV_slideShow").style.overflow="hidden"; // IE5 Mac
	document.getElementById("zDIV_slideShow").style.display="none";
	// we remove the opacity stuff
	document.getElementById("wrapper").className="none";
	jQuery('#wrapper').css('opacity',1);
	// we set focus back to the thumbnail that triggered the "popup" DIV
	var TJK_itemNumber = eval(document.getElementById("zA_title").hash.substring(1));
	TJK_anchor[TJK_itemNumber].focus();
}

function badabingbadaboum()
{
	TJK_stage = document.getElementById("zDIV_slideShow");
	TJK_itemTitle = document.getElementById("zA_title");
	TJK_itemDescription = document.getElementById("zA_description");
	TJK_navPrev = document.getElementById("zA_previous");
	TJK_navClose = document.getElementById("zA_close");
	TJK_navNext = document.getElementById("zA_next");
	TJK_zCounter = document.getElementById("zDIV_counter");
	TJK_zImage = document.getElementById("zA_image").getElementsByTagName("img")[0];
	// we do some opacity stuff
	document.getElementById("wrapper").className="transparent";
	jQuery('#wrapper').css('opacity',0.2);

	// IE5 Mac (phantom links)
	// this.blur();
	// this is to reset the fix for IE Mac (see statement in (hideTJK_stage())	
	TJK_stage.style.height="100%";
	TJK_stage.style.display="block";
	TJK_zImage.src = this.href.replace(this.hash,"");
	TJK_zImage.alt = this.getElementsByTagName("img")[0].alt;
	TJK_zImage.onclick = hideTJK_stage;
	
	// "style.cursor" breaks IE5
	TJK_zImage.className = "hand";
	TJK_zImage.title =  altSluiten; //"Back to the Gallery";
	// the href value we set for this anchor will be used to give focus back to the appropriate thumbnail 
	TJK_itemTitle.setAttribute("href",this.href);
	// since we have a real href value in there we don't want the user to trigger the link
	TJK_itemTitle.onclick=fakeIt;
	// clicking on the close box will close the popup DIV
	TJK_navClose.onclick=hideTJK_stage;
	// setting the action for the prev/next links
	TJK_navPrev.onclick=goPrevious;
	TJK_navNext.onclick=goNext;	
	// now we can set focus for keyboard users
	TJK_navPrev.focus();
	// setting the height - mainly for IE - the second one is for IE5
	TJK_stage.style.height = (document.documentElement.clientHeight > 0) ? document.documentElement.clientHeight+"px" : document.body.clientHeight+"px";
	// setting the width for IE 5 so there is no gap near the scrollbar
	if(document.documentElement.clientHeight == 0)TJK_stage.style.width=document.body.clientWidth+"px" ;
	// setting the title and description
	TJK_itemTitle.firstChild.data = this.getElementsByTagName("img")[0].alt;
	TJK_itemDescription.firstChild.data = this.title;

	// if there is a long description in there, we use it as href value of the short description and we give it a title to. If there is none we make sure we reset values previously set and we do not let the user follow the "empty" link
	if(this.getElementsByTagName("img")[0].longDesc)
	{
		TJK_itemDescription.href = this.getElementsByTagName("img")[0].longDesc;	
		// appendData() breaks IE5 Win
		TJK_itemDescription.firstChild.data=this.title+" [more info...]";
		TJK_itemDescription.title = "Follow this link for more Information";	
	}
	else
	{
		TJK_itemDescription.removeAttribute("href");	
		TJK_itemDescription.title = "";	
	}

	// we set the starting values for the "counter"
	var current = eval(TJK_itemTitle.hash.substring(1)) + 1;
	TJK_zCounter.firstChild.nodeValue = txtSlide +current+ txtOutOf +TJK_anchor.length;//"Slide #"+current+" out of "+TJK_anchor.length;	
	// hiding the button when everything "loads" depending on which slide we are on
	// first we reset both buttons in case they have been turned off last time the user left the slideshow
	TJK_navNext.className="nonOpaque";
	TJK_navPrev.className="nonOpaque";
	TJK_itemNumber = eval(document.getElementById("zA_title").hash.substring(1));
	if(TJK_itemNumber==0)
	{
		TJK_navPrev.className="transparent";
		TJK_navNext.className="nonOpaque";
	}
	
	if(TJK_itemNumber==document.getElementById(TJK_gallery).getElementsByTagName("a").length-1)
	{
		TJK_navNext.className="transparent";
		TJK_navPrev.className="nonOpaque";
	}
	
	return false;	// voorkomen dat link geactiveerd wordt
}
