var navOptions = ['about','services','solutions','platform','investor','partners'];
var CSSover = " over";
var CSSnoBdr = " noBdr";
var CSSselected = " selected";
var currPage = location.pathname;

var ieModel = false;
/*
var ie6Browser = false;
var ie7Browser = false;
*/

/* iframe */
var iwidth=0
var iheight=0
var ileft=0
var iFilter=0;

function addEvent(_target,_event,_function){
	if (_target.addEventListener)
		_target.addEventListener(_event, _function, false );
	else{
		_target.attachEvent('on'+_event, _function);
		ieModel = true;	
	}	
}
// firebug degradiation
if (! ("console" in window) || !("firebug" in console)) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group"
                 , "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    window.console = {};
    for (var i = 0, len = names.length; i <len; ++i) window.console[names[i]] = function() {};
}

// utility functions 
function endBubble(evt)
{
    if(evt.cancelBubble == false){ 
        evt.cancelBubble = true; 
        evt.returnValue = false;
        
     }
	 if (evt.stopPropagation) {
	    evt.stopPropagation(); 
	    evt.preventDefault();
    	
	 }
}
/**
 * This function allows the programmer to retrieve objects biased on the class name you 
 * want to retrieve. Similar to the GetElementByID and GetElementByTagName.
 * @member UtilNS
 * @param {object} oElm The object you want to search, could be a whole document or something more specific.
 * @param {string} strTagName The string containing the name of the tag name i.e. "a", "div", "span" what ever the class name is attached to.
 * If no tag is given it will search all elements.
 * @param {string} strClassName The string containing the class name you're searching for
 * @returns An array filled with the class names found in the search
 * @type Array
 * {@link  http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#more-256 getElementsByClassName} Utility Function
 */
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0, len=arrElements.length; i<len; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return arrReturnElements;
}

function overNavMenu(){
	var nodeBefore = null;
	var node=null;
	var nodeBefore=null;
	navRoot = document.getElementById("menu");
	var topLevel = currPage.substr(1, currPage.length);
	topLevel = (topLevel.indexOf("/") > 0) ? topLevel.substr(0, topLevel.indexOf("/")) : topLevel;
	//console.debug("top Level", topLevel);

	for (var i=0, len =navRoot.childNodes.length ; i<len; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI"){
			if(nodeBefore!=null && node.className.match("selected")!=null){
				nodeBefore.className="noBdr";
			}
			// set currtab
			//console.debug("found tab in page: %b %d %s" , ((currPage.indexOf(navOptions[i]) > -1) ? true : false), currPage.indexOf(navOptions[i]), currPage.slice(currPage.indexOf(navOptions[i]), currPage.indexOf(navOptions[i])+navOptions[i].length));
			var currTab = (topLevel.indexOf(navOptions[i]) > -1) ? true : false;
			if(currTab)
			{
				//console.debug("node class name ", node.className);
				node.className = (node.className.length > 2 ) ? node.className + " selected" : "selected";
				var nodeBefore=clearBeforeNavMenu(node,true);
				if(nodeBefore!=null){
					nodeBefore.className=nodeBefore.className.replace("noBdr","");
					nodeBefore.className+=" noBdr";
				}
				//console.debug("node class name update", node.className);
			}
			
			/* set overactions */
			node.onmouseover=function(){
				this.className+=" over";
				clearBeforeNavMenu(this,true);
			};
			node.onmouseout=function(){
				this.className=this.className.replace("over", "");
				clearBeforeNavMenu(this,false);
			};
			nodeBefore=node;
		}
	}
	if(nodeBefore!=null && nodeBefore.className.match("selected")==null){
		nodeBefore.className="noBdr";
	}
}

function clearBeforeNavMenu(_item,_isOver){
	var navRoot = _item.parentNode;
	var nodeBefore = null;
	var nodeLast=null;
	for(var i=0, len=navRoot.childNodes.length;i<len;i++ ){
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI"){
			if(node==_item){
				nodeBefore=nodeLast;
			}
			nodeLast=node;
		}
	}
	if(nodeBefore!=null && _item.className.match("selected")==null){
		if(_isOver==true){
			nodeBefore.className=nodeBefore.className.replace("noBdr","");
			nodeBefore.className+=" noBdr";
		}else{
			nodeBefore.className=nodeBefore.className.replace("noBdr","");
		}
	}
	return nodeBefore;
}


function setMenus()
{
		var lhn = getElementsByClassName(document, "div", "MenuLeftTier3");
		var banner = getElementsByClassName(document, "img", "BannerTitle");
		//var allianceStr = "alliances and partnerships";
		if(lhn && (lhn.length == 1))
		{
			var temp = lhn[0];
			var ulName = temp.getElementsByTagName("ul");
			
			if(ulName[0].id == "leftMenu")
			{
				var temp2 = ulName[0];
				var aTags = temp2.getElementsByTagName("a");
				var path = new String(location);
				path = path.toLowerCase();

				if(path.indexOf("#") == (path.length -1))
					path = path.substr(0, path.length-1);
					
				if(path.indexOf("?") > 0 ) {
					pathTemp = path.split("?");
					path = pathTemp[0];
				}
					
				//alert(path + " " + path.indexOf("partner") + " " + path.indexOf("corporate"));
				
				path2 = new String(location.search);
				path2 = path2.substr(1, path2.length);
				if(path2.indexOf("#") == (path2.length -1))
						path2 = path2.substr(0, path2.length-1);	
				
				var i=0;
				var foundNum = -1;
				
				for(i=0, len=aTags.length; i < len; i++)
				{
					var linkPath = new String(aTags[i].href);
					linkPath = linkPath.toLowerCase();
				//console.debug("%s %s %s %s %b", banner[0].alt, aTags[i].text, aTags[i].href, path,(banner[0].alt == aTags[i].text));						
				//alert(banner.length + " " + banner[0].alt + " " + aTags[i].innerHTML);
					if(path == linkPath)
					{
						foundNum = i;
						break;
					}
					else if((banner.length ==1) && (banner[0].alt == aTags[i].innerHTML) )
					{
						foundNum = i;
						break;
					}
					else
					{	// check search params
						
						linkPath = linkPath.substr(linkPath.indexOf("?")+1, linkPath.length);
						var foundIndex = linkPath.lastIndexOf("id=");
						linkPath = linkPath.substr(foundIndex, linkPath.length);
						if(foundIndex > 0 && (path2 == linkPath))
						{
							foundNum = i;
							break;
						}
						
					}
				}
				
				if(foundNum != -1)
				{
					var leaf = aTags[foundNum];
					while(leaf.parentNode.id != "leftMenu")
					{
						leaf = leaf.parentNode;
					}
					leaf.className += " SelectedMenu";	  
				}		
		}
	}
}

function closeIframe(){
	iwidth=0;
	iFilter=0;
	document.getElementById("internalPopup").style.display="none";
	document.getElementById("internalPopupIframe").src="about:blank";
}
function showIframe(url,width,height){
   if(navigator.appVersion.match("MSIE 6")) 
      resizeMasterShadow();
	var oldIFilter = 0;
	if (iwidth<100){
		iwidth=iwidth+10;
		setTimeout('showIframe()',1);
	}
	if(iFilter==0){
		var iframe=document.getElementById("internalPopupIframe");
		var divIframe=document.getElementById("internalPopupDiv");
		iframe.style.display="none";
		iframe.src=url;
		iframe.style.height=height+"px";
		divIframe.style.width=width+"px";
		iframe.style.display="block";
	}
	iFilter=iFilter+1;
	document.getElementById("internalPopup").style.display="block";
	document.getElementById("internalPopupIframe").style.width=iwidth+"%";

	//filter: alpha(opacity=60);opacity: .6;-moz-opacity:0.6;
	shadow=document.getElementById("internalPopupShadow");
	if(shadow.style.filter){
		if(navigator.appVersion.match("MSIE 6")) resizeMasterShadow();
		shadow.style.filter="alpha(opacity="+(iFilter*6)+")";
	}else if(shadow.style.opacity){
		shadow.style.opacity=((iFilter*6)/100);
	}else{
		try{
			if(shadow.style.match("-moz-opacity")!=null){
				shadow.style.replace("-moz-opacity="+oldFilter,"");
			}
			shadow.style+="-moz-opacity="+((iFilter*6)/100);
		}catch(ex){}
	}
	oldIFilter=iFilter;
}
function resizeMasterShadow(){
   try{
	document.getElementById("internalPopup").style.width=document.body.clientWidth+"px";
	document.getElementById("internalPopupShadow").style.height=document.body.clientHeight+"px";
	document.getElementById("internalPopup").style.position="absolute";
	document.getElementById("internalPopupShadow").style.position="absolute";
	}catch(ex){}
}
if(navigator.appVersion.match("MSIE 6")) addEvent(window,'resize',resizeMasterShadow);
/*******************End Contact Us Window Slide***********************/

