function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// the change link colour functions do not
// work with NS 4, decide if we are NS 4
// nor do they work if NS on the Mac
is_netscape4 = false;
is_netscapeMac = false;
if(navigator.appName == "Netscape") {
	if(parseInt(navigator.appVersion) < 5.0) {
		is_netscape4 = true;
	}
	platform = navigator.platform.toLowerCase();
	if(platform.indexOf("mac") > -1) {
		is_netscapeMac = true;
	}	
}

// menu images values
path_to_arrow = "images/common/menu/arrow.gif";
path_to_dots = "images/common/menu/horizontal_dots.gif"
path_to_spacer = "images/common/spacer.gif"
link_on_colour = "#FF6600";
link_off_colour = "#000000";
link_dis_colour = "#999999";

ID = 0
LABEL = 1;
PARENT = 2;
LEVEL = 3;
LAYER = 4;
STATUS = 5;
menu_a = new Array();
var array_element = false;
var menu_a_on = Array();
path_to_root = "./"


/**************************************************
 activates menu:
 	highlights correct links, 
	turns on correct arrows, 
	adds correct dots
**************************************************/
function CE_activate_menu(id) {
	// from given id, get which links and
	// parent links should be on
	CE_get_parents_as_array(id);

	// setup the menu so correct links
	// are highlighted
	CE_links_setup();		
}

/**************************************************
 turn off all links, then turns on correct ones
 including adding arrows and under lines
**************************************************/
function CE_links_setup(id) {
	// disable all
	for(i_link=0; i_link<menu_a.length; i_link++) {
		CE_link_dis(menu_a[i_link][ID]);
		// hide arrow
		CE_menu_arrow_off(menu_a[i_link][ID]);
		// hide underline
		CE_menu_underline_off(menu_a[i_link][ID]);
		// hide layer
		CE_hide_layer(i_link)
	}
	
	// selectable links should be "off"
	for(i=0; i<menu_a.length; i++) {
		if( (CE_in_array(menu_a_on, menu_a[i][PARENT]))  || (!menu_a[i][PARENT])) {
			//alert("black: " + menu_a[i][ID]);
			CE_link_off(menu_a[i][ID]);
		}
	}
	
	// for current links
	for(i_link=0; i_link<menu_a_on.length; i_link++) {
		// hightlight
		CE_link_on(menu_a_on[i_link]);
		// display arrow
		CE_menu_arrow_on(menu_a_on[i_link]);
		// display underline
		CE_menu_underline_on(menu_a_on[i_link]);
		// display the layer that this 
		// menu item is on
		CE_show_layer_from_id(menu_a_on[i_link])
		// turn on menu, so no rollout occurs
		CE_set_status(menu_a_on[i_link], true);
	}
}


function CE_menu_over(id) {
	array_element = CE_get_menu_by_id(id);

	// menu turn arrow on
	CE_menu_arrow_on(id);
	
	// turn link on 
	CE_link_on(id);
	if(array_element > -1) { 
		window.status = menu_a[array_element][LABEL];
		// if this layer is not on
		if(!menu_a[array_element][STATUS]) {
			// hide layers on the same level and greater
			CE_hide_layers(menu_a[array_element][LEVEL]);
			// any layers to show?
			if(menu_a[array_element][LAYER]) {
				// now show layer
				CE_show_layer(array_element)
			}
		}
	}
	return true;
}
function CE_menu_out(id) {
	array_element = CE_get_menu_by_id(id);

	window.status = '';

	if(array_element > -1) { 	
		// if this layer is not on
		if(!menu_a[array_element][STATUS]) {
			CE_menu_arrow_off(id);
			CE_link_off(id);
		}
		// do we need to hide layers?
		if(menu_a[array_element][LAYER]) {
			// hide layer
			CE_hide_layer(array_element)
		}
		// now show layers that are on
		CE_show_layers();
	}
}



function CE_off_layers(level) {
	for(i=0; imenu_a.length; i++) {
		if( (menu_a[i][LAYER]) && (menu_a[i][LEVEL] >= level) ) {
			menu_a[i][STATUS] = false;
		}
	}
}


/**************************************************
 Utility functions
**************************************************/
function CE_get_menu_by_id(id) {
	for(i=0; i<menu_a.length; i++) {
		if(menu_a[i][ID] == id) {
			return i;
		}
	}
	return false;
}
function CE_get_parents_as_array(id) {
	if(id != 0) {
		// where in the array is this menu id
		array_element = CE_get_menu_by_id(id);
		menu_a_on.push(menu_a[array_element][ID]);
		if(menu_a[array_element][PARENT]) {
			CE_get_parents_as_array(menu_a[array_element][PARENT]);
		}
	}
}
function CE_in_array(a, v) {
	for(in_a=0; in_a<a.length; in_a++) {
		if(a[in_a] == v) { return true; }
	}
	return false;
}
function CE_set_status(id, status) {
	array_element = CE_get_menu_by_id(id);
	menu_a[array_element][STATUS] = status;
}

/**************************************************
 adds menu element to menu_a array
**************************************************/
function CE_m_add(id, label, parent, level, layer) {
	menu_a.push(Array(id, label, parent, level, layer, false));
}
// replacement array.push
// taken from http://www.webreference.com/dhtml/column32/4.html
if(!Array.prototype.push) {
    function array_push() {
        for(i=0;i<arguments.length;i++){
            this[this.length] = arguments[i];
        }
        return this.length;
    }
    Array.prototype.push = array_push;
}

/**************************************************
 shows or hides menu image elements:
 arrow , underline dots and vertical dots
**************************************************/
function CE_menu_arrow_on(id) {
	if(!is_netscape4 && id) {
		document[("ia"+id)].src = path_to_root+path_to_arrow;
	}
}
function CE_menu_arrow_off(id) {
	if(!is_netscape4 && id) {
		document[("ia"+id)].src = path_to_root+path_to_spacer;
	}
}
function CE_menu_underline_on(id) {
	if(!is_netscape4 && id) {
		document[("iu"+id)].src = path_to_root+path_to_dots;
	}
}
function CE_menu_underline_off(id) {
	if(!is_netscape4 && id) {
		document[("iu"+id)].src = path_to_root+path_to_spacer;
	}
}
/**************************************************
 highlights links
**************************************************/
function CE_link_on(id) {
	if(!is_netscape4 && !is_netscapeMac && id) {
		linkName = "m"+id;
		if(document.all) { o = document.all[linkName]; }
		else { o = document.getElementById(linkName); }
		o.style.color = link_on_colour;
	}
}
/**************************************************
 un-highlights links
**************************************************/
function CE_link_off(id) {
	if(!is_netscape4 && !is_netscapeMac && id) {
		linkName = "m"+id;
		if(document.all) { o = document.all[linkName]; }
		else { o = document.getElementById(linkName); }
		o.style.color = link_off_colour;
	}
}
/**************************************************
 gives links "disabled" colour
**************************************************/
function CE_link_dis(id) {
	if(!is_netscape4 && !is_netscapeMac && id) {
		linkName = "m"+id;
		if(document.all) { o = document.all[linkName]; }
		else { o = document.getElementById(linkName); }
		o.style.color = link_dis_colour;
	}
}
/**************************************************
 functions for showing and hiding 
 individual and all layers
**************************************************/
function CE_hide_layer(array_element) {
	if(menu_a[array_element][LAYER]) {
		MM_showHideLayers(menu_a[array_element][LAYER],'','hide');
	}
}
function CE_hide_layers(level) {
	for(i=0; i<menu_a.length; i++) {
		if(menu_a[i][LEVEL] >= level) { CE_hide_layer(i); }
	}
}

function CE_show_layer(array_element) {
	if(menu_a[array_element][LAYER]) {
		MM_showHideLayers(menu_a[array_element][LAYER],'','show');
	}
}
function CE_show_layer_from_id(id) {
	array_element = CE_get_menu_by_id(id);
	if(menu_a[array_element][LAYER]) {
		MM_showHideLayers(menu_a[array_element][LAYER],'','show');
	}
}
function CE_show_layers() {
	for(i=0; i<menu_a.length; i++) {
		if(menu_a[i][STATUS]) { CE_show_layer(i); }
	}
}

