// JavaScript Document


//this function highlights the link that the user is at
function checklocation(url){

	var currURL = "" + url;
	
	//look for ending in "#" and if present, remove it
	if (currURL.charAt(currURL.length-1)=="#") 
		{
			currURL = currURL.substring(0, currURL.length-1);
			}
	if (currURL.substring(currURL.length-3)=="#go"){
			currURL = currURL.substring(0,currURL.length-3);
		}

	// look for ending in "/" and if present, append at the end "index.html"
	if (currURL.charAt(currURL.length-1)=="/") 
		{
			var str = "index.html";
			currURL = currURL.concat(str);
			}
	
	var topURL = "";
	var foldername = "";
	var pos;
	
	//TOP NAVIGATION
	//If the page is not an index page, then identify the section and highlight it	
		if (currURL.charAt(currURL.length-6)!="x"){

				pos = currURL.lastIndexOf("/");
				//remove the file name
				topURL = currURL.substr(0, pos);
				 	
				//determine where the next "/" is, , because folder name is right before that
				pos= topURL.lastIndexOf("/"); 
				
				foldername = topURL.substring(pos+1, topURL.length);
				
				if (foldername == "math" || foldername == "CNAevents" || foldername == "CCFevents" || foldername == "gradevents"){
					//remove folder name from topURL
					pos = topURL.lastIndexOf("/");
					topURL = topURL.substr(0, pos);				
				}
				
				if (foldername == "events" || foldername == "news"){
					//remove two folder names from topURL
					pos = topURL.lastIndexOf("/");
					topURL = topURL.substr(0, pos);
					pos = topURL.lastIndexOf("/");
					topURL = topURL.substr(0, pos);	
				}
				
				var str = "/index.html";
				topURL = topURL.concat(str);
				
				//search collection of links of document and highlight the section link - top navigation
				for (var i=0; i<document.links.length;i++)
				{	
					var link = document.links[i];
					
					if(link == topURL){
						link.style.textDecoration = "none";		
					 	link.style.color="#999999";
						link.href=topURL + "#";
						break;
					} //end of if
				}//end of for
				
				
		}//end of if


//LOCAL NAVIGATION
	//On first, second and third level pages, the URL of the page coincides with the URL of the link on the local nav
	//But for fourth level pages, the currURL is adjusted
		
		if (foldername == "CNAevents" || foldername == "CCFevents" || foldername == "gradevents" || foldername == "news"){
				currURL = topURL;		
		}
		if (foldername == "events"){
			//remove filename
			pos = topURL.lastIndexOf("/");
			topURL = topURL.substr(0, pos);
			//add URL termination of Events page
			currURL = topURL + "/math/events.html";
		}
		
	
	
	//find the link on the local navigation that corresponds to the currURL and highlight it
	for (var i=0; i<document.links.length;i++)
		{	
		
		var link = document.links[i];

		if(link == currURL){		
			  link.style.textDecoration = "none";		
			  link.style.backgroundColor = "#666666";
			  link.style.color="#FFF";
			  break;
			} 
		}
	}
