var iTimer = null;
var oCurrentWrapperDiv = null;
var oCurrentCategoryDiv = null;
var bDoExpand = true;
var iWrapperHeight = 0;
function showCategories(iWrapperIdx, iCategoryIdx) {
	try {
		clearTimer();
		var oWrapperDiv = document.getElementById("WrapperLevel" + iWrapperIdx);
		var oCategoryDiv = document.getElementById("Category" + iCategoryIdx);
		var bApplyFilter = oWrapperDiv.style.display == "block" && oCategoryDiv != oCurrentCategoryDiv;

		if (oCurrentWrapperDiv != null && oCurrentWrapperDiv != oWrapperDiv) oCurrentWrapperDiv.style.display = "none";
		if (oCurrentCategoryDiv != null) oCurrentCategoryDiv.style.display = "none";
		oCurrentWrapperDiv = oWrapperDiv;
		oCurrentCategoryDiv = oCategoryDiv;

		if (bDoExpand) animateExpandLinks();

		if (bApplyFilter && oWrapperDiv.filters && oWrapperDiv.filters.length > 0) oWrapperDiv.filters[0].apply();
		if (oWrapperDiv.style.display != "block") oWrapperDiv.style.display = "block";
		oCategoryDiv.style.display = "block";
		if (bApplyFilter && oWrapperDiv.filters && oWrapperDiv.filters.length > 0) oWrapperDiv.filters[0].play();

//	alert(oWrapperDiv.id + " : " + oCategoryDiv.id);
	}
	catch (e) {
	}
}
function animateExpandLinks() {
	bDoExpand = false;
	iWrapperHeight = iWrapperHeight + 10;
	oCurrentWrapperDiv.style.height = iWrapperHeight + "px";
	if (iWrapperHeight < 120) {
		window.setTimeout("animateExpandLinks()", 5);
	}
}
function clearTimer() {
	if (iTimer != null) window.clearTimeout(iTimer);
}
function collapseLinks() {
	clearTimer();
	iTimer = window.setTimeout("animateCollapseLinks()", 2000);
}
function animateCollapseLinks() {
	iWrapperHeight = iWrapperHeight - 10;
	oCurrentWrapperDiv.style.height = iWrapperHeight + "px";
	if (iWrapperHeight > 0) {
		window.setTimeout("animateCollapseLinks()", 5);
	}
	else {
		oCurrentWrapperDiv.style.display = "none";
		oCurrentWrapperDiv = null;
	}
}

//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
// Initialise
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
var iMaxHeight = 0;
var oCurrentCollection = null;

//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
// To avoid being too jerky we must always expand the sub link menu
// so that it is always the same size, which means we need to work
// out which is the biggest in order to make sure every panel fits in
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
function initialiseSubPanels() {
	var oSubItemsContainer = document.getElementById("subItemsContainer");
	var oPanelCollection = oSubItemsContainer.getElementsByTagName("div");
	//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
	// Loop through the collection and find the biggest panel which
	// we'll use as our default size
	//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
	for (var ii=0; ii<oPanelCollection.length; ii++) {
		var oPanel = oPanelCollection[ii];

		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
		// Workaround for the fact that clientHeight will come back as
		// zero because the display is set to none
		//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
		oPanel.style.position = "absolute";
		oPanel.style.visibility = "hidden";
		oPanel.style.display = "block";
		oPanel.iHeight = oPanel.offsetHeight; // keep track of height for later user
		if (oPanel.offsetHeight > iMaxHeight) iMaxHeight = oPanel.offsetHeight;
		oPanel.style.position = "static";
		oPanel.style.visibility = "";
		oPanel.style.display = "none";
	}

	//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
	// Now adjust each so that is vertically aligned
	//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::://
	for (var ii=0; ii<oPanelCollection.length; ii++) {
		var oPanel = oPanelCollection[ii];
		if (oPanel.iHeight < iMaxHeight) {
			oPanel.style.paddingTop = ((iMaxHeight-oPanel.iHeight)/2) + "px";
		}
	}
	oSubItemsContainer.style.height = iMaxHeight + "px";
}

//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
// Show the links corresponding to the category that has been
// mouse overred
//#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#
function showChildLinks(sId) {
	if (iMaxHeight == 0) initialiseSubPanels();
	if (oCurrentCollection != null) oCurrentCollection.style.display = "none";
	var oCollection = document.getElementById(sId);
	if (oCollection != null) {
		oCollection.style.display = "block";
		oCurrentCollection = oCollection;
	}
}
