// JavaScript Document

function initForm(){ 

	document.images.MainPicture.src = picRoot + Pic[1] // set the current picture
	document.getElementById('picDescription').style.margin="5px"	
	document.getElementById('picDescription').innerHTML =  PicDescription[1] 
	document.getElementById('selectedPhotoId').innerHTML = 1 + " of " + stripLength.toString() + " Photos"	
	var oContainer = document.getElementById('picContainer');
	var oTable = document.createElement("table");
	oContainer.appendChild(oTable)
	var oTr = oTable.insertRow()
	for(var x=1;x<Pic.length;x++){
		var td = document.createElement("td")
		td.picIndex = x;
		td.onclick = function(){changeImage(this.picIndex)}
		td.vAlign="top";
		var img = document.createElement("img")
		img.src = picRoot + Pic[x]
		img.id = "icon" + x.toString()
		img.resized = false;
		img.name = "iconimg"
		img.onload = function(){resize(this)} 
		oTr.appendChild(td)	
		td.appendChild(img)

	}

}
function loadIcons(){
	var arrIcons = document.getElementsByName("iconimg")
	for(var i = 0; i<document.images.length;i++){
		if(document.images[i].name=="iconimg" && !document.images[i].resized){
			x = document.images[i].width;
			y = document.images[i].height;
			document.images[i].height= 100
			document.images[i].width = x/y*100
		}
	}	
	}
function resize(oIMG){	
			x = oIMG.width;
			y = oIMG.height;
			oIMG.height=100;
			a =  x/y*100

			oIMG.width =a
			//oIMG.style.display = "inline"
			oIMG.resized = true;
}
function changeImage(index){
	document.images.MainPicture.src = picRoot + Pic[index] // set the current picture
	document.getElementById('picDescription').style.margin="5px"
	document.getElementById('picDescription').innerHTML = PicDescription[index] 
	document.getElementById('selectedPhotoId').innerHTML = index + " of " + stripLength.toString() + " Photos"
//	document.getElementById('selectedPhotoId').innerHTML = index + " of 4 Photos"
//	alert(3)
	currentPhoto = index 
}

function RotatePhotoViewer(shift){
	if (shift == 1){
		if (currentPhoto == stripLength){
			changeImage(0)
		}
		if (currentPhoto != stripLength){
			changeImage(currentPhoto + 1)
		}
	}

	if (shift == -1){
		if (currentPhoto == 1){
			changeImage(stripLength + 1)
		}
		if (currentPhoto != 1){
			changeImage(currentPhoto - 1)
		}
	}
}
