/* Thumbnail bar animation */
var thumbnail_bar_start = 298;
var thumbnail_bar_end = 400;
var thumbnail_timer = null;

function ShowThumbnailBar()
{
	clearTimeout(thumbnail_timer);
	MoveThumbnailsUpOne();
}

function HideThumbnailBar()
{
	if(document.getElementById("RangeImageThumbnails") == null)
	{
		setTimeout("HideThumbnailBar()", 500);
		return;
	}
	clearTimeout(thumbnail_timer);
	thumbnail_timer = setTimeout("MoveThumbnailsDownOne()", 1000);
}

HideThumbnailBar();

function MoveThumbnailsDownOne()
{
	if(!document.getElementById("RangeImageThumbnails")) return;

	var styleTopString = document.getElementById("RangeImageThumbnails").style.top.length == 0 ? thumbnail_bar_start + "px" : document.getElementById("RangeImageThumbnails").style.top;
	var currentTop = parseInt(
		((/[0-9].*/.exec(styleTopString)))
	);

	currentTop = currentTop + 5;

	document.getElementById("RangeImageThumbnails").style.top = currentTop.toString() + "px";

	if(currentTop < thumbnail_bar_end)
	{
		thumbnail_timer = setTimeout("MoveThumbnailsDownOne()", 20);
	}
	else
	{
		document.getElementById("RangeImageThumbnails").style.top = thumbnail_bar_end + "px";
		clearTimeout(thumbnail_timer);
	}
}

function MoveThumbnailsUpOne()
{
	if(!document.getElementById("RangeImageThumbnails")) return;

	document.getElementById("RangeImageThumbnails").style.top = thumbnail_bar_start + "px";
	clearTimeout(thumbnail_timer);
	//Now hide after after a few seconds unless the mouse is moved over the image area
	thumbnail_timer = setTimeout("HideThumbnailBar()", 2000);
}

addMouseMoveMethod("imageThumbnailPosition()");

function SwitchImage(imgSrc, TextPanelToSwitch)
{
	for(var p=0; p<panels.length; p++)
	{
		document.getElementById(panels[p]).style.display = "none";
	}

	document.getElementById("RangeImageContainer0").innerHTML = "<img src=\"" + imgSrc + "\" />";

	if(TextPanelToSwitch.length == 0) return;

	//Check a text panel exists for this image
	if(document.getElementById(TextPanelToSwitch) != null)
	{
		document.getElementById(TextPanelToSwitch).style.display = "block";
	}
}

var ThumbX, ThumbY, ThumbW, ThumbH;

function imageThumbnailPosition()
{

	var ThisObj = document.getElementById("ImagePanel0");
	if(ThisObj == null) return;

	//Reset
	ThumbX = 0;
	ThumbY = 0;
	ThumbW = ThisObj.offsetWidth;
	ThumbH = ThisObj.offsetHeight;

	while(ThisObj != null){
		ThumbX += ThisObj.offsetLeft;
		ThumbY += ThisObj.offsetTop;
		ThisObj = ThisObj.offsetParent;
	}


	if(xMousePos >= ThumbX && (xMousePos <= ThumbX + ThumbW) && yMousePos >= ThumbY && yMousePos <= (ThumbY + ThumbH))
	{
		//Still over image panel. Keep showing
		ShowThumbnailBar();
	}
}
