// JavaScript Document
var currentI = -1;
function enlargeImage(i) {
	document.getElementById('enlargeImg').src = 'images/gallery/'+imgId[i]+'.jpg';
	document.getElementById('enlargeImg').style.width = imgWidth[i]+'px';
	document.getElementById('enlargeImg').style.height = imgHeight[i]+'px';
	document.getElementById('descriptionImg').innerHTML = imgDescription[i];
	currentI=i;
	fadeIn(0);
}
function fadeIn(opacity) {
	if(opacity<100){
		opacity+=5;
		setOpacity(opacity);
		setTimeout("fadeIn("+opacity+")", 10);
	}
}
function fadeOut(i,opacity) {
	if(currentI!=i){
		if(opacity>0){
			opacity-=5;
			setOpacity(opacity);
			setTimeout("fadeOut("+i+","+opacity+")", 10);
		}
		else enlargeImage(i);
	}
}
function setOpacity(opacity){
	var object = document.getElementById('enlargeImg').style;
	object.opacity = opacity/100;
	object.MozOpacity = opacity/100;
	object.KhtmlOpacity = opacity/100;
	object.filter = "alpha(opacity="+opacity+")"; 
}
function clearGallery(){
	document.getElementById("galleryContent").innerHTML='';
}
function generateGallery(){
	for(var i=0;i<imgId.length-1;i++){
		var thumbHeight = imgHeight[i]/5;
		var thumbWidth = imgWidth[i]/5;
		document.getElementById("galleryContent").innerHTML=document.getElementById("galleryContent").innerHTML+'<img src="images/gallery/'+imgId[i]+'.jpg" class="thumbnail" width="'+thumbWidth+'" height="'+thumbHeight+'" onmouseover="this.style.border=\'1px solid #000000\'" onmouseout="this.style.border=\'1px solid #FFFFFF\'" onmousedown="fadeOut('+i+',100);if(cycle==true) cycleStopStart();" alt="'+imgDescription[i]+'">';
	}
}
function startGallery(){
	var newI = currentI+1;
	if(newI>=imgId.length-1) newI = 0;
	fadeOut(newI,100);
}
setTimeout("startGallery();", 100);
var cycleInterval = setInterval("startGallery();", 5000);
var cycle = true;
function cycleStopStart(){
	if(cycle==true){
		clearInterval(cycleInterval);
		document.getElementById('buttonStartStop').value = 'Start Slideshow';
		cycle = false;
	}
	else {
		cycleInterval = setInterval("startGallery();", 5000);
		document.getElementById('buttonStartStop').value = 'Stop Slideshow';
		cycle = true;
	}
}
function nextImg(){
	if(cycle==true) cycleStopStart();
	startGallery();
}
function previousImg(){
	if(cycle==true) cycleStopStart();
	var newI = currentI-1;
	if(currentI==0) newI = imgId.length-2;
	fadeOut(newI,100);
}
