//These 9 variables point to to the path of the graphics needed for the navigation script.
//	Therefore, you have to change the path in only one location.
var navImagesDir="http://www.ou.edu/cas/psychology/images/navigation/";
var activeconnectPath=navImagesDir+"activeconnect.gif"
var activelinkLPath=navImagesDir+"activelinkL.gif";
var activelinkTPath=navImagesDir+"activelinkT.gif";
var blankPath=navImagesDir+"blank.gif";
var branchpicPath=navImagesDir+"branchpic.gif";
var nonactivebranchPath=navImagesDir+"nonactivebranch.gif";
var psyPath=navImagesDir+"psy.gif";
//var ouPath=navImagesDir+"ou.gif";//Commented 1/24/2005
//var psy_titlePath=navImagesDir+"psy_titlePath.gif";//Commented 1/24/2005

function navigation(openbranch,highlightlink,rootdistance) {
// openbranch = number of branch that is opened (from 0)
// highlightlink = number of page in branch from which script is called
// rootdistance = distance from root directory, -1 = absolute adresses
var branchheight = 20;
var linkheight = branchheight - 5;

var branch = new Array(
	"The Department", 
	"Graduate Program", 
	"Undergraduate", 
	"Facilities",
	"People", 
	"Resources",
	"Courses",
	"Research",
	"Centers",
	"Department Access",
	"Search");

var branchlink = new Array(
	"/index.htm",
	"/grad/index.htm", 
	"/undergrad/index.htm",
	"/facilities/index.htm", 
	"/people/faculty.htm",
	"/resources/links.htm",
	"/resources/psychologycourses.htm",
	"/research/index.htm",
	"/centers/centers.html",
	"/restricted/RoomSchedule.htm",
	"/search.htm");

// The Department
var b0 = new Array(
	"Current Events", 
	"Welcome",
	"Department Overview",
	"Department Description",
	"Surrounding Area",
	"Contact Information");
var b0link = new Array(
	"/index.htm",
	"/home/message.htm",
	"/home/",
	"/home/description.htm",
	"/home/surrounding.htm",
	"/home/contact.htm");

// Graduate
var b1 = new Array(
	"Overview", 
	"Areas of Specialization",
	"Area",
	"Financial Support",
	"Admission",
	"MS/MA Requirements",
	"Phd Requirements",
	"Application Information",
	"Gettys Award",
	"PGSA");
var b1link = new Array (
	"/grad/index.htm", 
	"/grad/areas.htm",
	"",
	"/grad/fund.htm",
	"/grad/admissionrequirement.htm",
	"/grad/mastersrequirement.htm",
	"/grad/phdrequirement.htm",
	"/grad/application.htm",
	"/grad/award.htm",
	"/grad/pgsa.htm");

//Undergraduate
var b2 = new Array(
	"Overview", 
	"General Information",
	"Academic Advising",
	"Opportunities",
	"Resources",
	"Psychology Club",
	"FAQ");
var b2link = new Array(
	"/undergrad/index.htm",
	"/undergrad/generalinfo.htm",
	"/undergrad/academicadvising.htm",
	"/undergrad/opportunities.htm",
	"/undergrad/resources.htm",
	"/undergrad/club.htm",
	"/undergrad/ugfaq.htm");

//Facilties
var b3 = new Array(
	"Overview", 
	"Participation",
	"Animal Cognition",
	"Human Cognition",
	"Social Psychology",
	"I / O",
	"Personality");
var b3link = new Array(
	"/facilities/index.htm", 
	"/facilities/pool.htm",
	"/facilities/animalcognitionlab.htm",
	"/facilities/humancognition.htm",
	"/facilities/socialpsychology.htm",
	"/facilities/industrialorganizational.htm",
	"/facilities/personality.htm");

//people
var b4 = new Array (
	"Faculty", 
	"Graduate Students", 
	"Administration");
var b4link = new Array(
	"/people/faculty.htm", 
	"/people/gradstudents.htm", 
	"/people/staff.htm");

// resources
var b5 = new Array (
	"Links",
	"Lunch Bunch");
var b5link = new Array (			
	"/resources/links.htm",
	"/resources/lunchbunchschedule.htm");

// courses
var b6 = new Array (
	"Descriptions");
var b6link = new Array (
	"/resources/psychologycourses.htm");
//Research
var b7 = new Array(
	"Overview",			   
	"Animal Behavior",
	"Cognitive",
	"Developmental",
	"I / O",
	"Quantitative",
	"Social/Personality");
var b7link=new Array(
	"/research/index.htm",
	"/research/animalbehavior.htm",
	"/research/cognitive.htm",
	"/research/developmental.htm",
	"/research/industrialorganizational.htm",
	"/research/quantitative.htm",
	"/research/socialpersonality.htm");

//Centers
var b8 = new Array (
	"Centers");
var b8link = new Array (
	"/centers/centers.html");

// Department Access
var b9	= new Array (
	"Room Scheduling",
	"Files");
var b9link = new Array (
	"/restricted/RoomSchedule.htm",
	"/restricted/Files.htm");				   

// Search
var b10 = new Array (
	"Site Map",
	"Site",
	"Result");
var b10link = new Array (
	"/sitemap.htm",
	"/search.htm",
	"");



var linktext = new Array();
linktext[0] = b0;
linktext[1] = b1;
linktext[2] = b2;
linktext[3] = b3;
linktext[4] = b4;
linktext[5] = b5;
linktext[6] = b6;
linktext[7] = b7;
linktext[8] = b8;
linktext[9] = b9;
linktext[10] = b10;

var links = new Array();
links[0] = b0link;
links[1] = b1link;
links[2] = b2link;
links[3] = b3link;
links[4] = b4link;
links[5] = b5link;
links[6] = b6link;
links[7] = b7link;
links[8] = b8link;
links[9] = b9link;
links[10] = b10link;

var path ="..";
//var path ="http://www.ou.edu/cas/psychology/";
if (rootdistance == 0) {path = "."}
if (rootdistance == -1) 
    { path = "http://www.ou.edu/cas/psychology"; 
    }
else{
    if (rootdistance > 1)
        {path +="/";
        for (var s=2; s<=rootdistance; s++)
            {path += "../";
            }//endfor
        }//endif rootdistance
    }//endif rootdistance
//path ="http://www.oU.edu/cas/psychology";


var tablewrite = "<table class=menu width= 150 border=0 cellspacing=0 cellpadding=0><TR><TD nowrap>&nbsp;</TD></TR>";

for (var i=0; i<branch.length; i++) {
	var linkPath=replaceSubstring(path+branchlink[i],"//","/")
	tablewrite += "<tr><td valign = center height = "+branchheight+" nowrap>";

	if (i==openbranch) {
		tablewrite += "<A class=navlargeactive href='"+ linkPath +"'>";
		tablewrite += "<IMG align=top border=0 height=20 SRC='"+branchpicPath+"'>";
	} else {
		tablewrite += "<A class=navlarge href='"+ linkPath +"'> ";
		tablewrite += "<IMG border = 0 align=center  SRC='"+nonactivebranchPath+"'>";
	}
	tablewrite +=branch[i]+"</A>";
	tablewrite +="</td></tr>";
	if (i==openbranch) {
	for (var j = 0; j<linktext[i].length; j++) {
		if (links[i][j] != "") { // this is not a sub-subpage
			tablewrite += "<tr><td valign = middle height = "+ linkheight +" nowrap>";
			if (j==highlightlink) {tablewrite +="<A class=highlight "
			}
			else { tablewrite += "<A class=navsmall ";
			} 	
			tablewrite +="href='"+path+links[i][j]+"'>";
			if (j==highlightlink) {tablewrite += "<IMG border=0 align=middle SRC='"+activelinkLPath+"' width=16 height=22>";
			}
			else {tablewrite +="<IMG border = 0 align=middle SRC ='";
				if (j < highlightlink) {
					if ((j == highlightlink-1) && (links[i][j+1]=="")) {
						tablewrite += activelinkLPath+"' width = 16 height = 22>";
					} 
					else {tablewrite += activeconnectPath+"' width = 16 height = 22>";
					}
				}
				else {tablewrite += blankPath+"'>";
				}
			}
			tablewrite +=linktext[i][j]+"</A></td></tr>";
			
		} //endif links
		else { if (j==highlightlink) { //this is a subsubheader
			tablewrite += "<tr><td valign = middle height = "+linkheight +" nowrap>";
			tablewrite +="<IMG border = 0 align=top SRC ='"+activelinkLPath+"' >";
			tablewrite +="<IMG border = 0 align=top SRC ='"+blankPath+"' width=4>";
			tablewrite += "<SPAN class=menuhighlight>"+linktext[i][j]+"</SPAN></td></tr>";
			} //endif j==highlightlink
			} //endelse 		
	} //endfor
	} //endif i==openbranch
} //endfor loop
tablewrite += "<tr><td height = 50>&nbsp;</td></tr>";


//linkPath=replaceSubstring(path+branchlink[i],"//","/");

//tablewrite +="<TR><TD nowrap align=center><IMG border=0 SRC='"+path+"/images/navigation/PSY.gif'></TD></TR>";
tablewrite +="<TR><TD nowrap align=center><A href='"+linkPath+"'><IMG border=0 SRC='"+psyPath+"'></a></TD></TR>";
tablewrite += "<tr><td height = 50>&nbsp;</td></tr>";
tablewrite += "</table>";
return tablewrite;
}


function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function