// JavaScript Document
function InitializeSlide(pnlID,step,arySlideIndex,growWidth,growHeight) {
	if (arySlideIndex<0) {
		arySlideIndex=arySlideShow.length-1;
	}
	else if (arySlideIndex>arySlideShow.length-1) {
		arySlideIndex=0;
	}
	intCurrentSlide=arySlideIndex;
	
	var arySlide=arySlideShow[arySlideIndex];
	var pnlLoading=document.getElementById('pnlLoading');
	var imgSlide =document.getElementById('imgSlide');
	var pnl=document.getElementById(pnlID);
	var pnlWidth=parseInt(pnl.style.width.replace("px",""));
	var pnlHeight=parseInt(pnl.style.height.replace("px",""));
	
	pnlLoading.style.display='block';
	imgSlide.style.display='none';
	imgSlide.src=arySlideShow[arySlideIndex]['filename'];
	
	
	if (growWidth=='') {
		if (pnlWidth<arySlide['width']) {
			growWidth='grow';
		} else {
			growWidth='shrink';
		}
	}
	
	if (growHeight=='') {
		if (pnlHeight<arySlide['height']) {
			growHeight='grow';
		} else {
			growHeight='shrink';
		}
	}
	ResizePanel(pnlID,step,arySlideIndex,growWidth,growHeight)
	
}

function ResizePanel(pnlID,step,arySlideIndex,growWidth,growHeight) {
	var pnl=document.getElementById(pnlID);
	var arySlide=arySlideShow[arySlideIndex];
	var pnlWidth=parseInt(pnl.style.width.replace("px",""));
	var pnlHeight=parseInt(pnl.style.height.replace("px",""));
	var bGrow=false;
	
	if (pnlWidth<arySlide['width'] && growWidth=="grow") {
		pnlWidth+=step;
		bGrow=true;
		if (pnlWidth>arySlide['width']) {
			pnlWidth=arySlide['width'];
		}
	}
	else if (pnlWidth>arySlide['width'] && growWidth=="shrink") {
		pnlWidth=pnlWidth-step;
		bGrow=true;
		if (pnlWidth<arySlide['width']) {
			pnlWidth=arySlide['width'];
		}
	}

	else if (pnlHeight<arySlide['height'] && growHeight=="grow") {
		pnlHeight+=step;
		bGrow=true;
		if (pnlHeight>arySlide['height']) {
			pnlHeight=arySlide['height'];
		}
	}
	else if (pnlHeight>arySlide['height'] && growHeight=="shrink") {
		pnlHeight=pnlHeight-step;
		bGrow=true;
		if (pnlHeight<arySlide['height']) {
			pnlHeight=arySlide['height'];
		}
		
	}

	if (bGrow) {
		pnl.style.width=pnlWidth+"px";
		pnl.style.height=pnlHeight+"px";
		setTimeout("ResizePanel('"+pnlID+"',"+step+","+arySlideIndex+",'"+growWidth+"','"+growHeight+"');",20);	
	}
	else {
		var pnlLoading=document.getElementById('pnlLoading');
		var imgSlide =document.getElementById('imgSlide');
		var lblAltText = document.getElementById('lblAltText');
		var lblSlideShowCounter = document.getElementById('lblSlideShowCounter');
		if (arySlide['xlfilename']!="") {
			var hlViewLarger =document.getElementById('hlViewLarger');
			hlViewLarger.href="javascript:OpenLarger('"+arySlide['xlfilename']+"','"+arySlide['xlwidth']+"','"+arySlide['xlheight']+"')";
			hlViewLarger.innerHTML="<br>View Larger";
		}
		pnlLoading.style.display='none';
		imgSlide.style.display='block';
		lblAltText.innerHTML=arySlide['alttext'];
		if (arySlideShow.length>1) {
			lblSlideShowCounter.innerHTML=(arySlideIndex+1)+" of "+arySlideShow.length;
		}
	}
	
}

function Play(pnlID,step,arySlideIndex) {
	InitializeSlide(pnlID,step,(intCurrentSlide+1),'','');
}

function Player(cmd,pnlID,step) {
		switch(cmd) {
		case "stop":
 			if (!timer) return false;
			clearInterval(timer);
  			break;
		case "play":
			timer = setInterval("Play('"+pnlID+"',"+step+","+(intCurrentSlide+1)+")",3000);
  			break;
		}
		

}

function OpenLarger(src,width,height) {
	window.open(src,'lg','width='+width+',height='+height);
}