
/* Expanding / contracting menu script
   Copyright 2004 Epic Multimedia
   www.epicmultimedia.com.au
*/

// Object constructors

function Section(id, name) {
	this.id = id;
	this.name = name;
	this.active = false;
	this.imgActive = new Image(imgWidth, imgHeight);
	this.imgActive.src = "images/nav_" + id + "_a.gif";
	this.imgNormal = new Image(imgWidth, imgHeight);
	this.imgNormal.src = "images/nav_" + id + "_n.gif";
	
	this.arrItems = new Array();
}

function addSection(id, name) {
	arrSections[arrSections.length] = arrSections[id] = new Section(id, name);
}

function Item(name, url, lines, ltarget) {
	this.name = name;
	this.url = url;
	this.height = lines * lineHeight + itemPadding;
	this.ltarget = ltarget;
}

function addItem(sectionId, name, url, lines, ltarget) {
	var arrItems = arrSections[sectionId].arrItems;
	arrItems[arrItems.length] = new Item(name, url, lines, ltarget);
}

/* Operational functions */

// (de)activate a given section
function activate(name) {
	var objSection = arrSections[name];
	// toggle this section
	objSection.active = !objSection.active;
	// deactivate any other sections
	if (objSection.active) {
		for (var i=0; i < arrSections.length; i++) {	
			if (arrSections[i] != objSection) arrSections[i].active = false;
		}
	}
	redraw();
}

// rollover an item
function over(itemId) {
	var objStyle = getStyleObject(itemId);
	objStyle.background = itemBgActive;
	objStyle.color = itemColorActive;
}

// rollout from an item
function out(itemId) {
	var objStyle = getStyleObject(itemId);
	objStyle.background = itemBgNormal;
	objStyle.color = itemColorNormal;
}

// go to the item's link
function clickItem(sectionId, n) {
	var objItem = arrSections[sectionId].arrItems[n];
	var templinktarget = objItem
	if (linkTarget == objItem.ltarget) {
      var objFrameRef = (linkTarget != "") ? eval("top." + linkTarget) : window;
      objFrameRef.document.location.href = objItem.url;
	} else {
    	if (objItem.ltarget == "leftFrame") {
	      var objFrameRef = ("leftFrame" != "") ? eval("top." + "leftFrame") : window;
          objFrameRef.document.location.href = objItem.url;
	    } else {
	      open(objItem.url)		
	    }
    } 
}

// redraw after activating or deactivating sections
function redraw() {
	var topCnt = menuTop;
	for (var i=0; i < arrSections.length; i++) {

		// redraw section images
		var objSection = arrSections[i];
		var objStyle = getStyleObject(objSection.id);
		if (objStyle != null) objStyle.top = topCnt;
		var objImage = (ns4) ? objStyle.document.images["img" + objSection.id] : document.images["img" + objSection.id];
		objImage.src = (objSection.active) ? objSection.imgActive.src : objSection.imgNormal.src;
		topCnt += imgHeight;

		// redraw items
		var arrItems = objSection.arrItems;
		for (var j=0; j < arrItems.length; j++) {
			var objItem = arrItems[j];
			var objStyle = getStyleObject(objSection.id + j);
			if (objStyle != null) {
				objStyle.visibility = (objSection.active ? "visible" : "hidden");
				objStyle.top = topCnt;
			}
			if (objSection.active) topCnt += objItem.height;
		}
		topCnt += 2;
	}
}

// draw the menu 
function drawMenu() {
	var topCnt = menuTop;
	for (var i=0; i < arrSections.length; i++) {
	
		// write the section html
		var objSection = arrSections[i];
		if (ns4) {
			document.write("<layer id='" + objSection.id + "' width=" + imgWidth + " height=" + imgHeight + " left=" + menuLeft + " top=" + topCnt + ">");
			document.write("<a href='javascript:activate(\"" + objSection.id + "\")'><img src='" + objSection.imgNormal.src + "' width=200 height=28 border=0 alt='" + objSection.name + "' name='img" + objSection.id + "'></a>");
			document.write("</layer>\n");
		} else {
			document.write("<div id='" + objSection.id + "' style='position:absolute;width:" + imgWidth + "px;height:" + imgHeight + "px;left:" + menuLeft + "px;top:" + topCnt + "px;'>");
			document.write("<a href='javascript:activate(\"" + objSection.id + "\")'><img src='" + objSection.imgNormal.src + "' width=200 height=28 border=0 alt='" + objSection.name + "' id='img" + objSection.id + "'></a>");
			document.write("</div>\n");
		}
		topCnt += imgHeight;

		// draw any sub items
		var arrItems = objSection.arrItems;
		for (var j=0; j < arrItems.length; j++) {
			var objItem = arrItems[j];
			if (ns4) {
				document.write("<layer id='" + (objSection.id + j) + "' width=" + itemWidth + " height=" + objItem.height + " left=" + itemLeft + " top=" + topCnt + " visibility='hidden'>");
				document.write("<table border=0 cellpadding=0 cellspacing=1 width='100%' height='100%'><tr><td class='menuitem'>");
				document.write("<a href='" + objItem.url + "' target='" + linktarget + "' onmouseover='over(\"" + (objSection.id + j) + "\")' onmouseout='out(\"" + (objSection.id + j) + "\")'>");
				document.write(objItem.name);

				document.write("</a>");
				document.write("</td></tr></table>");
				document.write("</layer>\n");
			} else {
				document.write("<div class='menuitem' id='" + (objSection.id + j) + "' style='position:absolute;visibility:hidden;left:" + itemLeft + "px;top:" + topCnt + "px;height:" + objItem.height + "px;' onmouseover='over(\"" + (objSection.id + j) + "\")' onmouseout='out(\"" + (objSection.id + j) + "\")' onclick='clickItem(\"" + objSection.id + "\", " + j + ")'>");
				document.write(objItem.name);
				document.write("</div>");
			}
		}
		topCnt += 2;
	}
}

/* cross-browser functionality */

// determine browser version
var ver=navigator.appVersion;
var dom=document.getElementById?1:0
var ie=(document.all)?1:0;
var ns6=(this.dom && parseInt(this.ver) >= 5)?1:0; 
var ns4=(document.layers && !this.dom)?1:0;

// return dom style object depending on browser version 
function getStyleObject(id) {
	if (ie) return(document.all[id].style);
	if (ns4) return(document.layers[id]);
	if (ns6) return(document.getElementById(id).style);
	return(null);
}

/* Netscape resize workaround */

if (ns4) onresize = function() { history.go(0) }

