/*   --------------------------- Main Navigation ----------------------- */	


var nav, selectedSection, selectedItem;
var menuTimeoutID = new Array();

function Navigation(base) {
	this.sections = new Array();
	this.base = base;
	this.selectedSection = '';
	if (selectedSection != null) this.selectedSection = toId(selectedSection);
	this.selectedItem = '';
	if (selectedItem != null) this.selectedItem = toId(selectedItem);
	this.timeoutId = 0;
}

Navigation.prototype.addSection = navigation_addSection;
Navigation.prototype.addItem = navigation_addItem;
Navigation.prototype.createHTML = navigation_createHTML;
Navigation.prototype.positionMenus = navigation_positionMenus;
Navigation.prototype.showMenu = navigation_showMenu;
Navigation.prototype.initHideMenu = navigation_initHideMenu;
Navigation.prototype.hideMenu = navigation_hideMenu;
Navigation.prototype.hideMenus = navigation_hideMenus;
Navigation.prototype.moveMenu = navigation_moveMenu;

function Section(name, url) {
	this.name = name;
	this.id = toId(name);
	this.url = url;
	this.visibility = false;
	this.speed = 10;
	this.width = 200;
	this.height = 0;
	this.maxHeight = 300;
	this.status = 'hidden';
	this.positioned = false;
	menuTimeoutID[menuTimeoutID.length] = 0;
	this.items = new Array();
}

function Item(name, url, isInactive) {
	this.name = name;
	this.isActive = true;
	if (isInactive) this.isActive = false;
	this.id = toId(name);
	this.url = url;
}

function navigation_addSection(name, url){
	this.sections[this.sections.length] = new Section(name, url);
}

function navigation_addItem(name, url, isInactive){
	var s = this.sections[this.sections.length-1];
	s.items[s.items.length] = new Item(name, url, isInactive);
}

/*   --------------------------- Menu Initialisation ----------------------- */	


function initNavigation() {
	obj = nav;
	setTimeout('obj.positionMenus()', 100);
}

function initHideMenu(menu) {
	nav.initHideMenu(menu);
}

function hideMenus(exception) {
	nav.hideMenus(exception);
}

function hideMenu(menu) {
	nav.hideMenu(menu);
}

function showMenu(menu) {
	nav.showMenu(menu);
}

function createNavigation() {
	nav.createHTML();
}

/*   --------------------------- Positioning ----------------------- */	

function navigation_positionMenus() {	
	// position menus
	for (i=0; i<this.sections.length; i++) {
		if (this.sections[i].items.length != 0) {
			var offsetLeft = -2;
			var offsetTop = 15;
			if (NN) offsetTop += 1;
			if (MAC && IE) offsetTop += 12;
			menuLeft = getImageLeft('ref_' + i, 'nav') + offsetLeft;
			menuTop = getImageTop('ref_' + i, 'nav') + offsetTop;
			moveLayer(this.sections[i].id, menuLeft, menuTop);
			this.sections[i].positioned = true;
		}
	}
}

/*   --------------------------- HTML Output ----------------------- */	
		
function navigation_createHTML() {
	var str = '';
	
	str += '<div id="nav" style="position: absolute; top: 36px; left: 160px; width: 540px; height:32px; z-index: 99;">\n';
	
	// create navigation bar
	str += '<table border="0" cellpadding="0" cellspacing="0">\n<tr>\n';
	for (i=0; i<this.sections.length; i++) {
			str += '<td width="1"><img name="ref_' + i + '" id="ref_' + i + '" src="/2004/media/nix.gif" width="1" height="1" alt="" border="0" class="ref"></td>';
			str += '<td align="left">';
			
			showMenuCmd = '';
			if (this.sections[i].items.length != 0) showMenuCmd = 'showMenu(' + i + '); ';
			
			if (this.sections[i].url != null) {
				str += '<a href="' + this.base + this.sections[i].url + '" class="nav" target="_top"';
			} else {
				str += '<a href="#" class="nav" style="cursor: default;" onClick="return false;"';
			}
			
			if (this.sections[i].id == this.selectedSection) {
				str += ' onMouseover="hideMenus(' + i + ');' + showMenuCmd + '" onMouseout="initHideMenu(' + i + ');">';
				str += '<img name="bn_' + i + '" id="bn_' + i + '" src="/2004/media/bn_' + this.sections[i].id + '_s.gif" border="0" height="15" alt=""></a></td>\n';
			} else {
				str += ' onMouseover="hideMenus(' + i + '); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');' + showMenuCmd + '" onMouseout="initHideMenu(' + i + '); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');">';
				str += '<img name="bn_' + i + '" id="bn_' + i + '" src="/2004/media/bn_' + this.sections[i].id + '_n.gif" border="0" height="15" alt=""></a></td>\n';
			}

			str += '<td><img src="/2004/media/nix.gif" width="15" height="2" alt="" border="0"></td>\n';
	}
	str += '</tr></table>';
	str += '</div>\n\n';
	
	//create menus
	for (i=0; i<this.sections.length; i++) {
		if (this.sections[i].items.length != 0) {
			str += '<div id="' + this.sections[i].id + '" style="position: absolute; top:0px; left: 0px; width: 142px; height:32px; visibility: hidden; z-index: 99;">\n';
			if (this.sections[i].id == this.selectedSection) {
				str += '<table width="142" border="0" cellpadding="0" cellspacing="0" onMouseover="showMenu(' + i + ');" onMouseout="initHideMenu(' + i + ');">\n';
			} else {
				str += '<table width="142" border="0" cellpadding="0" cellspacing="0" onMouseover="showMenu(' + i + '); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');" onMouseout="initHideMenu(' + i + '); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');">\n';
			}
			// str += '<tr><td height="3" bgcolor="#ff0000"><img src="/media/nix.gif" width="1" height="3" alt="" border="0"></td></tr>';
			for (j=0; j<this.sections[i].items.length; j++) {
				str += '<tr>';
				
				if (this.sections[i].id == this.selectedSection) {
					if (this.sections[i].items[j].id == this.selectedItem) {
						str += '<td id="td_' + i + '_' + j + '" onMouseover="showMenu(' + i + ');" onClick="top.location.href=\'' + this.base + this.sections[i].items[j].url + '\'" class="navSelected">\n';
						str += '<a id="a_' + i + '_' + j + '" href="' + this.base + this.sections[i].items[j].url + '" class="navSelected" target="_top" onMouseover="showMenu(' + i + ');">';
					} else {
						if (this.sections[i].items[j].isActive) {
							str += '<td id="td_' + i + '_' + j + '" onMouseover="showMenu(' + i + '); mouseOverItem(\'' + i + '_' + j + '\');" onMouseout="mouseOutItem(\'' + i + '_' + j + '\');" onClick="top.location.href=\'' + this.base + this.sections[i].items[j].url + '\'" class="nav">\n';
							str += '<a id="a_' + i + '_' + j + '" href="' + this.base + this.sections[i].items[j].url + '" class="nav" target="_top" onMouseover="showMenu(' + i + ');">';
						} else {
							str += '<td id="td_' + i + '_' + j + '" onMouseover="showMenu(' + i + ');" class="nav" style="cursor: default;" onClick="return false;">\n';
							str += '<a id="a_' + i + '_' + j + '" href="#" class="nav" style="cursor: default;" target="_top" onMouseover="showMenu(' + i + ');" onClick="return false;">';
						}
					}
				} else {
					if (this.sections[i].items[j].id == this.selectedItem) {
						str += '<td id="td_' + i + '_' + j + '" onMouseover="showMenu(' + i + ');" onClick="top.location.href=\'' + this.base + this.sections[i].items[j].url + '\'" class="navSelected">\n';
						str += '<a id="a_' + i + '_' + j + '" href="' + this.base + this.sections[i].items[j].url + '" class="navSelected" target="_top" onMouseover="showMenu(' + i + ');">';
					} else {
						if (this.sections[i].items[j].isActive) {
							str += '<td id="td_' + i + '_' + j + '" onMouseover="showMenu(' + i + '); mouseOverItem(\'' + i + '_' + j + '\'); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');" onMouseout="mouseOutItem(\'' + i + '_' + j + '\'); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');" onClick="top.location.href=\'' + this.base + this.sections[i].items[j].url + '\'" class="nav">\n';
							str += '<a id="a_' + i + '_' + j + '" href="' + this.base + this.sections[i].items[j].url + '" class="nav" target="_top" onMouseover="showMenu(' + i + ');">';
						} else {
							str += '<td id="td_' + i + '_' + j + '" onMouseover="showMenu(' + i + '); changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');" onMouseout="changeImage(\'bn_' + i + '\', \'/2004/media/bn_' + this.sections[i].id + '_n.gif\');" class="nav" style="cursor: default;" onClick="return false;">\n';
							str += '<a id="a_' + i + '_' + j + '" href="#" class="nav" style="cursor: default;" target="_top" onMouseover="showMenu(' + i + ');" onClick="return false;">';
						}
					}
				}
	
				str += this.sections[i].items[j].name + '</a>&nbsp;&nbsp;';
				str += '</td></tr>\n';
				if (j != this.sections[i].items.length - 1) {
					str += '<tr><td height="1" bgcolor="#000000"><img src="/media/nix.gif" width="1" height="1" alt="" border="0"></td></tr>';
				}
			}
			str += '</table>';
			str += '</div>\n\n';
		}
	}
	
	// alert(str);
	document.write(str);
}



/*   --------------------------- Menu Behavior ----------------------- */	

function navigation_showMenu(menu) {
	clearTimeout(this.timeoutId);
	if (this.sections[menu].positioned) {
		for (i=0; i<this.sections.length; i++) {
			if ((i!=menu)&&(this.sections[i].items.length!=0)) {
				this.sections[i].visibility = false;
				this.hideMenu(i);
			}
		}
		simpleClipLayer(this.sections[menu].id, this.sections[menu].width, this.sections[menu].height);
		this.sections[menu].visibility = true;
		showLayer(this.sections[menu].id);
		if (this.sections[menu].status != 'expanding') {
			this.sections[menu].status = 'expanding';
			obj = this;
			menuTimeoutID[menu] = setTimeout('obj.moveMenu(' + menu + ')', 2);
		}
	} else {
		obj = this;
		this.timeoutId = setTimeout('obj.showMenu(' + menu + ')', 500);
	}
}

function navigation_moveMenu(menu) {
	clearTimeout(menuTimeoutID[menu]);
	if (this.sections[menu].status == 'expanding') {
		this.sections[menu].height = this.sections[menu].height + this.sections[menu].speed;
		if (this.sections[menu].height >= this.sections[menu].maxHeight) {
			this.sections[menu].height = this.sections[menu].maxHeight;
			this.sections[menu].status = 'visible';
			simpleClipLayer(this.sections[menu].id, this.sections[menu].width, this.sections[menu].height);
		} else {
			this.sections[menu].height = this.sections[menu].height + this.sections[menu].speed;
			simpleClipLayer(this.sections[menu].id, this.sections[menu].width, this.sections[menu].height);
			obj = this;
			menuTimeoutID[menu] = setTimeout('obj.moveMenu(' + menu + ')', 2);
		}
	}
}

function navigation_initHideMenu(menu) {
	if (this.sections[menu].positioned) {
		if (this.sections[menu].items.length != 0) {
			this.sections[menu].visibility = false;
			obj = this;
			this.timeoutId = setTimeout('obj.hideMenu(' + menu + ')', 150);
		}
	}
}

function navigation_hideMenu(menu) {
	clearTimeout(this.timeoutId);
	this.sections[menu].status = 'hidden';
	this.sections[menu].height = 0;
	simpleClipLayer(this.sections[menu].id, this.sections[menu].width, 0);
	if (!this.sections[menu].visibility) {	
		if (this.sections[menu].items.length!=0) hideLayer(this.sections[menu].id);
	}
}

function navigation_hideMenus(exception) {
	for (var i=0; i<this.sections.length; i++) {
		if (this.sections[i].items.length!=0) {
			if (exception!=null) {
				if (exception != i) {
					this.sections[i].visibility = false;
					this.hideMenu(i);
				}
			} else {
				this.sections[i].visibility = false;
				this.hideMenu(i);
			}
		}
	}
}

function mouseOverItem(id) {
	element('td_' + id).style.backgroundColor = '#FF6666';
}

function mouseOutItem(id) {
	element('td_' + id).style.backgroundColor = '#FF0000';
}






