/* 20050603
		
	$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	
	CONTENTS: Gallery Controls
	SECTIONS:
	SET IMAGES IN PLACE 
	FLASH CONTAINER
	EVENT FIRING 
	TIME TRACKING 
	IMAGE DIRECTIONS 
	PREVIEW CONTROL 
	PAUSE CONTROL 
	SUBSCRIPTION 
	LOAD IMAGE/TITLE INFORMATION 
	MENU WINDOW CONTROLS 
	makeMenusVisible
	COOKIES 
	MISC 
	
	$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
	$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$			
*/
	/* ***************************************************************************** BEGIN SET IMAGES IN PLACE   */
	function pauseIconOff(oDiv)
	{//show/hide pause icon
		
		oDiv.style.display="none";
	}
	var previousDiv=false;
	var nextDiv=false;
	function getItems(itemNumber)
	 {
		setEventTime();
		autoPlayInterval=arrayAutoPlayInterval[getThisItem];
		if(itemNumber==itemDisplayed)
		{
			//pause the show
			setPause(1);
			//show pause icon
			//alert('paused');
		}
		else
		{//SHOW IS NOT PAUSED
			if(itemNumber>=0)
			{
				getThisItem=itemNumber;	
			}
			//alert(itemNumber);
			if(!(itemNumber))
			{
				//alert('undefined');
				//alert(getThisItem);
				var itemNumber=getThisItem;
				//getThisItem=itemNumber;
				//alert(getThisItem);
			}
			//alert(itemNumber+"    iN : getThisItem    "+getThisItem);
			/* START FLASH PLAYER IF NECESSARY */
			if(jsMasterItemsArray[getThisItem]=="swfItem")
			{/*if it is a swf item then load the source into flash*/
				var swfName='swf_'+ch+'_'+sh+'_'+getThisItem;
				resumeFlash(swfName);
			}
			if(fadePlayerItems==true)
			{//if I want images to fade into each other
				//first, move the next image underneath the existing image.
				var previousMedia=document.getElementById('itemDiv_'+ch+"_"+sh+"_"+itemDisplayed);
				var previousMediaDesc=document.getElementById('itemDesc_'+ch+"_"+sh+"_"+itemDisplayed);
				var playMediaNow=document.getElementById('itemDiv_'+ch+"_"+sh+"_"+getThisItem);
				playMediaNow.style.zIndex=(parseFloat(itemViewZIndex)-2);
				previousDiv=previousMedia;
				nextDiv=playMediaNow;
				//alert("previousDivId: "+previousDiv.id+" nextDivId: "+nextDiv.id+" previousDivZIndex: "+previousDiv.style.zIndex+" nextDivzIndex: "+nextDiv.style.zIndex+" previousDiv opacity: "+previousDiv.style.opacity+" nextDiv opacity: "+nextDiv.style.opacity);
				fade(previousDiv.id);
				if(jsMasterItemsArray[itemDisplayed]=="swfItem")
				{/*if it is a swf item then load the source into flash*/
					
					var swfName='swf_'+ch+'_'+sh+'_'+getThisItem;
					pauseFlash(swfName);
					setTimeout("rewind('"+swfName+"')",750);
				}
				var playMediaNowDesc=document.getElementById('itemDesc_'+ch+"_"+sh+"_"+getThisItem);
				playMediaNowDesc.style.zIndex=itemDescViewZIndex;
				if(progressBarView==true)
				{
					var progressBar=document.getElementById('progressBar_'+ch+"_"+sh+"_"+getThisItem);
					progressBar.style.backgroundColor="#9E5654";
					var prevProgressBar=document.getElementById('progressBar_'+ch+"_"+sh+"_"+itemDisplayed);
					prevProgressBar.style.backgroundColor="#422F2F";
				}
				previousMediaDesc.style.zIndex=10+itemDisplayed;
				lastItemTimeChange=returnCurrentTime();
				itemDisplayed=getThisItem;
			}
			else
			{//images won't fade into each other
				/*pause and rewind any swfs*/
				if(jsMasterItemsArray[itemDisplayed]=="swfItem")
				{/*if it is a swf item then load the source into flash*/
					var swfName='swf_'+ch+'_'+sh+'_'+getThisItem;
					pauseFlash(swfName);
					setTimeout("rewind('"+swfName+"')",750);
				}
				var playMediaNow=document.getElementById('itemDiv_'+ch+"_"+sh+"_"+getThisItem);
				playMediaNow.style.zIndex=itemViewZIndex;
				var previousMedia=document.getElementById('itemDiv_'+ch+"_"+sh+"_"+itemDisplayed);
				previousMedia.style.zIndex=10+itemDisplayed;
				var playMediaNowDesc=document.getElementById('itemDesc_'+ch+"_"+sh+"_"+getThisItem);
				playMediaNowDesc.style.zIndex=itemDescViewZIndex;
				var previousMediaDesc=document.getElementById('itemDesc_'+ch+"_"+sh+"_"+itemDisplayed);
				previousMediaDesc.style.zIndex=10+itemDisplayed;
				if(progressBarView==true)
				{
					var progressBar=document.getElementById('progressBar_'+ch+"_"+sh+"_"+getThisItem);
					progressBar.style.backgroundColor="#9E5654";
					var prevProgressBar=document.getElementById('progressBar_'+ch+"_"+sh+"_"+itemDisplayed);
					prevProgressBar.style.backgroundColor="#422F2F";
				}
				lastItemTimeChange=returnCurrentTime();
				itemDisplayed=getThisItem;
			}
		}//end SHOW NOT PAUSED
	 }
	 function autoPlay()
	 {
		 	
		/*need to introduce a paused timer here. this would keep the time that something is paused, then calculate that back into this equation
		so that the timing of the show is accurate*/
		
		if ((paused!='yes'))
		{
		/* this last OR condition was added to try and ensure pausing is happening when
			the channelGuide is launched. 
		
		 */	
			if (autoPlayCycle < itemCounter)
			{
				var timeNow=returnCurrentTime();
				var spread;
				/*20061024 modify so that it is based upon lastItemTimeChange time rather than spreads  previous code removed*/
				spread=timeNow - lastItemTimeChange;
				if (spread > autoPlayInterval)
				{
					nextItem();
					autoPlayCycle=itemDisplayed;
					autoPlayTime=currentTime;
				}
				else
				{
				}
			}
			else
			{
				alert('autoplaycycle is not less than item counter');
				/* slide show is paused */ 
			}
		} 
		  evaluateAutoPlay();
	 }
	/* check to determine if you should autoPlay */
	function evaluateAutoPlay()
	{
		setTimeout("autoPlay()",250);
		
	}

/* ***************************************************************************** BEGIN IMAGE DIRECTIONS  */
 function nextItem()
 {
	setEventTime();
	getThisItem=parseFloat(getThisItem);
	//alert(itemDisplayed);
	itemDisplayed=parseFloat(itemDisplayed);
	if(!(document.getElementById('itemDiv_'+ch+"_"+sh+"_"+getThisItem)))
	{
		
	}
	else
	{
		//alert(itemDisplayed+" "+getThisItem);
		//var playMediaNow=document.getElementById('itemDiv_'+ch+"_"+sh+"_"+getThisItem);
		//playMediaNow.style.zIndex=968;
	}
	if (itemDisplayed==(itemCounter-1))
	{ 
		if (loop==1)
		{
			/*20050608 loop only the show*/
			
			getThisItem=0;
			getItems(getThisItem);
		}
		else
		{
			/*20050608 if loop = other follow instructions setup in decideNextPrev*/
			//window.location=nextPage;
		}
	}
	else if (itemDisplayed < itemCounter) 
	{
		/* regular item, advance to next */
		getThisItem=itemDisplayed + 1;
		getItems(getThisItem);
	}
	else
	{
		alert('why here');	
	}
	
 }
 function prevItem()
 {
	setEventTime();
	if ( itemDisplayed > 0)
	{
		getThisItem=itemDisplayed - 1;
		getItems(getThisItem);
	}
	else if ((itemDisplayed==0))
	{
		/* First item in the show */
		if (loop==1)
		{
			/*if loop equals one loop 1 = loop the show*/
			/* if gallery is on the very first image and someone clicks back arrow, 
		    this sets the preview to the total number of images - 1
			*/
			getThisItem=itemCounter- 1;
			getItems(getThisItem);
		}
		else
		{
			/*20050608 if loop = other follow instructions setup in decideNextPrev*/
			//window.location=prevPage;
		}
	}
 }

/* ***************************************************************************** BEGIN PAUSE CONTROL  */
		 
var pauseAction=0;
/*20061024 autoPlayPauseCorrection added. keeps track of the autoPlayInterval while pause is on*/
var autoPlayPauseCorrection=0;
function setPause(action)
 {	
 /*  action signifies that a human action happened. 
 evaluate hide tools checks the action variable to stop flicker...
 */	
	if ((paused=="no")&&(action==1))
	{
		if(document.getElementById('progressBarPause_'+ch+'_'+sh+'_'+getThisItem).style.display!="block")
		{
			document.getElementById('progressBarPause_'+ch+'_'+sh+'_'+getThisItem).style.display="block";
		}
		if(jsMasterItemsArray[getThisItem]=="swfItem")
		{/*if it is a swf item then load the source into flash*/
			var swfName='swf_'+ch+'_'+sh+'_'+getThisItem;
			pauseFlash(swfName);
		}
		paused="yes";
		pauseAction=1;
		/*20061024 even when a show is paused keep track of the autoPlayInterval so that when unpaused, the clock starts where it left off*/
		var currentTime=returnCurrentTime();
		var spread=currentTime - lastItemTimeChange;
		autoPlayPauseCorrection=spread;
		evaluatePause();
	}
	else if ((paused=="yes")&&(action==1))
	{
		
		
		/*20050310 - added paused=no, can't unestand why it wasn't there...*/
		paused="no";
		pauseAction=0;
		if(document.getElementById('progressBarPause_'+ch+'_'+sh+'_'+getThisItem).style.display!="none")
		{
			document.getElementById('progressBarPause_'+ch+'_'+sh+'_'+getThisItem).style.display="none";
		}
		if(jsMasterItemsArray[getThisItem]=="swfItem")
		{/*if it is a swf item then load the source into flash*/
			var swfName='swf_'+ch+'_'+sh+'_'+getThisItem;
			resumeFlash(swfName);
		}
		/*20061024 adjust the autoPlayInterval to keep counting from where it was before the pause action*/
		var currentTime=returnCurrentTime();
		/* subtract the time elapsed before the pause from current time and this keeps autoPlayInterval accurate regardless of pausing*/
		var adjustItemTimeChange=currentTime-autoPlayPauseCorrection;
		lastItemTimeChange=adjustItemTimeChange;
		evaluatePause();
		
	}
	else if((paused=="no")&&(action!=1))
	{
		/*20050310 - added this if condition, somthing isn't right... 
		paused=="yes";
		setEventTime();
		evaluatePause();
		var swapButton=document.getElementById('pauseButton');
		swapImage(swapButton,'on');*/
		/*20050601 added this back in , trying to find an inconsistency*/
		evaluatePause();
		
		
	}
	else if((paused=="yes")&&(action!=1))
	{
		/*20050310 - added this if condition, somthing isn't right... 
		paused=="yes";
		
		evaluatePause();
		var swapButton=document.getElementById('pauseButton');
		swapImage(swapButton,'on');*/
		/*20050601 added this back in , trying to find an inconsistency*/
		evaluatePause();
		/* 20050602 removing setEventTime, events should only be set by clicks 
		setEventTime();*/
		
		
	}
 }
		 
function evaluatePause()
{
	/*20050601 Added the call to pauseAction=1*/
	setTimeout("setPause()",100);
}
function returnTime(plusTime)
{//add the load time to the autoplay Interval
	autoPlayInterval=autoPlayInterval+plusTime;	
}

