
/*   --------------------------- Navigation object(s) ----------------------- */	

function Navigation(base, subDir, bgColor, borderColor) {


	this.base = '';
	this.subDir = '';
	if (base != null) this.base = base;
	if (subDir != null) this.subDir = subDir;
	this.bgColor = '#002299';
	this.borderColor = '#A6BAD0';
	if (bgColor != null) this.bgColor = bgColor;
	if (borderColor != null) this.borderColor = borderColor;
	this.sections = new Array();
	this.left = 3;
	this.top = 133;
	this.timeoutId = 0;

	this.selectedSection = '';
	this.selectedItem = '';
	
	if (selectedSection != null) this.selectedSection = toId(selectedSection);
	if (selectedItem != null) this.selectedItem = toId(selectedItem);

	this.addSection = navigation_addSection;
	this.addItem = navigation_addItem;
	this.setSelected = navigation_setSelected;
	
	this.createHTML = navigation_createHTML;
	this.showMenu = navigation_showMenu;
	this.hideMenu = navigation_hideMenu;
	this.hideMenus = navigation_hideMenus;
	this.initHideMenu = navigation_initHideMenu;
	this.positionMenus = navigation_positionMenus;
	
}

function Section(name, url) {
	this.name = name;
	this.url = url;
	this.id = toId(name);
	this.items = new Array();
	this.positioned = false;
	this.visibility = false;
}

function Item(name, url) {
	this.name = name;
	this.url = url;
	this.id = toId(name);
	this.items = new Array();
}

function navigation_addSection(name, url) {
	this.sections[this.sections.length] = new Section(name, url);
}

function navigation_addItem(name, url) {
	var navSection = this.sections[this.sections.length-1];
	navSection.hasChildren = true;
	navSection.items[navSection.items.length] = new Item(name, url);
}


/*   --------------------------- methods ----------------------- */	

function navigation_positionMenus() {	
	// position menus
	for (i=0; i<this.sections.length; i++) {
		if (this.sections[i].items.length != 0) {
			offsetLeft = 47;
			offsetTop = 4;
			if (IE && MAC) {
				offsetTop += 6;
				offsetLeft += -5;
			}
			if (NN4 || NN6) offsetLeft += 3;
			if (NN6 && (navigator.userAgent.indexOf('6.0') == -1)) offsetTop += 135;
			menuLeft = getImageLeft(this.sections[i].id + 'Ref', 'nav') + offsetLeft;
			menuTop = getImageTop(this.sections[i].id + 'Ref', 'nav') + offsetTop;
			moveLayer('div' + i, menuLeft, menuTop);
			this.sections[i].positioned = true;
		}
	}
}

function navigation_setSelected(nr) {
	this.selectedSection = this.sections[nr].id;
	
	for (var i=0; i<this.sections.length; i++) {
		changeImage('bn' + i, this.base + '/media/' + 'dot_nav.gif', 'nav');
	}
	changeImage('bn' + nr, this.base + '/media/' + 'dot_nav_selected.gif', 'nav');
}

function navigation_showMenu(nr) {
	clearTimeout(this.timeoutId);
	if (this.sections[nr].positioned) {
		this.hideMenus();
		this.sections[nr].visibility = true;
		showLayer('div' + nr);
		
		if (NN4) {
			this.sections[nr].visibility = false;
			obj = this;
			this.timeoutId = setTimeout('obj.hideMenu(' + nr + ')', 2500);
		}
	} else {
		obj = this;
		this.timeoutId = setTimeout('obj.showMenu(' + nr + ')', 500);
	}
}
	
function navigation_initHideMenu(nr) {
	clearTimeout(this.timeoutId);
	if (this.sections[nr].positioned) {
		if (this.sections[nr].items.length != 0) {
			this.sections[nr].visibility = false;
			obj = this;
			this.timeoutId = setTimeout('obj.hideMenu(' + nr + ')', 500);
		}
	}
}

function navigation_hideMenu(nr) {
	clearTimeout(this.timeoutId);
	if (!this.sections[nr].visibility) {	
		if (this.sections[nr].items.length != 0) hideLayer('div' + nr);
	}
}

function navigation_hideMenus() {
	clearTimeout(this.timeoutId);
	for (var i=0; i<this.sections.length; i++) {
		if (this.sections[i].items.length != 0) {
				this.sections[i].visibility = false;
				this.hideMenu(i);
		}
	}
}

/*   --------------------------- HTML Output ----------------------- */	
		
function navigation_createHTML() {
	str = '';
		
	str += '<div id="nav" style="position: absolute; top:' + this.top + 'px; left: ' + this.left + 'px; width: 130px; height:200px; z-index: 99;">\n';
	
	// create navigation bar
	str += '<table border="0" cellpadding="2" cellspacing="0" width="126">\n\n';
	for (var i=0; i<this.sections.length; i++) {
		str += '<tr><td width="1"><img name="' + this.sections[i].id + 'Ref" id="' + this.sections[i].id + 'Ref" src="/media/nix.gif" width="1" height="1" alt="" border="0" class="positioner"></td>';

		str += '<td width="12" valign="top"><img id="bn' + i + '" name="bn' + i + '" src="' + this.base + 'media/';	
		(this.sections[i].id == this.selectedSection) ? str += 'dot_nav_selected.gif' : str += 'dot_nav.gif';
		str += '" width="9" height="13" alt="" border="0"></td>';
		
		var initHideCmd = '';
		if (IE || NN6) initHideCmd = 'initHideMenu(' + i + '); ';
		var showMenuCmd = '';
		if (this.sections[i].items.length != 0) showMenuCmd = 'showMenu(' + i + '); ';
		
		str += '<td width="113" valign="top" onMouseover="hideMenus();' + showMenuCmd + '" onMouseout="' + initHideCmd + '" style="cursor: hand;">';
		if (this.sections[i].url != null) {
			if (this.sections[i].url.indexOf('javascript') != -1) {
				str += '<a href="' + this.sections[i].url + '" class="nav" onMouseover="hideMenus();' + showMenuCmd + '" onMouseout="' + initHideCmd + '" onClick="setSelected(' + i + ')">';
			} else {
				str += '<a href="' + this.sections[i].url + '" class="nav" onMouseover="hideMenus();' + showMenuCmd + '" onMouseout="' + initHideCmd + '" onClick="setSelected(' + i + ')">';
			}
			str += this.sections[i].name + '</a></td>';
		} else {
			str += '<a href="#" class="nav" onMouseover="hideMenus();' + showMenuCmd + '" onMouseout="' + initHideCmd + '" style="cursor: default;" onClick="setSelected(' + i + ')">' + this.sections[i].name + '</a></td>';
		}
		str += '</tr>';
		str += '<tr><td colspan="3"><img src="/media/nix.gif" width="40" height="3" alt="" border="0"></td></tr>';
	}
	str += '</table>';
	str += '</div>\n\n';
	
	//create menus
	for (var i=0; i<this.sections.length; i++) {
		if (this.sections[i].items.length != 0) {
			str += '<div id="div' + i + '" style="position: absolute; top:0px; left: 0px; width: 140px; height:160px; visibility: hidden; z-index: 99;">\n';
			str += '<table border="0" cellpadding="1" cellspacing="0"><tr><td bgcolor="' + this.borderColor + '">';
			str += '<table border="0" cellpadding="8" cellspacing="0"><tr><td bgcolor="' + this.bgColor + '">';
			str += '<table border="0" width="136" cellpadding="0" cellspacing="0" bgcolor="' + this.bgColor + '" onMouseover="showMenu(' + i + ');" onMouseout="initHideMenu(' + i + ');">';
			
			padding = '';
			if ((IE || NN6) && (!IE4)) padding = ' padding: 0px;';
			
			for (var j=0; j<this.sections[i].items.length; j++) {
				if (this.sections[i].items[j].url.toLowerCase().indexOf('javascript') != -1) {
					var url = this.sections[i].items[j].url;
					var action = url.substring(url.toLowerCase().indexOf(':') + 1, url.length);
					str += '<tr>\n<td onMouseover="showMenu(' + i + ');" onClick="' + action + '" style="cursor: hand;' + padding + '">';
					str += '<a href="#" class="nav2" onMouseover="showMenu(' + i + ');" onClick="setSelected(' + i + '); return false;">' + this.sections[i].items[j].name + '</a></td></tr>\n';
				} else {
					str += '<tr>\n<td onMouseover="showMenu(' + i + ');" onClick="document.location.href=\'' + this.sections[i].items[j].url + '\'" style="cursor: hand;' + padding + '">';
					str += '<a href="'  + this.sections[i].items[j].url + '" class="nav2" onMouseover="showMenu(' + i + ');" onClick="setSelected(' + i + ')">' + this.sections[i].items[j].name + '</a></td></tr>\n';
				}


				if (j != this.sections[i].items.length - 1) str += '<tr><td><img src="/media/nix.gif" width="40" height="7" alt="" border="0"></td></tr>';
			}
			str += '</table></td></tr></table></td></tr></table>';
			str += '</div>\n\n';
		}
	}
	
	// alert(str);
	document.write(str);
}





/*   --------------------------- inpage functions ----------------------- */	


function createNav() {
	nav.createHTML();
}

function initNav() {
	obj = nav;
	setTimeout('obj.positionMenus()', 100);
}

function showMenu(nr) {
	nav.showMenu(nr);
}

function initHideMenu(nr) {
	nav.initHideMenu(nr);
}

function hideMenus() {
	nav.hideMenus();
}

function setSelected(nr) {
	nav.setSelected(nr);
}

/*   --------------------------- SubNavigation object(s) ----------------------- */	

function SubNavigation(base, subDir) {
	this.base = '';
	this.subDir = '';
	if (base != null) this.base = base;
	if (subDir != null) this.subDir = subDir;
	this.sections = new Array();
	this.left = 160;
	this.top = 118;
	this.timeoutId = 0;
	
	this.selectedSubItem = '';
	if (selectedSubItem != null) this.selectedItem = toId(selectedSubItem);

	this.addSection = subNavigation_addSection;
	this.createHTML = subNavigation_createHTML;
	this.createSpace = subNavigation_createSpace;
}

function SubSection(name, url) {
	this.name = name;
	this.url = url;
	this.id = toId(name);
}

function subNavigation_addSection(name, url) {
	this.sections[this.sections.length] = new SubSection(name, url);
}

/*   --------------------------- HTML Output ----------------------- */	
		
function subNavigation_createHTML() {
	if (this.sections.length != 0) {
		var str = '';
		
		str += '<div id="subnav" style="position: absolute; top:' + this.top + 'px; left: ' + this.left + 'px; width: 130px; height:200px; z-index: 98;">\n';
	
		// create navigation bar
		str += '<table border="0" cellpadding="0" cellspacing="0" width="590">';
		str += '<tr><td><img src="' + this.base + '/media/hr.gif" width="590" height="1" alt="" border="0"></td></tr>';
		str += '<tr><td><table border="0" cellpadding="0" cellspacing="0"><tr><td><img src="/media/nix.gif" width="2" height="22" alt="" border="0"></td>';
		for (var i=0; i<this.sections.length; i++) {
			str += '<td><a href="' + this.base + this.subDir + this.sections[i].url + '" class="subnav">' + this.sections[i].name + '</a></td>';
			str += '<td><img src="/media/nix.gif" width="30" height="12" alt="" border="0"></td>';
		}
		str += '</tr></table>';
		str += '</td></tr><tr><td><img src="' + this.base + '/media/hr.gif" width="590" height="1" alt="" border="0"></td></tr></table>';
		str += '</div>\n\n';
		
		// alert(str);
		document.write(str);
	}
}

function subNavigation_createSpace() {
	if (this.sections.length != 0) document.write('<img src="/media/nix.gif" width="2" height="36" border="0" alt="">');
}

/*   --------------------------- inpage functions ----------------------- */	

function createSubNav() {
	subnav.createHTML();
}

function createSubNavSpace() {
	subnav.createSpace();
}

/*   --------------------------- create variables ----------------------- */	

var nav = new Navigation();

var subnav = new SubNavigation();
