var utils = {

init : function(){
	var theBody = document.getElementsByTagName('body')[0];
	if((theBody.id != 'sweeps') && (theBody.id != 'downloads')){
		utils.highlightNav();
	}
	utils.startList();
	var theLinks = document.getElementsByTagName('a');
	for (var i=0; i<theLinks.length; i++){
			if(theLinks[i].className == 'popup'){
				utils.addEvent(theLinks[i], 'click', utils.newPopUp);
			}
	}
	
	var theNav = document.getElementById("cnav");
	var theAnchors = theNav.getElementsByTagName("a");
	for (var i=0; i<theAnchors.length; i++){
		utils.addEvent(theAnchors[i], 'focus', function(){this.hideFocus=true;});
		utils.addEvent(theAnchors[i], 'click', function(){setTimeout("utils.highlightNav()",50);});
	}
},

startList : function(){
	var theCnav = document.getElementById("cnav");
		var theLinks = theCnav.getElementsByTagName("a");
		var allNavChildNodes = theCnav.childNodes.length;
		for (var i=0; i < allNavChildNodes; i++){
			var node = theCnav.childNodes[i];
			if (node.nodeName=="LI"){ 			
				node.onmouseover=function() {this.className="over";}
				node.onmouseout=function(){this.className=this.className.replace("over", "");}
   			}
   		}
	for(var i=0; i<theLinks.length; i++){
		theLinks[i].onmouseup = function(){
			if((this.parentNode.parentNode.parentNode.parentNode.id == "global_nav2") || (this.parentNode.parentNode.parentNode.parentNode.id == "global_nav3")){
				this.parentNode.parentNode.parentNode.parentNode.className = "hide";
			}
		}	 
	} 
},

newPopUp : function (e){
	window.open(this.href,'name','height=650,width=545,scrollbars=yes'); 
	utils.stopDefault(e);
},

highlightNav : function(){
	var theBody = document.getElementsByTagName("body")[0];
	var theLocation = window.location.href;
	theLocationNumber = theLocation.lastIndexOf('#') + 2;
	theSelection = theLocation.substring(theLocationNumber).split("/");
	theSelection = theSelection[0];
	theBody.className = theSelection;
	theScenarioNumber = theSelection.lastIndexOf("a");
	theScenarios = theSelection.substring(theScenarioNumber);
	if(theScenarios == "ario"){theBody.id = "recharging_moments";}
	else if((theLocationNumber == "1") ||  (theSelection == "")){theBody.id = "home";}
	else{theBody.id = "products";}
},


addEvent : function(obj, type, func) {
    if (obj.addEventListener) {obj.addEventListener(type, func, false);}
    else if (obj.attachEvent) {
      obj["e" + type + func] = func;
      obj[type + func] = function() {obj["e" + type + func] (window.event);}
      obj.attachEvent("on" + type, obj[type + func]);
    }
    else {obj["on" + type] = func;}
	},
	
	stopDefault : function(e) {
     if (!e) {e = window.event;}
     if (!e.preventDefault) {
         e.preventDefault = function() { this.returnValue = false; }
     }
     e.preventDefault();
     return false;
  }
}

utils.addEvent(window, 'load', utils.init);