
// menudef.js v0.5

// *********************************************************
// Object: ControlCollection
// Container of activated client Web Controls
//
function ControlCollection() { 
	this.length = 0; 
	this.add = add; 
	// this.remove = remove; 
	// this.contains = contains;
	return this 
} 


function add(object) { 
	this.length++; 
	this[this.length] = object 
	this[object.id] = object;
} 


function MenuNavigation(name){ }

MenuNavigation.prototype.newItem = 

function(name,parent,txt,lnk,targ,w,h,img1,img2,cl,cl2,align,rows,nolink,onclick,onmouseover,onmouseout) {
        clientCollection.add([onclick,txt,name,parent]);
}
        
var currLevel = 1;
var subLevel = 1;
var lastSubLevel = 1;
var hasSubnav = false;

function getBasename( url ) {
	if( url.contains("/") ) return url.split("/")[ url.split("/").length-1 ]; else return url;
}

MenuNavigation.prototype.construct = function() {

    for (i=1; i<=clientCollection.length; i++)
    {
	if (clientCollection[i][2] == ("top"+currLevel))  {
		var id = "";
		var urlClientCon = getBasename( clientCollection[i][0] );
		var urlLocation  = getBasename( document.location.href );
		
		if( (i == 1) && urlLocation.split("-").length < 10  ) { 
			id = "current"; 
		} else {
			if( urlClientCon.split("-").length > 10 ) {
				
				if( urlClientCon.split("-")[4] == urlLocation.split("-")[4] ) {
					if( urlClientCon.split("-")[12] == urlLocation.split("-")[12] ) {
						id = "current";
					}
				}
			}
		}

		div += '<li id="'+id+'"><div><a href="'+clientCollection[i][0]+'"><span>' + clientCollection[i][1] +"</span></a></div>";
		currLevel++;
	}
	
	if( clientCollection[i][2] == ("sub"+ subLevel) ) {
		if( subLevel == lastSubLevel) div += "<ul>";
		div += '<li><a href="'+clientCollection[i][0]+'"><span>' + clientCollection[i][1] + '</span></a></li>';
		subLevel++;
	}
	
	if ( clientCollection[i+1] != null && clientCollection[i+1][2] == ("top"+ currLevel)  ) {
	
		if( subLevel > lastSubLevel ) {
			div += "</ul>"; 
			lastSubLevel = subLevel ;
		}
		
		div += '</li>';
		
	}

    }

    
    div += "</ul>";
    
    document.getElementById('menuBar').innerHTML = div;
  
}



MenuNavigation.prototype.init = function() {

	var navRoot = document.getElementById("nav");	
	
	for (i=0;  i<navRoot.childNodes.length;  i++) 
	{
		var node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
			var urlClientCon = getBasename( node.childNodes[0].childNodes[0].href );
			var aSel = ( $E('a.nav2s') != null ) ? $E('a.nav2s') : $E('a.nav2a');
			if( aSel != null &&  aSel.href != null ) {
				var urlSearch = getBasename( aSel.href );
				if( urlClientCon.split("-")[12] == urlSearch.split("-")[12] ) {
					node.id = "current";
					break;
				}
			}

		}
	}

}



/**
* set events, w3c-compatible and ie
*/
function addEvent(obj, eventType, func, useCaption)
{
	if (!obj || !eventType || !func) {
		return false;
	} else if (obj.addEventListener) {
		obj.addEventListener(eventType, func, useCaption);
		return true;
	} else if (obj.attachEvent) {
		var retVal = obj.attachEvent("on"+eventType, func);
		return retVal;
	} else {
		return false;
	}
}





// Vars
var clientCollection = new ControlCollection(); 
var div = "<ul id=\"nav\">";
var objMenu = new MenuNavigation("objMenu") ;


startList = function() {

	objMenu.init();

	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
//window.onload=startList;
addEvent(window, "load", startList);





/**
	some common helper functions
*/

function getLayer( strID )
{
	if( document.all && !window.opera )
		return document.all[ strID ];
	else
		return document.getElementById( strID );
}

/**
 * special handling for ie 6, to place the bottom of the window
 */
if(document.all && !window.opera) {

	addEvent(window, "load", initFooterIE);
}

function initFooterIE() {
	window.onscroll = positionFooter;
	window.onresize = positionFooter;
	positionFooter();
}

function positionFooter() {
	try {
		getLayer("pageFooter").style.position = "absolute";
		getLayer("pageFooter").style.display = "block";
		getLayer("pageFooter").style.top = (document.body.clientHeight + document.body.scrollTop - getLayer("pageFooter").offsetHeight);
	} catch(e) {}
}



