/* This script is hand-written by Nguyen Duc Hieu, http://coffeemugvn.com */
var position = new Array;
var fileName = new Array;
var total = new Array;

function initialize(getFileName, getTotal, getCount) {
	count = getCount;
	fileName[count] = getFileName;	
	total[count] = getTotal;		
	position[count] = 1;
	
	printInfo(count);	

	var s='';	
	var i=0;
	for (i=total[count]; i>1; i--) {
		s = s + '<img src='+ fileName[count] + i + '.jpg />';		
	}	
	document.write('<div class="nodisplay">'+s+'</div>');

	//setImage(fileName[count] + position[count] + ".jpg", count);
}

// Create link function to switch image backward
function prev(getCount){	
	var count = getCount;
	position[count]--;
	if(position[count]<1){
		position[count]=total[count];
	}
	
	setImage(fileName[count] + position[count] + ".jpg", count);
	printInfo(count);	
}

// Create link function to switch image forward
function next(getCount){
	var count = getCount;
	position[count]++;
	if(position[count]>total[count]){
		position[count]=1;    
	}
	
	setImage(fileName[count] + position[count] + ".jpg", count);	
	printInfo(count);
}

function printInfo(getCount) {
	var count = getCount;
	
	var infoText = document.getElementById("photonav-info"+count);
	if (infoText) {
		infoText.innerHTML = position[count] + ' / ' + total[count];
	}
}

function setImage(imgSrc, getCount) {	
	var count=getCount;
	var bigphoto = document.getElementById("bigphoto"+count);
	
	if (bigphoto) {
		var imgs = bigphoto.getElementsByTagName("img");
		var img = imgs[0];
		img.src = imgSrc;
	}
}
