var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRefCat(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function getStyCat(id) {
	return (isNS4 ? getRefCat(id) : getRefCat(id).style);
} 

// Hide timeout.
var popTimerCat = 0;
// Array showing highlighted lmenu items.
var litNowCat = new Array();

function popOverCat(lmenuNum, itemNum) {
	clearTimeout(popTimerCat);
	hideAllButCat(lmenuNum);
	litNowCat = getTreeCat(lmenuNum, itemNum);
	changeColCat(litNowCat, true);
	targetNum = lmenu[lmenuNum][itemNum].target;
	if (targetNum > 0) {
	thisX = parseInt(lmenu[lmenuNum][0].ref.left) + parseInt(lmenu[lmenuNum][itemNum].ref.left);
	thisY = parseInt(lmenu[lmenuNum][0].ref.top) + parseInt(lmenu[lmenuNum][itemNum].ref.top);
	with (lmenu[targetNum][0].ref) {
	left = parseInt(thisX + lmenu[targetNum][0].x);
	top = parseInt(thisY + lmenu[targetNum][0].y);
	visibility = 'visible';
      }
   }
}
function popOutCat(lmenuNum, itemNum) {
	if ((lmenuNum == 0) && !lmenu[lmenuNum][itemNum].target)
		hideAllButCat(0)
	else
		popTimerCat = setTimeout('hideAllButCat(0)', 500);
	}
	
function getTreeCat(lmenuNum, itemNum) {

	// Array index is the lmenu number. The contents are null (if that lmenu is not a parent)
	// or the item number in that lmenu that is an ancestor (to light it up).
	itemArray = new Array(lmenu.length);

	while(1) {
		itemArray[lmenuNum] = itemNum;
		// If we've reached the top of the hierarchy, return.
		if (lmenuNum == 0) return itemArray;
		itemNum = lmenu[lmenuNum][0].parentItem;
		lmenuNum = lmenu[lmenuNum][0].parentlmenu;
	}
}

// Pass an array and a boolean to specify colour change, true = over colour.
function changeColCat(changeArray, isOver) {
	for (lmenuCount = 0; lmenuCount < changeArray.length; lmenuCount++) {
		if (changeArray[lmenuCount]) {
			newCol = isOver ? lmenu[lmenuCount][0].overCol : lmenu[lmenuCount][0].backCol;
			// Change the colours of the div/layer background.
			with (lmenu[lmenuCount][changeArray[lmenuCount]].ref) {
				if (isNS4) bgColor = newCol;
				else backgroundColor = newCol;
			}
		}
	}
}

function hideAllButCat(lmenuNum) {
	var keeplmenus = getTreeCat(lmenuNum, 1);
	for (count = 0; count < lmenu.length; count++)
	if (!keeplmenus[count])
	lmenu[count][0].ref.visibility = 'hidden';
	changeColCat(litNowCat, false);
}


function writeLeftMenu() {

	if (!isDOM && !isIE4 && !isNS4) return;

	for (currlmenu = 0; currlmenu < lmenu.length; currlmenu++) with (lmenu[currlmenu][0]) {
	// Variable for holding HTML for items and positions of next item.
	var str = '', itemX = 0, itemY = 0;

	// Also use properties of each item nested in the other with() for construction.
	for (currItem = 1; currItem < lmenu[currlmenu].length; currItem++) {
		
		if(currlmenu > 0){
			if (currItem == 1) borderClass = 'itemSublmenuBorderTop';
			else borderClass = 'itemSublmenuBorder';
		}
		
		with (lmenu[currlmenu][currItem]) {	
		
		var itemID = 'lmenu' + currlmenu + 'item' + currItem;

	var w = (isVert ? width : length);
	var h = (isVert ? length : width);
	var sAlign = (isVert ? "left" : "center");

	// Create a div or layer text string with appropriate styles/properties.
	// Thanks to Paul Maden (www.paulmaden.com) for helping debug this in IE4, apparently
	// the width must be a miniumum of 3 for it to work in that browser.
	if (isDOM || isIE4) {
		str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX + '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
		if (backCol) str += 'background: ' + backCol + '; ';
		str += '" ';
}

if (isNS4) {
	str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' +  w + '" height="' + h + '" visibility="inherit" ';
	if (backCol) str += 'bgcolor="' + backCol + '" ';
}

if (borderClass) str += 'class="' + borderClass + '" ';

// Add mouseover handlers and finish div/layer.
str += 'onMouseOver="popOverCat(' + currlmenu + ',' + currItem + ')" onMouseOut="popOutCat(' + currlmenu + ',' + currItem + ')">';



//cms25 menus - link or not link
if (href != '') { //clickable
	str += '<table width="' + (w - 8) + '" border="0" height="' + h + '" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td valign="middle" align="' + sAlign + '" height="' + (h - 7) + '">' + '<a class="' + textClass + '" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + unescape(text) + '</a></td>';
}
else { //not clickable
	str += '<table width="' + (w - 8) + '" border="0" height="' + h + '" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td valign="middle" align="' + sAlign + '" height="' + (h - 7) + '" class="' + textClass + '">' + unescape(text) + '</td>';
}

//end cms25 menus




// Add contents of item (default: table with link inside).
// In IE/NS6+, add padding if there's a border to emulate NS4's layer padding.
// If a target frame is specified, also add that to the <a> tag.


if (target > 0) {

	lmenu[target][0].parentlmenu = currlmenu;
	lmenu[target][0].parentItem = currItem;

	// Add a popOutCat indicator.
	if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
}

str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
if (isVert) itemY += length + spacing;
else itemX += length + spacing;

}
}

if (isDOM) {

	var newDiv = document.createElement('div');
	document.getElementsByTagName('body').item(0).appendChild(newDiv);
	newDiv.innerHTML = str;
	ref = newDiv.style;
	ref.position = 'absolute';
	ref.visibility = 'hidden';

}

if (isIE4) {
	document.body.insertAdjacentHTML('beforeEnd', '<div id="lmenu' + currlmenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
	ref = getStyCat('lmenu' + currlmenu + 'div');
}

// In NS4, create a reference to a new layer and write the items to it.
if (isNS4) {
	ref = new Layer(0);
	ref.document.write(str);
	ref.document.close();
}

for (currItem = 1; currItem < lmenu[currlmenu].length; currItem++) {
	itemName = 'lmenu' + currlmenu + 'item' + currItem;
	if (isDOM || isIE4) lmenu[currlmenu][currItem].ref = getStyCat(itemName);
	if (isNS4) lmenu[currlmenu][currItem].ref = ref.document[itemName];
	}
}

with(lmenu[0][0]) {
	ref.left = x;
	ref.top = y;
	ref.visibility = 'visible';
	   }
}



function moveRootCat()
{
 with(lmenu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);
}