﻿/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	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(){

            $('[loginPassword]').keyup(
                    function(e) {  
                      
                        if(e.keyCode == 13) 
                        {    
                      
                         $('[isLoginFormButton]').click();    e.preventDefault();  
                         }
                    }
            );

	      $("input.FormField").mouseover(function(){
	        
	        $(this).addClass("FormFieldHover");
	        $(this).removeClass("FormField");
	    });
	    
	     $("input.FormField").mouseout(function(){
	        
	        $(this).addClass("FormField");
	        $(this).removeClass("FormFieldHover");
	    });
	    
	    
	    
	    $(".LogoutButtons").mouseover(function(){
	        
	        $(this).addClass("LogoutButtonsHover");
	        $(this).removeClass("LogoutButtons");
	    });
	    
	     $(".LogoutButtons").mouseout(function(){
	        
	        $(this).addClass("LogoutButtons");
	        $(this).removeClass("LogoutButtonsHover");
	    });
	    
	    $(".Button").mouseover(function(){
	        
	        $(this).addClass("ButtonHover");
	        $(this).removeClass("Button");
	    });
	    
	     $(".Button").mouseout(function(){
	        
	        $(this).addClass("Button");
	        $(this).removeClass("ButtonHover");
	    });
	    // 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;
		
					
		        }	
        		
		        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('onclass'));
				            } 
		                }
		                else
		                {
		                    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass'));       
		                }    
		            }
		            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('onclass'));
				            } 
		                }
		                else
		                {
		                    if (($(this).attr('id') != activeLink.attr('id'))) { 
		                         $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass')); 
		                    }
		                }     
				    }		
			  });
	    }
	    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('onclass'));
				            } 
		                }
		                else
		                {
		                    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass'));       
		                }    
		            }
		            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('onclass'));
				            } 
		                }
		                else
		                {
		                    if (($(this).attr('id') != activeLink.attr('id'))) { 
		                         $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass')); 
		                    }
		                }     
				    }		
			 }
		
			 
			 
			 // 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);
		        }
		    }
		  
		  
		    /*
		    // open children automatically at the end
		    var theNextChild = activeLink.attr("id").split("_link").join("_1");
		    
		    alert("#" + theNextChild);
		  //  if($(theNextChild)){
		        $("#" + theNextChild).slideToggle(menuOpenSpeed);
		  //  }
		   // if(theNextChild)
		   // {
		   // alert("X");
		   // }
		   */
		  }
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function generateURL(LinkPath,LinkToGoTo,LinkID){
		var tempURL = LinkToGoTo;
		
		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 generateURLQS(LinkPath,LinkToGoTo,LinkID,QS){
		var tempURL = LinkToGoTo;
		
		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("") + QS;
			}
			else
			{
				tempURL += "?linkPath=" + LinkPath.split("menu").join("").split("_link").join("") + "&lID=" + LinkID.split("menu").join("").split("_link").join("") + QS;
			}
		}
        
		document.location.href= tempURL.split("#").join("");
		return;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Prevent links being executed
	
	function stopLink(){
		return;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
