
$(document).ready(function(){

    var bodyID = this.body.id;
    //var requestURL  = this.location.href.substring(0,this.location.href.indexOf(".aspx")+5);
    var requestURL  = this.location.href;
    requestURL = requestURL.replace("#","");
    //alert(requestURL);
  
    if (!requestURL.endsWith('/')) 
        requestURL = requestURL+"/";
    //Now remove 3rd Level from the URL for setting the select class on navigation
    var mySplitResult = requestURL.split("/");
    if(mySplitResult.length == 7 )
    {
        requestURL = requestURL.replace(mySplitResult[5]+"/","");
    }
    
    $('#primary_nav a').each(function(i) {
        if(this.toString()==requestURL)
        {
	        var parentID=$(this).parent().attr("id");
	        if(parentID=="")
	        {
	            parentID=$(this).parent().parent().parent().attr("id");
	        }
	        $("#"+parentID+" a:first").addClass("selected");
	        $("#"+parentID+" ul:first").show();
	        this.className = "selected";
	    }
    });
    
    //Handling Global navigation    
    $('#li_applynow').mouseover(function()
    {   
        $("#li_applynow ul:first").show();
    });

    $('#li_applynow').mouseout(function()
    {   
        
       $("#li_applynow ul:first").hide();
    });
});

String.prototype.endsWith = function(str) 
{return (this.match(str+"$")==str)}


/**
 * @purpose            : Get the (x,y) coordinate of a DOM element
 * @param  object elem : a DOM element or null
 * @return object      : an associative array, where indicies "x"
 *                       and "y" hold their respective coordinates
 * @note               : function is recursive
 */
function getXYpos(elem) {
   if (!elem) {
      return {"x":0,"y":0};
   }
   var xy={"x":elem.offsetLeft,"y":elem.offsetTop}
   var par=getXYpos(elem.offsetParent);
   for (var key in par) {
      xy[key]+=par[key];
   }
   return xy;
}