//////////////////////////////////////////////////////////////////
// EPIC Group PLC
//
// Project Name : Research mindedness
//
// File Description : Contains generic rollover code.
//
// Notes:
//
// Modification History :
// Johnc 21/10/03
// Created.
//
//////////////////////////////////////////////////////////////////

var preloadArray = new Array()

function init()
{
	preloadImages()
	testHighlightSection()
}

function init_case()
{
	preloadImages()
	testHighlightSection()
}

function preloadImages()
{
	for (var count=0; count < document.images.length; count++)
	{
		if (document.images[count].name.indexOf("button") != -1)
		{
			var currImage = document.images[count]
			var currPath = currImage.src.slice(0, currImage.src.lastIndexOf("_"))
			var currExtension = currImage.src.slice(currImage.src.lastIndexOf("."), currImage.src.length)
			preloadArray[preloadArray.length] = new Image()
			preloadArray[preloadArray.length-1].src = currPath + "_c" + currExtension
		}
	}
}

function swapImage(whatImage, whatState)
{

	var currImage = document.images[whatImage]
	var currPath = currImage.src.slice(0, currImage.src.lastIndexOf("_"))
	var currExtension = currImage.src.slice(currImage.src.lastIndexOf("."), currImage.src.length)

	currImage.src = currPath + "_" + whatState + currExtension
	//alert (currImage.src);
}

function testHighlightSection()
{


	var currFile = document.location.href.slice( (document.location.href.lastIndexOf("/") + 1), document.location.href.length)
	//alert (currFile);
	// Index pages are not in a section, as such they will never highlight a bullet. Files in section 00_other shouldn't
	// highlight either.
	//alert(currFile)
	if ((currFile.indexOf("index") == -1) && (document.location.href.indexOf("00_other") == -1))
	{
		var currFileSplit = currFile.split("_")


		// parseInt() all items in the array, if they aren't NaN, convert them back into
		// a string, then pad them with a leading 0 if needed.
		var count = 0;
		var itemToHighlight = "";

		var inCaseStudies = false;
		var doneFirstNumber = false;
		if (currFileSplit[count] == "case")
		{
			inCaseStudies = true;
			//alert("Known in case.")
		}

		while (count < currFileSplit.length)
		{
			//alert(currFileSplit[count])


			// Trim leading leading, if present.
			if (currFileSplit[count].charAt(0) == "0")
				currFileSplit[count] = currFileSplit[count].slice(1 , currFileSplit[count].length)


			currFileSplit[count] = parseInt(currFileSplit[count])

			if ((!isNaN(currFileSplit[count])) && ((!inCaseStudies) || (!doneFirstNumber && inCaseStudies)))
			{
				//alert ("Adding second item");

				currFileSplit[count] = currFileSplit[count].toString()

				if (currFileSplit[count].length == 1)
					currFileSplit[count] = "0" + currFileSplit[count]

				itemToHighlight += "_" + currFileSplit[count];
				doneFirstNumber = true;
			}
			count++
		}
		itemToHighlight = "nav" + itemToHighlight;

		//alert (itemToHighlight);
		highlightSection(itemToHighlight)
	}
	else
	{
		if ((currFile.indexOf("index") != -1) && (currFile != "index.htm"))
			highlightSection("nav_00")
	}
}

function highlightSection(whatHighlight)
{
	//alert ('highlight section');
	var currLI = document.getElementById(whatHighlight)

	// If its longer than 6 chars, then it should be set to an arrow, else a disc
	if (whatHighlight.length > 6)
		currLI.style.listStyleImage = "url(../../images/interface/bullet_h.gif)"
	else
		currLI.style.listStyleImage = "url(../../images/interface/bullet_h.gif)"

	// Set the first childNodes to have a blue background, this should normally be the link.
	currLI.childNodes[0].style.backgroundColor = "#04376C"
	currLI.childNodes[0].style.color = "#ffffff"
}

/*
// Diagnostic function for IE only
document.onmouseover = showTagInfo;

function showTagInfo()
{
	currObj = window.event.srcElement;
	window.status = "Tag = " + currObj.tagName + " Class = " + currObj.className
}
*/

function fnOpenModal(whatPage)
{
	var WhichDialog = '../dialogues/' + whatPage;
	//alert (WhichDialog);
	if (document.all)
	  NewWin = window.showModalDialog(WhichDialog,"Dialog Box Arguments # 1","dialogHeight: 170px; dialogWidth: 390px; dialogTop: 250px; dialogLeft: 250px; edge: Sunken; center: No; help: No; resizable: No; status: No;");
	else
		window.open(WhichDialog,null,"height=180,width=400,status=yes,toolbar=no,menubar=no,location=no");
}

function fnOpenModalWide(whatPage)
{
	var WhichDialog = '../dialogues/' + whatPage;
	if (document.all)
	  NewWin = window.showModalDialog(WhichDialog,"Dialog Box Arguments # 1","dialogHeight: 170px; dialogWidth: 720px; dialogTop: 250px; dialogLeft: 250px; edge: Sunken; center: No; help: No; resizable: No; status: No;");
	else
		window.open(WhichDialog,null,"height=180,width=720,status=yes,toolbar=no,menubar=no,location=no");
}



