/******************************************
Copyright: 	ZippySolutions Ltd., 2003
			If you'd like to use this code
			then please get in touch with
			us at info@zippysolutions.com
*******************************************/
var isNav, isIE
var coll = ""
var styleObj = ""

if(parseInt(navigator.appVersion)>=4)
{
	if(navigator.appName == "Netscape")
	{
		isNav = true
	} else
	{
		isIE = true
		coll = "all."
		styleObj = ".style"
	}
}

function getObject(obj)
{
	var theObj
	if(typeof obj == "string")
	{
		theObj = eval("document." + coll + obj + styleObj)
	} else
	{
		theObj = obj
	}
	return theObj
}

//Error handling code
window.onerror = myOnError
msgArray = new Array()
urlArray = new Array()
lnoArray = new Array()

msgArray[0] = "Starting Message"
urlArray[0] = "Starting URL"
lnoArray[0] = "Starting Line Number"

function myOnError(msg, url, lno) 
{   
	msgArray[msgArray.length] = msg   
	urlArray[urlArray.length] = url   
	lnoArray[lnoArray.length] = lno   
	return true
}

function showErrors()
{
	var errorMessage, i
	
	errorMessage = ""
	
	for(i = 0; i< msgArray.length; i++)
	{
		errorMessage =  errorMessage + "Error " + (i+1) + " : \n" + "Message = " + msgArray[i] + "\n" + "URL = " + urlArray[i] + "\n" + "Line = " + lnoArray[i] + "\n\n" + "************************\n"
	}
	alert(errorMessage)
}

//Positioning an object at a specific pixel cordinate
function shiftTo(obj, x, y)
{
	var theObj = getObject(obj)
	if(isNav)
	{
		theObj.moveTo(x,y)
	} else
	{
		theObj.pixelLeft = x
		theObj.pixelTop = y
	}
}

//Setting the visibility of an object to visible
function show(obj)
{
	var theObj = getObject(obj)
	theObj.visibility = "visible"
}

//Setting the visiblity of an object to hidden
function hide(obj)
{
	var theObj = getObject(obj)
	theObj.visibility = "hidden"
}

//Utility function returns rendered width of object content in pixels
function getObjWidth(obj)
{
	if(isNav)
	{
		return obj.clip.width
	} else
	{
		return obj.clientWidth
	}
}

function doNothing()
{
	return true;
}

function initialise(name, parentName, xcord, ycord, mwidth, outerBack, middleBack, innerBack, highlight, nLinks, lHeight, lBackground, wZIndex, visibility, alwaysOn, delay, siteRoot)
{
	this.menuName = name
	this.menuParentName = parentName
	this.menuX = xcord
	this.menuY = ycord
	this.menuWidth = mwidth
	this.outerBackground = outerBack
	this.middleBackground = middleBack
	this.innerBackground = innerBack
	this.highlightColour = highlight
	
	this.numLinks = nLinks
	this.linkHeight = lHeight
	this.linkBackground = lBackground
	
	this.zIndexOuter = wZIndex
	this.zIndexMiddle = (wZIndex+1)
	this.zIndexInner = (wZIndex+2)
	this.visibility = visibility
	this.alwaysOn = alwaysOn
	this.timeOut = delay
	this.siteRoot = siteRoot
	
	
	//Variables initialised at runtime
	this.menuHeight = (((this.linkHeight+1) * this.numLinks)+3)
	
	this.middleX = (this.menuX+1)
	this.middleY = (this.menuY+1)
	this.middleWidth = (this.menuWidth-2)
	this.middleHeight = (this.menuHeight-2)
	
	this.innerLayerX = (this.menuX+2)
	this.innerLayerY = (this.menuY+2)
	this.innerLayerWidth = (this.menuWidth - 3)
	this.innerLayerHeight = (this.menuHeight - 3)
	
	this.linkWidth = (this.menuWidth-4)
	this.linkX = (this.menuX+2)
	this.linkY = (this.menuY+2)
	
	this.outString = ""
	
	this.linksArray = new Array()		//The array that holds all the links information
	this.linksArrayIndex = 0
	
	this.litupLink = null
	this.shownChildMenu = null
}

function flip(varLayer, varImage, imageID)
{
	if(isNav)
	{
		var obj = eval("document." + varLayer + ".document." + imageID);
	}else
	{
		var obj = eval("document." + imageID);
	}
	
	if(typeof(obj) == "object")
	{
		obj.src = varImage
	}
}

function writeMenus()
{
	//Write the outer layer
	if(this.outerBackground != null)
	{
		this.outString = this.outString + "<div id=\""+(this.menuName)+"Outer\" 	style=\"position:absolute; width:"+(this.menuWidth)+"px; height:"+(this.menuHeight)+"px; z-index:"+(this.zIndexOuter)+"; left: "+(this.menuX)+"px; top: "+(this.menuY)+"px; background-color: "+(this.outerBackground)+"; layer-background-color: "+(this.outerBackground)+"; border: 1px none #000000; visibility: "+this.visibility+";\"></div>"
	}
	//Write the middle layer
	if(this.middleBackground != null)
	{
		this.outString = this.outString + "<div id=\""+this.menuName+"Middle\" 	style=\"position:absolute; width:"+this.middleWidth+"px; height:"+this.middleHeight+"px; z-index:"+this.zIndexMiddle+"; left: "+this.middleX+"; top: "+this.middleY+"; background-color: "+this.middleBackground+"; layer-background-color: "+this.middleBackground+"; border: 1px none #000000; visibility: "+this.visibility+";\"></div>"
	}
	//Write the inner layer
	if(this.innerBackground != null)
	{
		this.outString = this.outString + "<div id=\""+this.menuName+"Inner\" 		style=\"position:absolute; width:"+this.innerLayerWidth+"px; height:"+this.innerLayerHeight+"px; z-index:"+this.zIndexInner+"; left: "+this.innerLayerX+"; top: "+this.innerLayerY+"; background-color: "+this.innerBackground+"; layer-background-color: "+this.innerBackground+"; border: 1px none #000000; visibility:"+this.visibility+"\"></div>"
	}
	//Write all the links in a loop
	
	for(i=0; i<this.numLinks; i++)
	{
		this.zIndexInner = this.zIndexInner + 1
		this.outString = this.outString + "<div id=\""+this.menuName+"Link"+i+"\" style=\"position:absolute; width:"+this.linkWidth+"px; height:"+this.linkHeight+"px; z-index:"+this.zIndexInner+"; left: "+this.linkX+"px; top: "+this.linkY+"px; background-color: "+this.linkBackground+"; layer-background-color: "+this.linkBackground+"; border: 1px none #000000; clip: rect(0 "+this.linkWidth+" "+this.linkHeight+" 0); visibility: "+this.visibility+"\">"
		if(isNav)
		{
			this.outString = this.outString + "	<ilayer width=\""+this.linkWidth+"\">"
			this.outString = this.outString + "	  <layer width=\""+this.linkWidth+"\" left=\"-4\" top=\"-6\">"
		}
		this.outString = this.outString + "		  <table width=\""+this.linkWidth+"px\"  height=\""+this.linkHeight+"px\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
		this.outString = this.outString + "		    <tr>"
		this.outString = this.outString + "		      <a href=\""+this.linksArray[i][0]+"\"><td  onMouseover=\""+this.menuName+".menuMouseOver(this, "+i+")\" onMouseout=\""+this.menuName+".menuMouseOut(this, "+i+")\"></a>"
		if(isNav)
		{
			this.outString = this.outString + "		      	<ilayer width=\""+this.linkWidth+"\">"
			this.outString = this.outString + "		      		<layer width=\""+this.linkWidth+"\" height=\""+(this.linkHeight+2)+"\" onMouseover=\""+this.menuName+".menuMouseOver(this, "+i+")\" onMouseout=\""+this.menuName+".menuMouseOut(this, "+i+")\" class=\"navTextNetscape\">"	
		}
		if(this.linksArray[i][2] != null)
		{
			if(isNav)
			{
				this.outString = this.outString + "		      			<div align=\"center\" class=\"navText\">"+"<a href=\""+this.linksArray[i][0]+"\" class=\"navText\">"+this.linksArray[i][1]+"</a>"    +"</div>"
			}else
			{
				this.outString = this.outString + "		      			<div align=\"center\" class=\"navText\" style=\"position:relative; top:3; left:0\">"+"<a href=\""+this.linksArray[i][0]+"\" class=\"navText\">"+this.linksArray[i][1]+"</a></div>"
			}
			if(this.siteRoot == true)
			{
				this.outString = this.outString + "						<div style=\"position:relative; top:-8; left:0\" align=\"right\"><img src=\"_includes/arrow.gif\"></div>"
			}else
			{
				this.outString = this.outString + "						<div style=\"position:relative; top:-8; left:0\" align=\"right\"><img src=\"../_includes/arrow.gif\"></div>"
			}
		}else
		{
			this.outString = this.outString + "		      			<div align=\"center\" class=\"navText\">"+"<a href=\""+this.linksArray[i][0]+"\" class=\"navText\">"+this.linksArray[i][1]+"</a>"    +"</div>"
		}
		if(isNav)
		{
			this.outString = this.outString + "		      		</layer>"
			this.outString = this.outString + "		      	</ilayer>"
		}
		this.outString = this.outString + "		      </td>"
		this.outString = this.outString + "		    </tr>"
		this.outString = this.outString + "		  </table>"
		if(isNav)
		{
			this.outString = this.outString + "	  </layer>"
			this.outString = this.outString + "	</ilayer>"
		}
		this.outString = this.outString + "</div>"
		this.linkY = (this.linkY + (this.linkHeight+1))
	}
	return this.outString
}

function clearTimers(menuName)
{
	var menuObject, parentObject, tempString
	menuObject = eval(menuName)
	clearTimeout(menuObject.layerTimer)
	if(menuObject.menuParentName != null)
	{
		clearTimers(menuObject.menuParentName)
	}
}

function highlightParent(menuName)
{
	var parentObject = eval(menuName)
	if(parentObject.litupLink != null)
	{
		parentObject.litupLink.bgColor = this.highlightColour
	}
}

function menuMouseOver(obj, linkID)
{
	var parentObject, childObject
	
	if((this.litupLink != null) && (typeof(this.litupLink == "object")))
	{
		this.litupLink.bgColor = this.linkBackground
	}
	
	obj.bgColor = this.highlightColour
	this.litupLink = obj
	if(this.menuParentName != null)
	{
		clearTimers(this.menuParentName)
		this.highlightParent(this.menuParentName)
	}
	if(this.layerTimer != null)
	{
		clearTimeout(this.layerTimer)
		if(this.shownChildMenu != null)
		{
			childObject = eval(this.shownChildMenu)
			clearTimeout(childObject.layerTimer)
			hideMenu(this.shownChildMenu)
		}
	}
	if(this.linksArray[linkID][2] != null)
	{
		clearTimeout(this.layerTimer)
		this.show(this.linksArray[linkID][2])
		this.shownChildMenu = this.linksArray[linkID][2]
	}
}

function showMenu(menuName)
{
	var outerLayer, middleLayer, innerLayer, linkObject, menuObject
	menuObject = eval(menuName)
	if(menuObject.outerBackground != null)
	{
		outerLayer = getObject(menuName+"Outer")
		outerLayer.visibility = "visible"
	}
	if(menuObject.middleBackground != null)
	{
		middleLayer = getObject(menuName+"Middle")
		middleLayer.visibility = "visible"
	}
	if(menuObject.innerBackground != null)
	{
		innerLayer = getObject(menuName+"Inner")
		innerLayer.visibility = "visible"
	}
	for(i=0; i<menuObject.numLinks; i++)
	{
		linkObject = getObject(menuName+"Link"+i)
		linkObject.visibility = "visible"
	}
}

function hideParent(menuName)
{
	var menuObject, parentObject, tempString
	menuObject = eval(menuName)
	tempString = "hideMenu('"+menuObject.menuName+"')"
	menuObject.layerTimer = setTimeout(tempString, menuObject.timeOut/*500*/)
	tempString = ""
	if(menuObject.menuParentName != null)
	{
		hideParent(menuObject.menuParentName)
	}
}

function menuMouseOut(obj, linkID)
{
	var tempString = ""
	var parentObject
	obj.bgColor = this.linkBackground
	if(this.shownChildMenu != null)
	{
		tempString = "hideMenu('"+this.shownChildMenu+"')"
		var childObject = eval(this.shownChildMenu)
		childObject.layerTimer = setTimeout(tempString, childObject.timeOut/*500*/)
	}
	if(this.menuParentName != null)
	{
		hideParent(this.menuParentName)
	}
	tempString = "hideMenu('"+this.menuName+"')"
	this.layerTimer = setTimeout(tempString, this.timeOut/*500*/)
}

function hideInitialMenu(menuName)
{
	var tempString = ""
	var menuObject = eval(menuName)
	tempString = "hideMenu('"+menuName+"')"
	menuObject.layerTimer = setTimeout(tempString, menuObject.timeOut/*500*/)
}

function hideObject(menuName, menuItem, layerID)
{
	var backgroundColour = eval(menuName + "." + menuItem)
	if(backgroundColour != null)
	{
		var layerObject = getObject(menuName + layerID)
		layerObject.visibility = "hidden"
	}
}

function hideMenu(menuName)
{
	var outerLayer, middleLayer, innerLayer, linkObject, menuObject
	menuObject = eval(menuName)
	if(menuObject.alwaysOn != true)
	{
		hideObject(menuName, "outerBackground", "Outer")
		hideObject(menuName, "middleBackground", "Middle")
		hideObject(menuName, "innerBackground", "Inner")
		for(i=0; i<menuObject.numLinks; i++)
		{
			linkObject = getObject(menuName+"Link"+i)
			linkObject.visibility = "hidden"
		}
		if(menuObject.menuParentName != null)
		{
			var parentObject = eval(menuObject.menuParentName)
			menuObject.shownChildMenu = null
		}
		if((menuObject.litupLink != null) && (typeof(menuObject.litupLink) == "object"))
		{
			menuObject.litupLink.bgColor = menuObject.linkBackground
		}
	}else
	{
		if((menuObject.litupLink != null) && (typeof(menuObject.litupLink) == "object"))
		{
			menuObject.litupLink.bgColor = menuObject.linkBackground
		}
	}
}

function addLink(target, targetName, childMenu)
{
	this.linksArray[this.linksArrayIndex] = new Array(target, targetName, childMenu)
	this.linksArrayIndex = this.linksArrayIndex + 1
}



function hideAll(menuNames)
{
	var menuNameArray = menuNames.split(",")
	var tempString = ""
	var i = 0
	for(i=0; i<menuNameArray.length; i++)
	{
		tempString = menuNameArray[i]
		showMenu(tempString);
		hideMenu(tempString);
	}
}

function initialHide(menuNameArray)
{
	var tempString = "hideAll('"+menuNameArray+"')"
	setTimeout(tempString, 100)
}

function dynamicMenu()
{	
	this.menuName; this.menuParentName; this.menuX; this.menuY; this.menuWidth; this.outerBackground; this.middleBackground; this.innerBackground; this.highlightColour; this.numLinks; this.linkHeight; this.linkBackground; this.zIndexOuter; this.visibility; this.alwaysOn; this.timeOut; this.siteRoot; this.linksArray; this.linksArrayIndex; this.menuHeight; this.middleX; this.middleY; this.middleWidth; this.middleHeight; this.innerLayerX; this.innerLayerY; this.innerLayerWidth; this.innerLayerHeight; this.linkWidth; this.linkX; this.linkY; this.zIndexMiddle; this.zIndexInner; this.outString; this.layerTimer; this.shownChildMenu; this.litupLink; this.initialise = initialise; this.writeMenus = writeMenus; this.menuMouseOver = menuMouseOver; this.menuMouseOut = menuMouseOut; this.addLink = addLink; this.show = showMenu; this.hide = hideMenu; this.highlightParent = highlightParent
}

//******* IMPLEMENTATION OF TEXT SCROLL
	var objTicker, nTickerWidth, nTickerX, nTickerY, objWidth, scrollTimer, objContainer, difference
	var nStartPosition = 345
	var nSpeed = 10
	var nMoveBy = 1

	function scroll()
	{
		if(isNav)
		{
			objTicker = eval("document.nContainer.document.nContent");
			objWidth = eval("document.nContainer.document.nContent");
		} else
		{
			objTicker = eval("document.all.nContent.style");
			objWidth = eval("document.all.nContent");
		}
		nTickerWidth = getObjWidth(objWidth);
		nTickerX = nStartPosition
		nTickerY = 0
		move();
	}

	function move()
	{
		nTickerX = (nTickerX-nMoveBy);
		shiftTo(objTicker, nTickerX, nTickerY);
		difference = nTickerX
		if(difference < 0)
		{
			if(  (difference * -1) > nTickerWidth)
			{
				nTickerX = nStartPosition;
			}
		}
		scrollTimer = setTimeout("move()", nSpeed);
	}

	function stopTicker()
	{
		clearTimeout(scrollTimer);
	}

	function startTicker()
	{
		scrollTimer = setTimeout("move()", nSpeed);
	}
