var fotoCount = 0
var fotosrow = 6
var	noPicThumbLocation = "http://www.z-spot.be/public/images/albums/noImage_thumb.jpg"
var photoNumberStart = 0

function init2(publicRoot)
{
	setImage(imageList[0][1], imageList[0][2])
	fotoCount = imageList.length
	setNavigation(0)	
}

function setImage(imgLocation, imgComment, photoNumber)
{
	photoNumb = photoNumber+photoNumberStart+1;
	
	var imgHtml = '<a href="'+imgLocation+'" target="_blanc"><img src="'+imgLocation+'" border="0" class="largeImg" /></a>';
		imgHtml += '<p class="imgComment">'+imgComment+'<br />';
		imgHtml += '('+photoNumb+'/'+fotoCount+')</p>';
	document.getElementById("currentImage").innerHTML = imgHtml;
}

function setThumb(thumbLocation, cellId, thumbId)
{
	var thumbHtml = '<img src="'+thumbLocation+'" onMouseDown="changeImage('+cellId+', '+thumbId+');" width="80"/>'
	document.getElementById(cellId).innerHTML = thumbHtml
}

function setEmptyThumb(cellId)
{
	var thumbHtml = '<img src="'+noPicThumbLocation+'" />'
	document.getElementById(cellId).innerHTML = thumbHtml
}

function setNavigation(count)
{
	var max = count + fotosrow
	var i = count
	var ii = 0
	
	while(i < max)
	{
		try{
			if(ii == 0){
				setImage(imageList[i][1], imageList[i][2], i)
				document.getElementById(ii).className = "thumbImgSelected"
			}
			setThumb(imageList[i][0], ii, i)
		}catch(err){
		   setEmptyThumb(ii)
		   document.getElementById(ii).className = "thumbImgInactive"
	    }

		i++;
		ii++;
	}
	setNavButtons(i)
}

function setNavButtons(lastImg)
{
	if(lastImg < fotoCount){
		var nextValue = '<img src="http://www.z-spot.be/public/images/icons/album_forward.png" onMouseDown="navChange(' + lastImg + ');" id="butNext"/>';
	}else{
		var nextValue = '&nbsp;'
	}

	if(lastImg > fotosrow){
		var backValue = '<img src="http://www.z-spot.be/public/images/icons/album_back.png" onMouseDown="navChange('+ (lastImg - 12) +');" id="butBack"/>'
	}else{
		var backValue = '&nbsp;';
	}

	document.getElementById("backButton").innerHTML = backValue
	document.getElementById("nextButton").innerHTML = nextValue

}

function navChange(count)
{	
	unsetThumbMark()
	setNavigation(count)
}

function changeImage(cellId, thumbId) 
{
	setImage(imageList[thumbId][1], imageList[thumbId][2], thumbId)
	unsetThumbMark()
	document.getElementById(cellId).className = "thumbImgSelected"
}

function unsetThumbMark()
{
	var i=0;
	
	while(i < fotosrow)
	{
		document.getElementById(i).className = "thumbImg"
		i++;
	}
}