//----configuration-------------------
	
	var imgArrNext = '<img src="../Templates/img/arrowRsm.gif" width="8" height="14" border="0" alt="next"/>';
	var imgArrLast = '<img src="../Templates/img/lastpic.gif" width="8" height="14" border="0" alt="last"/>';
	var imgArrPrev = '<img src="../Templates/img/arrowLsm.gif" width="8" height="14" border="0" alt="previous"/>';
	var imgArrFirst = '<img src="../Templates/img/firstpic.gif" width="8" height="14" border="0" alt="first" />';
	var imgPlay = "../Templates/img/icon_play.gif";
	var imgStop = "../Templates/img/icon_stop.gif";
	var imgSpacer = "../Templates/img/spacer.gif";
	
	//----end of configuration-----------
	
	
//	var imageCount  = imgGallery.length; removed so we can avoid the variable declaration error; replaced with if statement
if(imgGallery){
  var imageCount  = imgGallery.length;
 }

	
	var isIE = false; 
	var agt = navigator.userAgent.toLowerCase();
	var mac_ie = ((agt.indexOf("mac")!= -1) && (agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var mac_safari = ((agt.indexOf("mac")!= -1) && (agt.indexOf("safari") != -1));
	var sThumbStrip = "";
	var rotate_delay = 6000; 
	var autoPlayMode = false;

	function parseMessages() {
		var nImageID = "";        
		var sTempStr = "";
	    
		for (var i=0;i<imageCount;i++)
			sTempStr = sTempStr + '<a href="javascript:void(showInternetImage(' + i + '));"><img src="' + imgGallery[i] + '_thumb.jpg" + border="0" class="thumb" alt=""/></a>';
	        
		if (sTempStr.length > 0){						
			document.getElementById("motiongallery").innerHTML = '<span id="trueContainer">' + sTempStr + '</span>';    
			sThumbStrip =  document.getElementById("motiongallery").innerHTML; 	
			showInternetImage(0);
			fillup();
		}
			
			
		if (document.getElementById("spAutoPlay")!=null) {
			document.getElementById("spAutoPlay").alt = "Auto Play";
			document.getElementById("spAutoPlay").src = imgPlay;
		}
			
						
		if (imageCount < 4){
			if (imageCount == 1) {
				document.getElementById("spAutoPlay").alt = "";		
				document.getElementById("spAutoPlay").src = imgSpacer;		
			}
			if (document.getElementById("motionleftObj")!=null)
				document.getElementById("motionleftObj").innerHTML = "";
			if (document.getElementById("motionrightObj")!=null)
				document.getElementById("motionrightObj").innerHTML = "";			
		}
			
			
		sTempStr= "";
	}
		
	function showInternetImage(num){   
	
		nCurPos = num;      
		//display viewable image for jpg and flash

		var strImageSource = '<a href=#" onclick="NewWindow(\'' + imgGallery[num] + '.jpg\', \'Gallery\',\'768\',\'768\',\'yes\',\'center\');">';
		strImageSource = strImageSource + '<img src="' + imgGallery[num] + '.jpg" onload="checkRotate(\'' + imgGallery[num+1] + '.jpg\');" border="0" name="imgIntImageSrc" alt="" /></a>';
			
		document.getElementById("IntImageSource").innerHTML = strImageSource;
		//if (document.getElementById("ImageTitle")!=null)
		//	document.getElementById("ImageTitle").innerHTML = "<b>" + oNodeImage.getAttribute("Caption") + "</b>";

		if (document.getElementById("arrowNext")!=null){
			if (nCurPos == imageCount-1){
				document.getElementById("arrowNext").innerHTML = '';
				document.getElementById("arrowLast").innerHTML = '';
				if(autoPlayMode){
					window.clearTimeout(ap);
					autoPlayMode = false;
					showStartPlay();
				}
			}
			else{
				document.getElementById("arrowNext").innerHTML = imgArrNext;
				document.getElementById("arrowLast").innerHTML = imgArrLast;
			}
		}
		if (document.getElementById("arrowPrev")!=null){
			if (nCurPos == 0)	{
				document.getElementById("arrowPrev").innerHTML = '';
				document.getElementById("arrowFirst").innerHTML = '';
			}
			else {
				document.getElementById("arrowFirst").innerHTML = imgArrFirst;
				document.getElementById("arrowPrev").innerHTML = imgArrPrev;
			}
		}
		
	}	
	
	function goNextPrevImage(bIncrement){
		if (bIncrement)
			nCurPos++;  
		else
			nCurPos--; 			

		if (imgGallery[nCurPos]!=null){
			showInternetImage(nCurPos); 
			if (bIncrement){
				if (imgGallery[nCurPos+1]!=null)
					OnLoadEvent(imgGallery[nCurPos+1] + '.jpg');
			}
			else {
				if (imgGallery[nCurPos-1]!=null)
					OnLoadEvent(imgGallery[nCurPos-1] + '.jpg');
			}
		}			  
	}
	
	function goLastImage(){
		nCurPos =   imageCount-1;
			
		if (imgGallery[nCurPos]!=null){
			showInternetImage(nCurPos); 
			OnLoadEvent(imgGallery[nCurPos] + '.jpg');
		}			  
	}
	
	function goFirstImage(){

		nCurPos = 0;
		if (imgGallery[nCurPos]!=null){
			showInternetImage(nCurPos); 
			OnLoadEvent(imgGallery[nCurPos] + '.jpg');
			}			  
	}
		
	function OnLoadEvent(sPreLoadImageSrc){
		var tmpImage = new Image;
	    
		if (document.images)
			tmpImage.src = sPreLoadImageSrc;
	}
	
	function showStopPlay(){
		document.getElementById("spAutoPlay").alt = "Stop";
		document.getElementById("spAutoPlay").src = imgStop;
	}

	function showStartPlay(){
		document.getElementById("spAutoPlay").alt = "Auto Play";
		document.getElementById("spAutoPlay").src = imgPlay;
	}

	function autoPlay() {
		if (document.getElementById("spAutoPlay").alt == "Auto Play")
			autoPlayMode = true;
		else
			autoPlayMode = false;
			
		(autoPlayMode)?showStopPlay():showStartPlay();
		rotate();                             
	}
	var ap;
	function checkRotate(sImageNextSrc) {	
		if(autoPlayMode)
			ap=window.setTimeout('rotate()', rotate_delay);
		if (sImageNextSrc.length > 0)
			OnLoadEvent(sImageNextSrc);
	}

	function rotate() {
		if (autoPlayMode) {
			goNextPrevImage(true);
		}
	}	
	
	var win=null;
	function NewWindow(mypage,myname,w,h,scroll,pos){
		if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
		if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/3:100;TopPosition=(screen.height)?(screen.height-h)/3:100;}
		else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=0}
			settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
			win=window.open(mypage,myname,settings);
		if(win.focus){win.focus();}
	}
	
	function CloseNewWin(){
		if(win!=null && win.open)win.close()
	}
	window.onfocus=CloseNewWin;
// -->
