/**
 * JS file using jQuery to add necessary styling to HTML leftnav menu's for VeriSign sites
 * Author: E Grobler
 * Version: 1.2
 * Date: 16/02/2010
 * 
 * Version 1.3  :o)
 * Author: Rob Perez
 * 
 * Added noClicksHere to disable cursor, underlining, and clicking when the user is on the highlighted page
 * while preserving existing "parental" clicking.
 * 
 * Date: April 5, 2010
 * 
   Version 1.3.1  :o)
 * Author: Rob Perez
 *  
 *  navigation now requires a function call rather than happening on ready()  for improved (perception of) performance
 *  
 *  generateLefNav()
 *  
 *  called immediately after the nav is available
 * 
 * 
 * Date: April 6, 2010
 * 
 */

noClicksHere = function(){
var myLocation = "" + window.location;
	$("div#leftnav ul a").each(function(i){
		if(this.href == myLocation || this.href + "index.html" == myLocation){
			$(this).css("cursor","text");
			$(this).css("textDecoration","none");
			$(this).click(function(){				
				return false;				
			});
		}
	});
}



generateLefNav = function(){

    /* Check if url contains 'index.html'. If not then add it to the url. */
	//First check if it's got some other name than index.html...

	var curr_url = "";
	var fname = ($.url.attr("file") == null) ? "" : $.url.attr("file");
	switch(fname) {
		case "": curr_url = $.url.attr("path") + "index.html"; break;
		case "index.html": curr_url = $.url.attr("path");break;
		default: curr_url = $.url.attr("path").substr(0,($.url.attr("path").length - $.url.attr("file").length)) + "index.html";break;
	}
	
	var parent_url = "";
	var notthere = 0;
	
	while (notthere < 1) {
		//If topmost URL, then parent and current url is the same, otherwise generate parent url.
		parent_url = (curr_url == $("div#leftnav ul a:first").attr("href")) ? curr_url : curr_url.substr(0, curr_url.substr(0, curr_url.lastIndexOf("/")).lastIndexOf("/")+1) + "index.html";
		//If the current url doesn't exist in the leftnav, then set it equal to its parent
		
		if ($("div#leftnav ul").find("li a[href$='"+curr_url+"']").length == 0) {
			notthere = 1;
		}
		else {
			notthere = $("div#leftnav ul").find("li a[href$='"+curr_url+"']").length;
		}
		//set variable to length (occurences of the current url)
		//
		
		//If current page url isn't part of the navigation, just set notthere var to 1 to get out of the endless loop
		if ((notthere < 1) && (curr_url == "/index.html")) {
			notthere = 1;
		}
		
	}
	
    //Adding classes to relevant <li> tags so the correct items are highlighted
    var curr_url_el = $("div#leftnav a[href$='" + curr_url + "']");
    var parent_count = curr_url_el.parents("li").length;
    
	/*
	if (notthere == 1) {
		curr_url_el.parents("li:eq(0):not([class='main'])").addClass("active").addClass("nohigh");
	} else {
		curr_url_el.parents("li:eq(0):not([class='main'])").addClass("active");
	}
    */
	curr_url_el.parents("li:eq(0):not([class='main'])").addClass("active");
	
    if (parent_count == 2) {
        curr_url_el.parents("li:eq(1):not([class='main'])").addClass("activechild");
    }
	
	if ((parent_count == 0) && (notthere == 1)) {
		//3rd level nav
		$("div#leftnav a[href$='" + parent_url + "']").parents("li:eq(1):not([class='main'])").addClass("activechild");
	}
	
	noClicksHere();

};


