var imagePosition = phpVars.tnCnt - 1;
var thumbPosition = 0;


// function preLoadImages() {
//	var preLoad = new Array()
//	
//	for(i = 0; i < 5 && i < p; i++) {
//	   preLoad[i] = new Image()
//	   preLoad[i].src = phpVars.imageDir + "tn/0/" + phpVars.images[i]
//	}
//}


function tnRollOff(thumbSlot) {
	document.images["tn" + (phpVars.tnCnt - 1 - thumbSlot)].src = phpVars.imageDir + "tn/0/" + phpVars.images[imagePosition - thumbSlot];
}
function tnRollOver(thumbSlot) {
	document.images["tn" + (phpVars.tnCnt - 1 - thumbSlot)].src = phpVars.imageDir + "tn/1/" + phpVars.images[imagePosition - thumbSlot];
}


function swapImage(thumbSlot) {
	thumbPosition = imagePosition - thumbSlot;
	updateImage();
}


function showNext() {
	if(thumbPosition + 1 < phpVars.images.length) {
		thumbPosition++;
		
		if(thumbPosition % phpVars.tnCnt == 0)
			scrollTnFw();
		
		updateImage();
	}
}
function showPrev() {
	if(thumbPosition - 1 >= 0) {
		thumbPosition--;
		
		if(thumbPosition % phpVars.tnCnt == phpVars.tnCnt - 1)
			scrollTnBw();
		
		updateImage();
	}
}


function updateImage() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.images['image'].style.filter="blendTrans(duration=0.5)";
		document.images['image'].filters.blendTrans.Apply();
		document.images['image'].filters.blendTrans.Play();
	}

	document.images['image'].src = phpVars.imageDir + phpVars.images[thumbPosition];
	
	document.getElementById("slideStatus").innerHTML = thumbPosition + 1 + " of " + phpVars.images.length;
	
	refreshArrows();
}


function scrollTnFw() {
	for(i = 0; i < phpVars.tnCnt; i++) {
		imagePosition++;
		if (imagePosition < phpVars.images.length) {
			document.images['tn' + i].style.visibility = 'visible';
			document.images['tn' + i].style.display='inline';
			document.images['tn' + i].src = phpVars.imageDir + "tn/0/" + phpVars.images[imagePosition];
		}
		else {
			document.images['tn' + i].style.visibility = 'hidden';
			document.images['tn' + i].style.display='none';
			document.images['tn' + i].src = "";
		}
	}
}
function scrollTnFw_old() {
	var elem = document.getElementById("tngalerie").getElementsByTagName("img")
	for(var i = 0; i < elem.length; i++) {
		elem[i].src = "images/wedding/tn/wedding-photography_001_tn1.jpg";
	} 
}


function scrollTnBw() {
	for(i = phpVars.tnCnt - 1; i >= 0; i--) {
		imagePosition--;
		document.images['tn' + i].style.visibility = 'visible';
		document.images['tn' + i].style.display='inline';
		document.images['tn' + i].src = phpVars.imageDir + "tn/0/" + phpVars.images[imagePosition - phpVars.tnCnt + 1];
	}
}


function refreshArrows() {
		if (thumbPosition > 0) {
			document.images['arrow_l'].style.visibility = 'visible';
			document.images['arrow_l'].style.display='inline';
		}
		else {
			document.images['arrow_l'].style.visibility ="hidden";
			document.images['arrow_l'].style.display='none';
		}
		
		if (thumbPosition < phpVars.images.length - 1) {
			document.images['arrow_r'].style.visibility = 'visible';
			document.images['arrow_r'].style.display='inline';
		}
		else {
			document.images['arrow_r'].style.visibility ="hidden";
			document.images['arrow_r'].style.display='none';
		}
}

