//====================================================
//---------- START - Toolbar utilities ---------------
//====================================================
//Declare page global variables
var strGblServerRoot = "";
var strGblButtonImageRoot = "";
var arrGblPreLoadImageNames = new Array();
var arrGblPreLoadImageFolders = new Array();
var strGblToolbarOnIcon = "";
var intGblCueThumbOn = 1;
	strGblServerRoot = "http://" + document.location.hostname + "/";
//	strGblServerRoot = "http://localhost/PFDCues/";
	strGblButtonImageRoot = strGblServerRoot + "images/main_toolbar/";
	strGblCueImageRoot = strGblServerRoot + "images/cues/";
	strGblToolbarOnIcon = "";
//------------------------------------------
function DLS_SwapImage(strImageName, strNewImageState)
{
var strCurrentImageState = "";
var strCurrentImageName = "";
var strNewImagePath = "";
var intPosSlash = -1;
var arrPath;
var intPathSlashes;
var n;

//Get the Image object
	var objThisImage = MM_findObj(strImageName);

//Exit if we have not found a valid image
	if (!objThisImage)
		return;

//An array by splitting the path of the image by backslashes
	arrPath = objThisImage.src.split("/");

	intPathSlashes = arrPath.length

//The image root name will always be the last path item
	strCurrentImageName = arrPath[intPathSlashes-1];

//As long as we follow the convention the next path item will always be the image state
	strCurrentImageState = arrPath[intPathSlashes-2];

//Now build the root path from the rest of the path items
	for (n = 0; n < intPathSlashes - 2; n++) 
	{
		strNewImagePath = strNewImagePath + arrPath[n] + "/";
	}

//Now build the final path for the swapped image by adding back in the new image state
	strNewImagePath  = strNewImagePath + strNewImageState + "/" + strCurrentImageName;

//Finally swap the new image for the old
	objThisImage.src = strNewImagePath;
}
//------------------------------------------
function DLS_SwapCueImage(strImageName, strNewImageState)
{
//Initiate our variables
	var strCurrentImageState = "";
	var strCurrentImageSize = "";
	var strCurrentImageName = "";
	var intCurrentImageNumber = 0;
	var strNewImagePath = "";
	var strNewImageName = "";
	var bolCurrentImageupper = true;
	var intPosDelim = -1;

//Get the Image object
	var objThisImage = MM_findObj(strImageName);

//Exit if we have not found a valid image
	if (!objThisImage)
		return;

//Get the complete image name and path
	strCurrentImageState = objThisImage.src;
//Trim off the HTML path to the image excluding the folder that indicates the state
	strCurrentImageState = strCurrentImageState.slice(strGblCueImageRoot.length);
	strCurrentImageName = strCurrentImageState;
	intPosDelim = strCurrentImageState.search("/");

//Get the current image size
	strCurrentImageSize = strCurrentImageState.slice(0, intPosDelim);

//Get the current image state
	intPosDelim = strCurrentImageState.search("/");
	strCurrentImageState = strCurrentImageState.slice(intPosDelim+1);
	intPosDelim = strCurrentImageState.search("/");
	strCurrentImageState = strCurrentImageState.slice(0, intPosDelim);

//Get the root image name
	intPosDelim = strCurrentImageName.search("/");
	strCurrentImageName = strCurrentImageName.slice(intPosDelim+1);
	intPosDelim = strCurrentImageName.search("/");
	strCurrentImageName = strCurrentImageName.slice(intPosDelim+1);
	intCurrentImageNumber = strCurrentImageName;
	intPosDelim = strCurrentImageName.search("/");
	strCurrentImageName = strCurrentImageName.slice(0, intPosDelim);

//Get the image number (For multiple cue images)
	intPosDelim = intCurrentImageNumber.search("/");
	intCurrentImageNumber = intCurrentImageNumber.slice(intPosDelim+1);
	intPosDelim = intCurrentImageNumber.search(".jpg");
	intCurrentImageNumber = intCurrentImageNumber.slice(0, intPosDelim);

//Check if the root image name is the currently selected toolbar icon
	if (intCurrentImageNumber == intGblCueThumbOn)
	{
		strNewImageState = "on";
		strNewImagePath = strGblCueImageRoot + strCurrentImageSize + "/" + strNewImageState + "/" + strCurrentImageName + "/" + intCurrentImageNumber +".jpg";
		objThisImage.src = strNewImagePath;
		return;
	}

//Swap the thumbnail image
	strNewImagePath = strGblCueImageRoot + strCurrentImageSize + "/" + strNewImageState + "/" + strCurrentImageName + "/" + intCurrentImageNumber +".jpg";
	objThisImage.src = strNewImagePath;

//Swap the medium-size image if this is a MouseDown event
	if (strNewImageState=="down")
	{
		strNewImageName = "cue_medium_image";
		objThisImage = MM_findObj(strNewImageName);
		if (!objThisImage)
			return;	
		strNewImagePath = strGblCueImageRoot + "medium/" + strCurrentImageName + "/" + intCurrentImageNumber + ".jpg";
		objThisImage.src = strNewImagePath;

//As this is a MouseDown we need to reset the currently On image number to the normal Off image
		strNewImageName = "cue_" + strCurrentImageName + "_";
		if (intGblCueThumbOn<10)
			strNewImageName = strNewImageName + "0";
		 strNewImageName = strNewImageName + intGblCueThumbOn + "_small";
		objThisImage = MM_findObj(strNewImageName);
		if (!objThisImage)
			return;
		strNewImagePath = strGblCueImageRoot + strCurrentImageSize + "/off/" + strCurrentImageName + "/";
		if (intGblCueThumbOn<10)
			strNewImagePath = strNewImagePath + "0";
		strNewImagePath = strNewImagePath + intGblCueThumbOn +".jpg";
		objThisImage.src = strNewImagePath;

//As this is a MouseDown we need set  the current On image number
		intGblCueThumbOn = parseInt(intCurrentImageNumber, 10);
	}
}
//------------------------------------------
function DLS_SwapToolbarImage(strImageName, strNewImageState)
{
//Initiate our variables
	var strCurrentImageState = "";
	var strCurrentImageName = "";
	var strNewImagePath = "";
	var strNewImageName = "";
	var bolCurrentImageupper = true;
	var intPosDelim = -1;

//Get the Image object
	var objThisImage = MM_findObj(strImageName);

//Exit if we have not found a valid image
	if (!objThisImage)
		return;
//Get the complete image name and path
	strCurrentImageState = objThisImage.src;

//Trim off the HTML path to the image excluding the folder that indicates the state
	strCurrentImageState = strCurrentImageState.slice(strGblButtonImageRoot.length);

	strCurrentImageName = strCurrentImageState
	intPosDelim = strCurrentImageState.search("/");
	if(intPosDelim <-0)
		return;

//Get the current image state
	strCurrentImageState = strCurrentImageState.slice(0, intPosDelim);
	
//Get the root image name
	intPosDelim = strCurrentImageName.search("/");
	strCurrentImageName = strCurrentImageName.slice(intPosDelim+1);
	intPosDelim = strCurrentImageName.search("_");
	strCurrentImageName = strCurrentImageName.slice(intPosDelim+1);
	intPosDelim = strCurrentImageName.search("_");
	strCurrentImageName = strCurrentImageName.slice(0, intPosDelim);

//Check if the root image name is the currently selected toolbar icon
	if (strCurrentImageName == strGblToolbarOnIcon)
	{
		strNewImageState = "on";
	}

//Swap the upper root image
	strNewImageName = "upper_" + strCurrentImageName + "_1";
	objThisImage = MM_findObj(strNewImageName);
	if (!objThisImage)
		return;	
	strNewImagePath = strGblButtonImageRoot + strNewImageState + "/" + strNewImageName + ".jpg";
	objThisImage.src = strNewImagePath;

//Swap the lower root image
	strNewImageName = "lower_" + strCurrentImageName + "_1";
	objThisImage = MM_findObj(strNewImageName);
	if (!objThisImage)
		return;	
	strNewImagePath = strGblButtonImageRoot + strNewImageState + "/" + strNewImageName + ".jpg";
	objThisImage.src = strNewImagePath;

//Swap the upper toolbar's lower section. If we are switching off the button special case the single image used
	if (strNewImageState=="off")
	{
		strNewImageName = "upper_toolbar_2";
	}
	else
	{
		strNewImageName = "upper_" + strCurrentImageName + "_2";
	}

	objThisImage = MM_findObj("upper_toolbar_2");
	if (!objThisImage)
		return;

	if (strNewImageState=="off")
	{
		if (strGblToolbarOnIcon!="")
		{
			strNewImagePath = strGblButtonImageRoot + "on/upper_" + strGblToolbarOnIcon + "_2.jpg";
		}
		else
		{
			strNewImagePath = strGblButtonImageRoot + "off/upper_toolbar_2.jpg";
		}
	}
	else
	{
		strNewImagePath = strGblButtonImageRoot + strNewImageState + "/" + strNewImageName + ".jpg";
	}
	objThisImage.src = strNewImagePath;

//Swap the lower toolbar's upper section. If we are switching off the button special case the single image used
	if (strNewImageState=="off")
	{
		strNewImageName = "lower_toolbar_2";
	}
	else
	{
		strNewImageName = "lower_" + strCurrentImageName + "_2";
	}

	objThisImage = MM_findObj("lower_toolbar_2");
	if (!objThisImage)
		return;

	if (strNewImageState=="off")
	{
		if (strGblToolbarOnIcon!="")
		{
			strNewImagePath = strGblButtonImageRoot + "on/lower_" + strGblToolbarOnIcon + "_2.jpg";
		}
		else
		{
			strNewImagePath = strGblButtonImageRoot + "off/lower_toolbar_2.jpg";
		}
	}
	else
	{
		strNewImagePath = strGblButtonImageRoot + strNewImageState + "/" + strNewImageName + ".jpg";
	}
	objThisImage.src = strNewImagePath;
}
//------------------------------------------
function DLS_PopulatePreLoadArrays()
{
	arrGblPreLoadImageNames[0]="about.gif";
	arrGblPreLoadImageNames[1]="contact.gif";
	arrGblPreLoadImageNames[2]="home.gif";
	arrGblPreLoadImageNames[3]="sell.gif";
	arrGblPreLoadImageNames[4]="view.gif";
	arrGblPreLoadImageNames[5]="sort.gif";
	arrGblPreLoadImageNames[6]="show.gif";

	arrGblPreLoadImageFolders[0]="down";
	arrGblPreLoadImageFolders[1]="over";
	arrGblPreLoadImageFolders[2]="off";
	arrGblPreLoadImageFolders[3]="on";
}
//------------------------------------------
function DLS_PreloadImages()
{
var arrImages = new Array();
var n1, n2;
	DLS_PopulatePreLoadArrays();
	
	for(n1=0; n1 < arrGblPreLoadImageFolders.length; n1++)
	{
		for(n2=0; n2 < arrGblPreLoadImageNames.length; n2++)
		{
			arrImages[n1, n2] = new Image;
			arrImages[n1, n2].src = strGblButtonImageRoot + arrGblPreLoadImageFolders[n1] + "/" + arrGblPreLoadImageNames[n2];
		}
	}
}
//====================================================
//---------- END - Toolbar utilities -----------------
//====================================================
//-->
