﻿/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$(document).ready(function(){
		$("area").mouseover(function(e){
			var theToolTipValue=$(this).attr("tooltip");
		    showCursorMessage($("#" + theToolTipValue).html());
		});
		
	    // hide all items where "menuItem" attribute exists
		$('[menuItem]').hide();
		//alert(openSelectedMenu);
		// 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");
        		   
		           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("") );
			    
				    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'));
				    }
				    else
				    {
					    $(this).removeClass($(this).attr('offclass')).addClass($(this).attr('onclass'));
				    }
    				
				    // 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
				    }
			    }
			 }
		});
				
		// swap class on mouseover, except those "selected/clicked on"
		$("div span").mouseover(function(){
		    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')); 
		                    }
		                }     
				    }		
			 }
		});
		
		// swap class on mouseout, except those "selected/clicked on"
		$("div span").mouseout(function(){
		    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);
		  }
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	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.replace(tempURL.split("#").join(""));
		return;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Prevent links being executed
	
	function stopLink(){
		return;
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
