/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*  The Left Navigation for the UPS SCS Internet Site   	    	 *
*																 *
*  Basic Structure:											   	 *
*																 *
*  This file (left_nav_global.js) is included at the  `     	 *
*  end of the "global.js" file.			        			   	 *
*  The actual list of all menu items in the 					 *
*  navigation are stored in an array for each 					 *
*  individual section. These arrays stored in an 				 *
*  included file called immediately before the menu 			 *
*  is printed to the page. For example:							 *
*																 *
*  <script language="JavaScript" 								 *
*  src="/javascripts/NameOfSection/nameOfSection_left_nav.js" 	 *
*  type="text/javascript"></script>								 *
*																 *
*  The actual printing is done immediately following this with   *
*  the code:													 *
*																 *
*  makeMenu(menuList);											 *
*																 *
*  makeMenu contains one argument,                               *
*  which is the array that was included as mentioned above.      *
*  Obviously the array (the src file)must be included before     *
*  the makeMenu function is called.								 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

//NOTE: For StyleSheet Updates:

/*All Navigation styles will be updated automatically with the exception
  of the NetScape inline styles in the "brownSubHeadBrowserFix" Function
  (at the bottom of the page)
*/


function makeMenu(menuList){

	//currentLocation will determine which page the user is currently on

	var currentLocation=document.location.pathname;

	//myMenuObj creates an object (Menu)
	//which will create the menu and then print it to screen

	var myMenuObj=new Menu(menuList, currentLocation);
}

//Menu object contains the entire navigation in one obj


function Menu(menuList, currentLocation){

	/*set ActiveID to the section index by default for example "/solutions/"
	  This will allow for someone who hits index.html or any page that
	  does not fit into the listed items to appear as the index page itself*/

	this.ActiveID=1;

	//set ActiveParentID to zero by default because index's parent is zero

	this.ActiveParentID=0;

	/*initiate an array to store each menu item within the navigation into one array
	  each as an object within that array*/

	this.myMenuItem=new Array();

	//Loop through every member of the menuList array and create an object for each
	/*menuList.length gives us the number of items in the menuList and loops the
	  correct number of times. As we are using this for every section, we needed
	  this value to be dynamic in nature*/


	for(var x=0;x<menuList.length;++x){
	   this.myMenuItem[x]=new MenuItem(menuList[x]);
	   //if the pathName for the link and the current
   	   //location path in the location bar match

		//ZH: 10/10/05:  Added lowercase funcitonality
	   if(currentLocation.toLowerCase()==this.myMenuItem[x].path.toLowerCase()){

	     //then this is the current Location and the left nav should reflect that
	     //get the ID of the menuItem and save it for later

	     this.ActiveID=this.myMenuItem[x].ID;

	     //get the parentID of the menuItem and save it for later

	     this.ActiveParentID=this.myMenuItem[x].parentID;

	     //set the menuItem to active, so that the item itself stores this value

	     this.myMenuItem[x].active=1;

	     //get the menuItem level that is active

	     activeLevel=this.myMenuItem[x].level;

		 //get the parent's parent (for level 4 use in order to display 2nd level menu)

		 if(this.ActiveParentID>1){

			activeGrandParent=this.myMenuItem[this.ActiveParentID-1].parentID;

		 }else{

			activeGrandParent=0;

		 }


	   }

	}



	//If no other pathName matched

	if(this.ActiveID==1){

	  //then assign the index (the first member of the object array)
	  //the attribute of active

	  this.myMenuItem[0].active=1;

	  activeGrandParent=0;

	  activeLevel=1;

	}



	//Now that we've created all of the menu items, let's print them to screen

	for(x=0;x<menuList.length;++x){



	   /*drawMenu is a function which simply decides which nav links to show and
	   which nav links not to show, and then prints them to the screen accordingly

	   There are 4 arguments sent to drawMenu

	   1. a String which is the returned result of the method: asString()
	   2. the MenuItem Object
	   3. the ActiveID
	   4. the ParentID of the Active Item

	   */

	   drawMenu(this.myMenuItem[x].asString(),this.myMenuItem[x], this.ActiveID ,this.ActiveParentID, activeLevel, activeGrandParent);

	}

}//End of Menu



//Object used for Each individual nav link

function MenuItem(menuString){

	/* Split takes all the values from the string and divides them into an array based on
	   the delimiter "|"
	*/

	var menuValues= menuString.split("|");

	//ID, Name, path, target, newWindow ,level, parentID

	this.ID=menuValues[0];   // Unique Identifier of the nav link
	this.name=menuValues[1]; // Name as seen on the page
	this.path=menuValues[2]; // Link to the page
	this.target=menuValues[3];// target, usually left empty unless link is outside url
	this.newWindow=menuValues[4]; //this identifies whether to put an image indicating that a new wind will be opened
	this.level=menuValues[5];   //level of hierarchy within nav, for now only 1 2 and 3 available
	this.parentID=menuValues[6]; //the ID of the hierarchy directly above
	this.active=0;		     //whether this is the current location or not, by default 0 (eg. false)
	this.asString=asString; //method for producing the actual link
}

//method for turning the info from the object into actual html

function asString(){

	var myString=""; //the variable to ultimately be returned

	//the only difference in image names between active and inactive links is the word blue or brown
	var color="blue"; //blue by default

	//create the beginning anchor tag
	var anchorBegin="<a href=\""+this.path+"\""+this.target+"\">";

	var anchorEnd="</a>";

	//if the new window icon will be used

	if(this.newWindow>0){

	  //generate the html to make it happen

	  var popupImage="<IMG ALT=\"\" BORDER=\"0\" HEIGHT=\"1\" SRC=\"/mwf/mwfapplications/images/1.gif\" WIDTH=\"3\"><IMG ALT=\"\" BORDER=\"0\" HEIGHT=\"10\" SRC=\"/mwf/mwfapplications/images/icn_popup_blue.gif\" WIDTH=\"9\">";

	  //attach the image to the end of the anchor tag so we don't need to concatenate everything at once

	  anchorEnd=popupImage+anchorEnd;

	}

	//If the link is active

	if(this.active!="0"){

	  color="brown"; //make the icon brown

	  anchorBegin=""; //get rid of the anchor Begin tag

	  anchorEnd=""; //get rid of the anchor End tag

	}


	/*do different stuff depending on which lewel of hierarchy the link is on
	  Each level has been determined in the style guide and based on Brian Cloward's
	  Consulting with MarComm. Before changing any part of this area of the script
	  please consult Brian and or MarComm*/

	switch(this.level){

	case "4":

		myString="<div class=\"ccsnmnavlv4\">&nbsp;"+anchorBegin+"<img alt=\"\" border=\"0\" height=\"8\" src=\"/mwf/mwfapplications/images/icn_chevron2_"+color+".gif\" width=\"8\">"+this.name+""+anchorEnd+"</div>\n";
		break;

	case "3":

		myString="<div class=\"ccsnmnavlv3\">&nbsp;"+anchorBegin+"<img alt=\"\" border=\"0\" height=\"8\" src=\"/mwf/mwfapplications/images/icn_chevron1_"+color+".gif\" width=\"8\">"+this.name+""+anchorEnd+"</div>\n";
		break;

	case "2":

		myString="<DIV class=\"ccsnmnavlv2\">&nbsp;"+anchorBegin+"<img alt=\"\" border=\"0\" height=\"8\" src=\"/mwf/mwfapplications/images/icn_arrow_"+color+"_nav.gif\" width=\"11\">"+this.name+""+anchorEnd+"</DIV>\n";
		break;

	case "1":

		//This part gets complicated with old netscape browsers, hence this fancy little function call
		myString=brownSubHeadBrowserFix(anchorBegin,this.name,anchorEnd);
		break;

	default:

		myString="";
		break;

	}

	return myString;

}

//Method to print the nav links to screen

function drawMenu(navString, navObj, activeID, parentID, activeLevel, activeGrandParent){

	switch(navObj.level){

		case "3":

			//If the link's parent is active

			//OR if the link has the same parent as the active link

			if((parseInt(navObj.parentID)==activeID)||(parseInt(navObj.parentID)==parentID)||((activeLevel==4)&&(parseInt(navObj.parentID)==activeGrandParent))){

			  //print it

			  document.writeln(navString);

			}

			break;

		case "4":

			if((parseInt(navObj.parentID)==activeID)||(parseInt(navObj.parentID)==parentID)){

			  //print it

			  document.writeln(navString);



			}

			break;

		case "2":

			document.writeln(navString);

			break;

		case "1":

			document.writeln(navString);

			break;

		default:

			break;

	}

}

function brownSubHeadBrowserFix(anchorBegin, name, anchorEnd){

//All if statements based on browser check for stylesheet in global.js

	  var linkString;

	  if(is_win){

	    if((is_nav) && (is_nav6up)){ //if the user is on NetScape 6 or above
	      //use normal stylesheet

	      linkString="<div class=\"ccsnmnavlv1\" style=\"padding-left:5px;\">"+anchorBegin+""+name+""+anchorEnd+"</div>\n<BR>\n";

	    }else if(is_nav){ //otherwise if

	    	    /*NetScape 4. whatever, use inline style, because old NetScape browsers

	    	      are finicky when it comes to stylesheets, and even more so when those

	    	      styles are being dictated by a JavaScript document.writeln*/



	    	    var brownStyle;



	    	    /*shorthand if statement if the anchor tag is empty (in other words

	    	      the link is active), color should be brown (663300), else color should

	    	      be blue (3366cc)*/

	    	    anchorBegin==""?brownStyle="color: #663300;": brownStyle="color: #3366CC;";



	            linkString="<div class=\"ccsnmnavlv1\" style=\"padding-left:5px;\">"+anchorBegin+"<font style=\"font-size: 9pt; font-weight: bold; "+brownStyle+" \">"+name+"</font>"+anchorEnd+"</div>\n<BR>\n";



	          }else{

	            //use normal stylesheet

	            linkString="<div class=\"ccsnmnavlv1\" style=\"padding-left:5px;\">"+anchorBegin+""+name+""+anchorEnd+"</div>\n<BR>\n";

		  }

	    }else if(((is_mac) && (is_nav)) && (!is_nav6up)){



	    	    //Same Netscape problem as above



	    	    anchorBegin==""?brownStyle="color: #663300;": brownStyle="color: #3366CC;";



	            linkString="<div class=\"ccsnmnavlv1\" style=\"padding-left:5px;\">"+anchorBegin+"<font style=\"font-size: 9pt; font-weight: bold; "+brownStyle+" \">"+name+"</font>"+anchorEnd+"</div>\n<BR>\n";



	    }else{



	      linkString="<div class=\"ccsnmnavlv1\" style=\"padding-left:5px;\">"+anchorBegin+""+name+""+anchorEnd+"</div>\n<BR>\n";



	    }

  	  return linkString;

}