// JavaScript Document
//Build for Ritchie Capital, LLC
//by Thirdwave, LLC
//created by Tad Renstrom
//last update November 3, 2005

//preload images arrays
OnImgPreLoadArray = new Array("/common/images/template/common/rc_toplevel_on.gif","/common/images/template/common/finance_toplevel_on.gif","/common/images/template/common/rqs_toplevel_on.gif");

OffImgPreLoadArray = new Array("/common/images/template/common/rc_toplevel_off.gif","/common/images/template/common/finance_toplevel_off.gif","/common/images/template/common/rqs_toplevel_off.gif");

//make arrays for navigation 
navigationArray = new Array()
NavDatArray = new Array()
NavNumbArray= new Array()

//finding main nav items by classname
selectNavDivs=document.getElementsByTagName("div");
var tempalert='';
var skiponthis='';
nn=0;
for(ni=0;ni<selectNavDivs.length;ni++){
	//alert(selectNavDivs[ni].className)
	if(selectNavDivs[ni].className == "navitem"){
		splitid=selectNavDivs[ni].id.split("_");
		navigationArraynum=splitid[1];
		navigationArray[navigationArraynum]=selectNavDivs[ni].id;
		//alert(navigationArray[navigationArraynum])
		
		NavNumbArray[nn]=splitid[1]
		
		
		if(ni==(selectNavDivs.length)){
		tempalert+=navigationArray[navigationArraynum]
		}else{
			tempalert+=navigationArray[navigationArraynum]+", "
			}
			nn++
		}
		spitother=selectNavDivs[ni].className.split("_")
	if(spitother[0] == "onstateNav"){
		splitid=selectNavDivs[ni].id.split("_");
		navigationArraynum=splitid[1];
		skiponthis=navigationArraynum;
		
		}
	
	}

//calculating primary navigation links location on page and placement of subnav underneath it.
function lineupnav(){
	adjnavlength=navigationArray.length;
	tempAlertHold=''
	for (ie=0; ie<adjnavlength; ie++){
	if(ie!=skiponthis){
			var offsetTrail = document.getElementById(navigationArray[ie]);
			var offsetLeft=0;
			var offsetTop=0;
				while(offsetTrail) {
						offsetLeft += offsetTrail.offsetLeft;
						offsetTop += offsetTrail.offsetTop;
						offsetTrail= offsetTrail.offsetParent;
					}
							
					if(navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined"){
						offsetLeft += document.body.leftMargin;
						offsetTop +=document.body.topMargin;
					
			}
			
			
			//object array to set position of sub nav dropdowns  
			NavDatArray[ie]=new Object()
			NavDatArray[ie].top=document.getElementById(navigationArray[ie]).offsetHeight+offsetTop;
			NavDatArray[ie].left=offsetLeft+1;
			if(browser == "Safari"){
				NavDatArray[ie].left2=offsetLeft+4;}
			else{
				NavDatArray[ie].left2=offsetLeft+2;}
			if(os == "Mac"){
			NavDatArray[ie].topLevelRightMarg=offsetLeft+document.getElementById(navigationArray[ie]).offsetWidth-2;}
			else{
				NavDatArray[ie].topLevelRightMarg=offsetLeft+document.getElementById(navigationArray[ie]).offsetWidth-1;
			}
			NavDatArray[ie].subNavId="subnav_"+ie+"_shadow";
			NavDatArray[ie].subNavIdTrue="subnav_"+ie;
			NavDatArray[ie].NavClassName=document.getElementById(navigationArray[ie]).className;
			NavDatArray[ie].marLeft=NavDatArray[ie].left-15;
			NavDatArray[ie].marRight=NavDatArray[ie].left+document.getElementById(NavDatArray[ie].subNavId).offsetWidth+15;
			
			document.getElementById(NavDatArray[ie].subNavId).style.top=NavDatArray[ie].top+"px";
			document.getElementById(NavDatArray[ie].subNavId).style.left=NavDatArray[ie].left+"px";
			tempAlertHold+=NavDatArray[ie].subNavId+", ";
			//alert(document.getElementById(NavDatArray[ie].subNavId).offsetHeight);
			//height of drop down sub nav items.
			if(document.getElementById(NavDatArray[ie].subNavId).offsetHeight>151){
				document.getElementById(NavDatArray[ie].subNavIdTrue).style.height="266px";}
				else{
					document.getElementById(NavDatArray[ie].subNavIdTrue).style.height="133px";}
			   }
			   
	}
	//alert(tempAlertHold)
}

//run calculations of navigation links location function
// set on body onload now.
//setTimeout("lineupnav()",500);

//rollover functionality for now current category links, opens dropdown nav as well
function opensub(OpenMe,temptype){
	tempvarstuff="nav_"+OpenMe;
	
		
		tempObj=new Object();
		tempObj.op=OpenMe
		tempObj.tt=temptype
		tempObj.Nid=tempvarstuff
		
		//close (rollover state and dropdowns) any none current category nav items, as well as current rollover
		for (cnt=0; cnt<NavNumbArray.length; cnt++){
			if(cnt!=skiponthis ){
				Idbycnt="nav_"+NavNumbArray[cnt]
				switch(tempObj.tt){
					case 'advisors':
					
					document.getElementById(Idbycnt).style.backgroundColor="#AFB697";
					break;
					case 'finance':
					
					document.getElementById(Idbycnt).style.backgroundColor="#85A3A3";
					break;
					case 'holdings':
					
					document.getElementById(Idbycnt).style.backgroundColor="#97A7AF";
					break;
					}
				
				document.getElementById(NavDatArray[cnt].subNavId).style.visibility="hidden";
				
			
			}
		}
		//change rollover states for current nav item and subnav
		switch(temptype){
		case 'advisors':
		document.getElementById(tempvarstuff).style.backgroundColor="#D6DAB7";
		break;
		case 'finance':
		document.getElementById(tempvarstuff).style.backgroundColor="#9AC2C2";
		

		break;
		case 'holdings':
		document.getElementById(tempvarstuff).style.backgroundColor="#B6C4CB";
		break;
		}
		
	//testing subnav dropdown and filter out empty dropdowns
	testinnerHTML=document.getElementById(NavDatArray[OpenMe].subNavIdTrue).innerHTML;
	//spliting up and finding links for mozilla browsers
	testinginnerHTML=testinnerHTML.split("<a");
	if(browser == "Firefox"){
		//alert(testinginnerHTML.length)
		testoftest=testinginnerHTML.length;
		}
		
		else if(document.all){
			//test ie for blanks
			testoftest=testinginnerHTML;}
			else{
				//test mozilla and other browsers
				testoftest=testinginnerHTML.length;}
	
	
	
	if (document.all) {	//ie
	if(testoftest!=0){
	
	document.getElementById(NavDatArray[OpenMe].subNavId).style.visibility="visible";}
	 document.onmousemove=followmouse1
	
	}
	else if (document.layers){	//ns old school version 4-6
	//alert("else if");
	document.getElementById(NavDatArray[OpenMe].subNavId).style.visibility="visible";
	window.captureEvents(Event.MOUSEMOVE)
	window.onmousemove=followmouse2

	
	}
	else {//all other browser newer versions of netscape, mozilla, safari, opera etc.
		//alert(NavDatArray[OpenMe].subNavId+" "+testoftest);
		if(testoftest>1){document.getElementById(NavDatArray[OpenMe].subNavId).style.visibility="visible";}
		if(browser == "Safari"){
			if(testinginnerHTML!=0){
		document.getElementById(NavDatArray[OpenMe].subNavId).style.visibility="visible";}}
	window.captureEvents(Event.MOUSEMOVE)
	window.onmousemove=followmouse2
	
	}

	
	}
	
	//navigation close for dropdowns in ie
	function followmouse1(){
		
		
		
		 if (event.clientY > NavDatArray[NavNumbArray[0]].top){
		if ((event.clientX < NavDatArray[tempObj.op].left) || (event.clientX > NavDatArray[tempObj.op].marRight)) {
		  document.onmousemove=null;
		  document.getElementById(NavDatArray[tempObj.op].subNavId).style.visibility="hidden";
			 
		switch(tempObj.tt){
		case 'advisors':
		
		document.getElementById(tempObj.Nid).style.backgroundColor="#AFB697";
		break;
		case 'finance':
		
		document.getElementById(tempObj.Nid).style.backgroundColor="#85A3A3";
		break;
		case 'holdings':
		
		document.getElementById(tempObj.Nid).style.backgroundColor="#97A7AF";
		break;
		}
	
	
	
																						   
	}
	
	}
	
	if (event.clientY < NavDatArray[NavNumbArray[0]].top){
		 if ((event.clientX < NavDatArray[tempObj.op].left2) || (event.clientX > NavDatArray[tempObj.op].topLevelRightMarg)) {
		  document.onmousemove=null;
		  document.getElementById(NavDatArray[tempObj.op].subNavId).style.visibility="hidden";
			document.status=tempObj.tt;
		switch(tempObj.tt){
		case 'advisors':
		
		document.getElementById(tempObj.Nid).style.backgroundColor="#AFB697";
		break;
		case 'finance':
		
		document.getElementById(tempObj.Nid).style.backgroundColor="#85A3A3";
		break;
		case 'holdings':
		
		document.getElementById(tempObj.Nid).style.backgroundColor="#97A7AF";
		break;
		}
		
		 }
	}
	}
	
	//specialize close for mozilla browser
	function closeitMoz(){
	
	for (cnt=0; cnt<NavNumbArray.length; cnt++){
			
				//alert(cnt);
				Idbycnt="nav_"+NavNumbArray[cnt]
				switch(tempObj.tt){
					case 'advisors':
					
					document.getElementById(Idbycnt).style.backgroundColor="#AFB697";
					break;
					case 'finance':
					
					document.getElementById(Idbycnt).style.backgroundColor="#85A3A3";
					break;
					case 'holdings':
					
					document.getElementById(Idbycnt).style.backgroundColor="#97A7AF";
					break;
					}
				document.getElementById(NavDatArray[NavNumbArray[cnt]].subNavId).style.visibility="hidden";
				
			
			
		}
	}
	
	//navigation close for dropdowns in all other (mozilla)
	function followmouse2(e){

	 if (e.pageY <  NavDatArray[NavNumbArray[0]].top){
		
		 if ((e.pageX < (NavDatArray[tempObj.op].left2)) || (e.pageX > (NavDatArray[tempObj.op].topLevelRightMarg))) {
		//rolloverfunction(tempplace, temprollunder, "off");
		document.getElementById(NavDatArray[tempObj.op].subNavId).style.visibility="hidden";
		//window.onmousemove=null;
		closeitMoz();

		}}
	 
	 
	  if (e.pageY >  NavDatArray[NavNumbArray[0]].top){
		 if ((e.pageX < NavDatArray[tempObj.op].marLeft) || (e.pageX > NavDatArray[tempObj.op].marRight)) {
		//rolloverfunction(tempplace, temprollunder, "off");
		document.getElementById(NavDatArray[tempObj.op].subNavId).style.visibility="hidden";
		//window.onmousemove=null;

		closeitMoz();
		}}
		
		
		
		
		
}


//Array for preloading images of navigation
RoundUpOvrImg = new Array();
//preload images
function preload(){
	
	for(xy=0; xy<OnImgPreLoadArray.length;xy++){ 
	RoundUpOvrImg[xy] = new Object
	RoundUpOvrImg[xy].imgon=new Image
	RoundUpOvrImg[xy].imgon.src=OnImgPreLoadArray[xy]
	RoundUpOvrImg[xy].imgoff=new Image
	RoundUpOvrImg[xy].imgoff.src=OffImgPreLoadArray[xy]
	
	}
	}
	
preload();

//rollover for tip top nav items
function ChngOutImg(ItemID,State,numbing){
	switch(State){
		case 'on':
		//alert(RoundUpOvrImg[numbing].imgon.src+" "+RoundUpOvrImg[numbing].imgoff.src);
		try{
		document.getElementById(ItemID).src=RoundUpOvrImg[numbing].imgon.src;}
		catch(e){alert(e.message+" "+ItemID)}
		break;
		case 'off':
		//alert(RoundUpOvrImg[numbing].imgon.src+" "+RoundUpOvrImg[numbing].imgoff.src);
		document.getElementById(ItemID).src=RoundUpOvrImg[numbing].imgoff.src;
		break;
		
		}
	
	}
	
