// JavaScript Document

///////////////////////////////////////////////////////////////////////
/// menu functions
///////////////////////////////////////////////////////////////////////////
function buildThumbNav(nbPerRow){

	htmlEmptyCell = '<td><img src="images/spacer.gif" width="59" height="43" /></td>';
	
	var myHtml = "<table><tr>";
	for(i=1; i <= numberOfimage; i++ ){
		//alert("?");
		myHtml += '<td width="66"  width="59" height="43"> '+ '<a href="#" class="highlightit">' +"<img  border='0' src=" +imgPrefixTb+ checkIfUnderTen(i)+  '.jpg  onClick= "setImage('+ i +');"  />'+ "</a></td>";
		
		numberOfEmptyCellLeft = Math.floor(nbPerRow - (numberOfimage/2))-1;
		numberOfEmptyCellRight = Math.ceil(nbPerRow - (numberOfimage/2))-1;
		
		if((i % nbPerRow == 0) && (i !=0)){ 
			myHtml += "</tr><tr>";
			for (l=0; l<=numberOfEmptyCellLeft; l++ ){
			myHtml += htmlEmptyCell;
			
			}
		}
	}
	
	for (l=0; l<=numberOfEmptyCellRight; l++ ){
		myHtml += htmlEmptyCell;
			
	}
	myHtml += "</tr></table>"
	return document.getElementById('imgNav').innerHTML = myHtml;
}


///////////////////////////////////////////////////////////////////////
///   swap image
///////////////////////////////////////////////////////////////////////////

function checkIfUnderTen(numero){
	if (eval(numero) < 10){
		numero = "0"+numero;
		}
	return numero
	
}
	
function setImage(num){
	if((num <= numberOfimage) &&(num > 0)){
		globalImg = num;
		document.getElementById('imgConatiner').innerHTML= "<img src=" +imgPrefix+ checkIfUnderTen(num)+".jpg />"
	}
	
	if(num == 1){ //on cache left arrow
		document.getElementById('leftArrow').innerHTML= "";
	}else{
		document.getElementById('leftArrow').innerHTML= '<div align="right" id="leftArrow"><a href="#"><img src="images/arrow-left-off.gif" name="arrowLeft" width="15" height="18" border="0" id="arrowLeft" onmouseover="MM_swapImage(\'arrowLeft\',\'\',\'images/arrow-left-on.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="btArrow(\'back\');" /></a> </div>';
	}
	
	if(num == numberOfimage){ //on cache left arrow
		document.getElementById('rightArrow').innerHTML= "";
	}else{
		document.getElementById('rightArrow').innerHTML= '<div align="right"  id="rightArrow"> <a href="#"><img src="images/arrow-right-off.gif" name="arrowRight" width="15" height="18" border="0" id="arrowRight" onmouseover="MM_swapImage(\'arrowRight\',\'\',\'images/arrow-right-on.gif\',1)" onmouseout="MM_swapImgRestore()"  onclick="btArrow(\'next\');" /></a></div>';
	}
	
}
	
function btArrow(strDirection){
		if(strDirection == "next"){
		var operator = 	1	;	
		}else{
			var operator = 0-1;
		}
		setImage(globalImg + operator);
}