﻿/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	var isSliding = false;
	var isTimingOut = false;
	
	function undoSliding(){
	    if(isTimingOut==false){
	         setTimeout("undoSliding2()",openOnSlideAddition);
	         isTimingOut = true;
	    }
	}
	
    function undoSliding2(){
	    isTimingOut = false;
	    isSliding = false;
	}
	
	$(document).ready(function(){
	    $("object").hide();
            setUI();
 
            $('[loginPassword]').keyup(
                    function(e) {  
                      
                        if(e.keyCode == 13) 
                        {    
                      
                         $('[isLoginFormButton]').click();    e.preventDefault();  
                         }
                    }
            );

	    
	   
	    
	    // hide all items where "menuItem" attribute exists
		$('[menuItem]').hide();
		  theTDs = $('td');
        
        for(k=0;k<theTDs.length;k++){
            if($(theTDs[k]).attr("style") != undefined){
                if( ($(theTDs[k]).attr("style").indexOf("silver") != -1) || ($(theTDs[k]).attr("style").indexOf("Silver") != -1)){
                       
                    $(theTDs[k]).attr("style",$(theTDs[k]).attr("style").split('Silver','#00529B'));
                    $(theTDs[k]).attr("style",$(theTDs[k]).attr("style").split('silver','#00529B'));
                }
                 if( ($(theTDs[k]).attr("style").indexOf("width") != -1) || ($(theTDs[k]).attr("style").indexOf("Width") != -1)  || ($(theTDs[k]).attr("style").indexOf("WIDTH") != -1) )
                {
                //
                    if( ($(theTDs[k]).attr("style").indexOf("70") != -1) )
                    {
                        $(theTDs[k]).html("<font color=\"#3f74aa\">" + $(theTDs[k]).html() +  "</font>")
 
                    }
                  
                }
            }
            
        }
		// if a menu item is specified for load, it will auto load.
	    if ( openSelectedMenu)
	    {
	            activeLink = $(activeLink);
	            activeLink.removeClass($(activeLink).attr('offclass')).addClass($(activeLink).attr('onclass'));
	    
		        var prev = "";
		        for(i=0;i<openMenuArray.length;i++)
		        {
		           // convert to Object
		           elObj 	= $("#menu" + prev + openMenuArray[i]);
		           linkObj 	= $("#menu" + prev + openMenuArray[i] + "_link");
        		   
				   subImage = $("#menu" + prev + openMenuArray[i] + "_image" );
				   if(subImage.length > 0)
					{
						document.getElementById(subImage.attr('id')).src = subImage.attr('onimg');
					}
		           linkObj.removeClass($(linkObj).attr('offclass')).addClass($(linkObj).attr('onclass'));
		           // build object reference
		           prev += openMenuArray[i] + "_";
        		   
		           // update object reference in array
		           openMenuArray[i]=elObj;
		
					
		        }	
        		$("#MenuContainer").slideToggle(500);
		        intervals = setInterval("toggleDelay()",menuOpenInterval);
	    }
			
		// define what happens when you click on a span
		$("div span").click(function(){
		    if(($(this).attr('href'))){
		      
			    if($(this).attr('href') != "#"){
				    generateURL($(this).parent().attr('id'),$(this).attr('link'),$(this).attr('id'));
			    }
			    else
			    {	
			        subMenu =  $("#" + $(this).attr('id').split("_link").join("") );
			    	subImage =  $("#" + $(this).attr('id').split("_link").join("_image") );
					
//					alert(subImage.length);
						
					
				    var closeThisMenu = false;
    				
				    $(this).parent().children('span').removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));
    				
				    if ($(subMenu).is(':visible')) {
					    closeThisMenu = true;
					    $(this).removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));
						if(subImage.length > 0)
						{
							document.getElementById(subImage.attr('id')).src = subImage.attr('offimg');
						}
				    }
				    else
				    {
					    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass'));
						if(subImage.length > 0)
						{
							document.getElementById(subImage.attr('id')).src = subImage.attr('onimg');
						}
				    }
    				
					
				    // Grab the ID and determine classes to swap to
    				
    					
				    // slide all on the same level closed
				    $(this).parent().children('div').not('[separator]').slideUp(menuCloseSpeed);
    		
				    if(closeThisMenu==false){
					    // slide the chosen one open			
					    $(subMenu).slideToggle(menuCloseSpeed); 
					    // swap style in
				    }
			    }
			 }
			 
			
		});
	
	    if(!openOnRollover)
	    {
	     	 $("div span").mouseover(function(){
			         subMenu =  $("#" + $(this).attr('id').split("_link").join("") + "_1");
			         
			         if(activeLink == ""){
		                if(subMenu.length > 0)
		                { 		               
		                    if (!$(subMenu).is(':visible')) {
					            $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass'));
				            } 
		                }
		                else
		                {
		                    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass'));       
		                }    
		            }
		            else
		            {
		               // alert($($(this).attr('id').split("_link").join("") + "_1"));
		                if(subMenu.length > 0)
		                {
		               // alert();
		              
		                    if ((!$(subMenu).is(':visible')) && ($(this).attr('id') != activeLink.attr('id'))) {
					             $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass'));
				            } 
		                }
		                else
		                {
		                    if (($(this).attr('id') != activeLink.attr('id'))) { 
		                         $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass')); 
		                    }
		                }     
				    }		
			  });
	    }
	    else
	    {
		// swap class on mouseover, except those "selected/clicked on"
		$("div span").mouseover(function(){
		
		if( !isSliding ){

		
		    if(($(this).attr('href'))){	    
		           
		            subMenu =  $("#" + $(this).attr('id').split("_link").join("") + "_1");
		           
		            if(activeLink == ""){
		                if(subMenu.length > 0)
		                { 		               
		                    if (!$(subMenu).is(':visible')) {
					            $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass'));
				            } 
		                }
		                else
		                {
		                    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass'));       
		                }    
		            }
		            else
		            {
		               // alert($($(this).attr('id').split("_link").join("") + "_1"));
		                if(subMenu.length > 0)
		                {
		              //  alert();
		                    if ((!$(subMenu).is(':visible')) && ($(this).attr('id') != activeLink.attr('id'))) {
					             $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass'));
				            } 
		                }
		                else
		                {
		                    if (($(this).attr('id') != activeLink.attr('id'))) { 
		                         $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('activeclass')); 
		                    }
		                }     
				    }		
			 }
		
			 
			 
			 // additional code for rollover:
			 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
			 
				if(($(this).attr('href'))){
		       
		       
		    
			    if($(this).attr('href') != "#"){
				 //   generateURL($(this).parent().attr('id'),$(this).attr('link'),$(this).attr('id'));
			    }
			   
			        subMenu =  $("#" + $(this).attr('id').split("_link").join("") );
			    	subImage =  $("#" + $(this).attr('id').split("_link").join("_image") );
					
//					alert(subImage.length);
						
					
				    var closeThisMenu = false;
    				
				    $(this).parent().children('span').removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));
    				
				    if ($(subMenu).is(':visible')) {
					    closeThisMenu = true;
					    $(this).removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));
						if(subImage.length > 0)
						{
							document.getElementById(subImage.attr('id')).src = subImage.attr('offimg');
						}
				    }
				    else
				    {
					    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass'));
						if(subImage.length > 0)
						{
							document.getElementById(subImage.attr('id')).src = subImage.attr('onimg');
						}
				    }
    				
					
				    // Grab the ID and determine classes to swap to
    				
    			     isSliding = true;
    			     
    			    
				    // slide all on the same level closed
				    $(this).parent().children('div').not('[separator]').slideUp(menuCloseSpeed);
    		
				    if(closeThisMenu==false){
					    // slide the chosen one open	
					    		
					    $(subMenu).slideToggle(menuCloseSpeed,undoSliding()); 
					    // swap style in
				    }
			    }
						 
			 }
		
			 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
			 
		});
		
		// swap class on mouseout, except those "selected/clicked on"
		
		
		 }
		$("div span").mouseout(function(){
		  undoSliding();
		    if(!(isSliding)){
		    
		    if(($(this).attr('href'))){
		           
		            subMenu =  $("#" + $(this).attr('id').split("_link").join("") );
		            
 		            if(activeLink == ""){
		                if($(subMenu).length > 0)
		                {
		                    if (!$(subMenu).is(':visible')) {
				              $(this).removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));   
				            }
		                }
		                else
		                {
		                    $(this).removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));       
		                }    
		            }
		            else
		            {
		                
		                if(subMenu.length > 0)
		                {
		                   
		                    if ((!$(subMenu).is(':visible')) && ($(this).attr('id') != activeLink.attr('id'))) {
					            $(this).removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));
				            } 
		                }
		                else
		                {
		                    if (($(this).attr('id') != activeLink.attr('id'))) { 
		                        $(this).removeClass($(this).attr('onclass')).addClass($(this).attr('offclass'));   
		                    }
		                }         
				    }	
			 }
			 }
			 
			
			 
		});
	});
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function toggleDelay(){
		  if(num < openMenuArray.length)
		  {
			openMenuArray[num].slideToggle(menuOpenSpeed);
			num++;
		  }   
		  else
		  {
		  clearInterval(intervals);
		    
		    if(activeLink.attr("id") != undefined)
		    {
		         if($(activeLink.attr("id").split("_link").join(""))){
		  
		         $("#" + activeLink.attr("id").split("_link").join("")).slideToggle(menuOpenSpeed);
		        }
		    }
		
		  buildSiteMap();
          SEOLinkReplace(); 
		  AjaxSiteMap();
		  $("#droppyNav").html($("#SiteMapDiv").html());
		  $("#SiteMapDiv").find('[isFakeLink]').each(function()
                {
		            $(this).before($(this).html());
		            $(this).remove();
		    });
		        ///  alert($("#droppyNav").find("ul:first-child").html());



		        //
		        if (document.all && !window.opera && !window.XMLHttpRequest && $.browser.msie)
		        { var isIE6 = true; }
		        else
		        { var isIE6 = false; };
		        $.browser.msie6 = isIE6;
		        if (isIE6) {
		            $("#droppyNav").find('div').remove();
		        }
               $("#droppyNav").find("ul:first-child").attr("id","nav");
		       $("#nav").hide();
                
		       $("#nav").droppy({speed: 100});
		       $("#nav").animate({ opacity:"toggle"}, 500);

		       $("#MenuContainer").html("");
		        $("#nav li").each(function()
                {
		            if($(this).html().indexOf("href") == -1){
		       
		              //  $(this).html("<a href\"#\">" + $(this).html() + "</a>");   
		            }
		        });
		        
		       $("#nav").find("[isBetween]").animate({ opacity:"toggle"}, 1000);
		       loadUrchin();
		   }
		 
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function generateURL(LinkPath,LinkToGoTo,LinkID){
		var tempURL = LinkToGoTo;
		
		if($("#" + LinkID).attr("target") == "_blank"){
		    window.open($("#" + LinkID).attr("link"));
		}
		else
		{
		    if(tempURL.indexOf("linkPath") == -1)
		    {
			    if(tempURL.indexOf("?") != -1){
				    tempURL += "&linkPath=" + LinkPath.split("menu").join("").split("_link").join("") + "&lID=" + LinkID.split("menu").join("").split("_link").join("");
			    }
			    else
			    {
				    tempURL += "?linkPath=" + LinkPath.split("menu").join("").split("_link").join("") + "&lID=" + LinkID.split("menu").join("").split("_link").join("");;
			    }
		    }
            
		    document.location.href= tempURL.split("#").join("");
		}
		return;
	}
	
		function generateURLSEO(LinkPath,LinkToGoTo,LinkID){
		var tempURL = LinkToGoTo;
		
		if($("#" + LinkID).attr("target") == "_blank"){
		
		    return $("#" + LinkID).attr("link");
		}
		else
		{
		    if(tempURL.indexOf("linkPath") == -1)
		    {
			    if(tempURL.indexOf("?") != -1){
				    tempURL += "&linkPath=" + LinkPath.split("menu").join("").split("_link").join("") + "&lID=" + LinkID.split("menu").join("").split("_link").join("");
			    }
			    else
			    {
				    tempURL += "?linkPath=" + LinkPath.split("menu").join("").split("_link").join("") + "&lID=" + LinkID.split("menu").join("").split("_link").join("");;
			    }
		    }
            
		   
		}
		//alert(tempURL);
		$('[href*=doAccordionSEOLink]').each(function()
        {
            
            theFunction = $(this).attr("href").split("javascript:").join("");
            theFunction = theFunction.split("'").join("");
            theFunction = theFunction.split("(").join("");
            theFunction = theFunction.split(");").join("");
            theFunction = theFunction.split("doAccordionSEOLink").join("");
            if(tempURL.indexOf(theFunction) != -1){
             $(this).attr("href",tempURL);
            }
            
        });
		return tempURL;
	}
	
	
	function generateURLQS(LinkPath,LinkToGoTo,LinkID,QS){
		var tempURL = LinkToGoTo;


		
		//if(tempURL.indexOf("linkPath") == -1)
		//{
			if(tempURL.indexOf("?") != -1){
				tempURL += QS;
			}
			else
			{
					tempURL += QS;//tempURL += "?linkPath=" + LinkPath.split("menu").join("").split("_link").join("") + "&lID=" + LinkID.split("menu").join("").split("_link").join("") + QS;
			}
		//}
      //  alert(tempURL);
		document.location.href= tempURL.split("#").join("");
		return;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Prevent links being executed
	
	function stopLink(){
		return;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function genSiteMap(){
    var theHTML = "";
    
    theHTML += "<ul>";
    
    $("#MenuContainer").children("span").each(function()
    {
        theHTML += "<li isBetween=\"true\" style=\"background-color:Transparent;display:none;background-image:url(" + getPaths() + "images/nav_divider.gif);background-repeat:no-repeat;height:60px;background-position:center;width:15px;\">&nbsp;</li>";
    //alert(theHTML);  
        theHTML += "<li><div isBetween=\"true\" style=\"display:none;\"><Br></div>";
        if($(this).attr("link")){
          theHTML += "<a SEOLink=\"true\" href=\"javascript:doAccordionSEOLink('" + $(this).attr("link")  + "');\">" + $(this).html() + "</a>";     
        }
        else
        {
         theHTML += "<a href=\"#\" isFakeLink=\"true\">" + $(this).html() + "</a>";     
        }
        //alert($(this).next("div").length);
        if($(this).next("div").length>0)
        {
            theHTML += getSubs($(this).next("div"));
        }
        theHTML += "</li>";     
      
    });
      theHTML += "<li isBetween=\"true\" style=\"background-color:Transparent;display:none;background-image:url(" + getPaths() + "images/nav_divider.gif);background-repeat:no-repeat;height:60px;background-position:center;width:15px;\">&nbsp;</li>";
      
    theHTML += "</ul>"
     
  
    	//document.write('<textarea rows="40" cols="250">'+theHTML+'</textarea>');

    return theHTML;
}

function getSubs(theObj){
    var theHTML = "";
    
    theHTML += "<ul>";
  
 // alert(theHTML);
    $(theObj).children("span").each(function()
    {
          
        theHTML += "<li>";
        //alert(theHTML);
        if($(this).attr("link")){
          theHTML += "<a SEOLink=\"true\" href=\"javascript:doAccordionSEOLink('" + $(this).attr("link")  + "');\">" + $(this).html() + "</a>";     
        }
        else
        {
           theHTML += "<a href=\"#\" isFakeLink=\"true\">" + $(this).html() + "</a>";     
        }
        if($(this).next("div").length>0)
        {
            theHTML += getSubs($(this).next("div"));
        }
        theHTML += "</li>";     
       
    });
    
    theHTML += "</ul>"

     return theHTML;
}



function showSiteMap(){
   
   //  SEOLinkReplace();
    $("#SiteMapDiv").html($("#SiteMapDiv").html().split("javascript:doAccordionSEOLink('").join("").split("');").join(""))
    $("#SiteMapDiv").slideToggle();
    
    $("#BodyDiv").slideToggle();
}