var highlightColor = "#c9cbff";
var selectedColor = "#ffff96";

var preloadedImage = new Image;
preloadedImage.src = "images/connect.gif";

function HighlightThumbNail(cellId)
{
	SetThumbNailBgColor(cellId, highlightColor);
}

function SetThumbNailBgColor(cellId, color)
{
	var cell = document.getElementById("thumbPic" + cellId);
	if(cell != null)
	{
		cell.bgColor = color;
	}
	var cell = document.getElementById("thumbDesc" + cellId);
	if(cell != null)
	{
		cell.bgColor = color;
	}
}

function UnHighlightThumbNail(cellId)
{
	var color = "white";

	var selId = document.getElementById("pictureViewerSelectedId");
	if(selId != null)
	{  
		if(selId.value == cellId)
		{
			color = selectedColor;
		}
	}
	

	var cell = document.getElementById("thumbPic" + cellId);
	if(cell != null)
	{
		cell.bgColor = color;
	}
	var cell = document.getElementById("thumbDesc" + cellId);
	if(cell != null)
	{
		cell.bgColor = color;
	}
}

var iCount = -1;
var iTotalCount;
var timer;
var timerRunning = false;
var slideShowInProgress = false;

function RunSlideShow(totalCount)
{
	if(timerRunning)
	{
		clearTimeout(timer); 
		timerRunning = false;
	}
	
	var button = document.getElementById("slideShowButton");
	if(button != null)
	{
		if(button.value == "Stop Slide Show")
		{
			button.value = "Run as Slide Show";
			slideShowInProgress = false;
		}
		else
		{
			iCount= -1;
			button.value = "Stop Slide Show";
			iTotalCount = totalCount;
			ShowPictureSlideShow();
		}
	}
	

	//alert(totalCount);
	
	return false;
}

function ShowPictureSlideShow()
{
	slideShowInProgress = true;
	
	iCount++;
	
	var counter = document.getElementById("picCounter" + iCount);
	var path = document.getElementById("picCounter" + iCount + "path");
	var desc = document.getElementById("picCounter" + iCount + "desc");
	if(counter != null && path != null && desc != null)
	{
		//alert(path.innerHTML + "  " + desc.innerHTML  + "  " + counter.innerHTML);
		ShowPicture(path.innerHTML, desc.innerHTML, counter.innerHTML);
	}
}


var picIdentifier = [];
var pictures = [];
var m_path;
var m_description;
var m_thumbNailId;

function ShowPicture(path, description, thumbNailId)
{	
	//alert("length: " + picIdentifier.length);
	
	//update status of picture viewer
	var span = document.getElementById("pictureViewerDesc");
	if(span != null)
	{
		if(span.innerHTML.indexOf("loading picture") == -1)
		{
			span.innerHTML = "<font color=navy>loading picture...please be patient</font> <img src='" + preloadedImage.src + "' align=absmiddle>";
		}
	}
	
	//check to see if desired pic has already been loaded
	var picId = -1;
	for(var i=0; i<picIdentifier.length; i++)
	{
		if(picIdentifier[i] == path)
		{
			picId = i;
		}
	}
	
	//load picture if needed
	if(picId == -1)
	{
		picId = picIdentifier.length;
		picIdentifier[picId] = path;
		pictures[picId] = new Image;
		pictures[picId].src = path;
	}

	//alert("picId: " + picId);
	
	//show the picture if it is fully loaded, otherwise wait .5 sec and try again
	if (pictures[picId] && (pictures[picId].complete || pictures[picId].complete==null)) 
	{
		if(span != null)
		{
			span.innerHTML = description;
		}
		
		var image = document.getElementById("pictureViewer");
		if(image != null)
		{
			image.filters[0].apply();
			image.src = path;
			image.filters[0].play();
			
			SetThumbNailBgColor(thumbNailId, selectedColor);
		
			var selId = document.getElementById("pictureViewerSelectedId");
			if(selId != null)
			{
				var oldId = selId.value; 
				selId.value = thumbNailId;
				UnHighlightThumbNail(oldId);
			}	
			
			if(slideShowInProgress)
			{
				if(iCount<iTotalCount)
				{
					timerRunning = true;
					timer = window.setTimeout("ShowPictureSlideShow()", 4000);
				}
				else
				{
					slideShowInProgress = false;
					
					var button = document.getElementById("slideShowButton");
					if(button != null)
					{
						button.value = "Run as Slide Show";
					}
				}
			}
		}
	}	
	else
	{
		m_path = path;
		m_description = description;
		m_thumbNailId = thumbNailId;
		
		setTimeout("ReCallShowPicture()", 500);
	}
}

function ReCallShowPicture()
{
	ShowPicture(m_path, m_description, m_thumbNailId);
}




/*

//set image paths
src = ["image1.gif", "image2.gif", "image3.gif", "image4.gif"]


//set duration for each image
duration = 4;

//Please do not edit below
ads=[]; 
ct=0;

function switchAd() 
{
	var n = (ct+1)%src.length;
	
	if (ads[n] && (ads[n].complete || ads[n].complete==null)) 
	{
		document["Ad_Image"].src = ads[ct=n].src;
	}
	
	ads[n=(ct+1)%src.length] = new Image;
	ads[n].src = src[n];
	
	setTimeout("switchAd()",duration*1000);
}
*/