﻿var dir = "site";
var timeOut = 5000;
var subMenuHover = false;
var timerID = 0;

// Parent Button Attributes
var previouseParentButtonId;
var parentButtonId;
var parentButtonImageDir;
var parentButtonNameOn;
var parentButtonNameOff;
var parentHasSubMenu;
var parentButtonOn = false;
var parentDivId = null; // Div id of the clicked parent tab with submenus

// Parent Id only set when a subnav item is clicked
var parentMenuButtonId = null;

var divId = null;
var previousDivId = null;
var sibblingDivIdOn = false;

// Sets OnMouseOver Roll Over Effect
function setOver(id,imageDir, nameon, hasSubMenu, buttonDivId)
{
    // Turns off the previous parent's attibutes before proceeding
    clearTimeout(timerID);
    setParentTabAttributesOff(false, null, null); 
    nullParentValues();
            

	// Checks to see if the previous rolled over tab and the current tab are different
	// If so turn off the previous tab, and turn on the current tab or
	// Turn the original parent's submenu on and turn off rollover
	
	if( (previousDivId != null) && (buttonDivId == null) )
	{
	    closePreviouseDivId(previousDivId, parentDivId, 'false');
	}
    else if((previouseParentButtonId != buttonDivId) && (previouseParentButtonId != null))    
        closePreviouseDivId(previousDivId, null, 'showNow'); 
	previouseParentButtonId = buttonDivId; 
	
	
	if(document.getElementById)
	{
		imgElem=document.getElementById(id);		
	    imgElem.setAttribute("src",imageDir +"/" + nameon);
		
		// Checks to see if the parent button is still turned on
	    isParentStillActive(previousDivId);            
        
		// Determines is a Tab item has a submenu
		if(hasSubMenu == 'true')
		{		
		    // Determines if there is a Div Id associated withthe subMenu
		    if(buttonDivId != null)
		    {
		        // Checks to see if there is another SubMenu currently turned on
		        if(previousDivId != null)
		        {
		            if(parentButtonOn == true)
		            {
		                sibblingDivIdOn = closePreviouseDivId(parentDivId, buttonDivId, 'false');
		                //timerId = setTimeout("showPreviouseDivId('" + buttonDivId + "')", 0); 	                
		            }
		            else
		            {
		                closePreviouseDivId(previousDivId, null, 'false');
		                divId = buttonDivId; 
                        previousDivId = divId; 
		            }
		        }
		        else
		        {		            
                    divId = buttonDivId; 
                    previousDivId = divId; 
                }
            }
            
	        // Sets the parent attributes for the SubNav if it exists
            parentButtonId = id;
            parentButtonImageDir = imageDir;
            parentButtonNameOn = nameon;
            parentHasSubMenu = hasSubMenu;           
            
            if(parentButtonOn == true)
		    {         
	            if( (document.getElementById(divId).style.display == "none") && (document.getElementById(previousDivId).style.display == "block") && (sibblingDivIdOn == false))
	            {             
	                showTabSubNav(divId);	                
	            }	   
	            // Set the previousDivId equal to the current rolled over button div
	            previousDivId = buttonDivId;         
		    }
		    else
		    {
		        if(document.getElementById(divId).style.display == "none")
	            {
	                showTabSubNav(divId);
	            }
		    }
		    
		}
		else
		{
		    // Handles hiding submenus without when rolling over a tab without a submenu
		    if(document.getElementById(divId) != null)
		    {
		        hideTabSubNav(true);
		    }
		}
	}
}

// Sets OnMouseOut Roll Over Effect
function setOut(id,imageDir,nameoff, hasSubMenu, buttonDivId)
{   
    if(hasSubMenu)
        parentButtonNameOff = nameoff;
    
    if(hasSubMenu == 'false')
    {
	    if(document.getElementById)
	    {
		    imgElem=document.getElementById(id);
		        imgElem.setAttribute("src",imageDir +"/" + nameoff);
	    }
	}
	else
	{
	    if(parentButtonOn == true)
	    { 
	        // Closes your rolled over subMenu
	        timerID = setTimeout("closePreviouseDivId('" + buttonDivId + "','" + parentDivId + "', 'true')", 2000);
	    }
	}
}

// ##################################################################################
//  Mouse Over Tab Sub Menu Methods 
// ##################################################################################

function showPreviouseDivId(prevDivId)
{
    document.getElementById(prevDivId).style.display = "block";
}

function closePreviouseDivId(prevDivId, showDivId, waitToCloseOriginal)
{ 
    sibblingDivIdOn = false;      
    if(prevDivId != null)
    {
        document.getElementById(prevDivId).style.display = "none";
        
        if( showDivId != null)
        {            
            document.getElementById(showDivId).style.display = "block";  
            // Turns off the rolled over Parent tab
            turnOffParentButton();                     
            return true;
        }
    }        
    else if(waitToCloseOriginal == 'true')
    {
        // Shows the original/Active submenu	       
        showPreviouseDivId(showDivId);
        
        // Turns off the rolled over Parent tab
        turnOffParentButton();
    }
    else if(waitToCloseOriginal == 'showNow')
    {              
        // Shows the original/Active submenu	       
        showPreviouseDivId(divId);
        
        // Turns off the rolled over Parent tab
        turnOffParentButton();
    }

}

function initializeDiv(buttonDivId)
{
    if(buttonDivId != null)
        divId = buttonDivId;
    alert(buttonDivId);
		    
    document.getElementById(divId).style.display = "none";
}

// Checks to see if the selected parent Tab is still turned on
// If the divId = null the parent is not active
function isParentStillActive(divId)
{
    if(document.getElementById(parentMenuButtonId) != null)
    {
        var buttonSrc = document.getElementById(parentMenuButtonId).src;
        //alert(buttonSrc.toString() + "   " + buttonSrc.toString().indexOf("off"));
        if( (buttonSrc.toString().indexOf("off") != -1) || (divId == null) )
        {
            parentButtonOn = false;       
            parentMenuButtonId = null;
        }
    }
}

// Clears out the parent button values
function nullParentValues()
{
    // Default settings for subNav
    parentButtonId = null;
    parentButtonImageDir = null;
    parentButtonNameOn = null;
    parentHasSubMenu = false;
}

// Turns on the Div containing the submenu items
function showSubNavDiv(showDivId)
{
    if(document.getElementById(showDivId) != null)
    {
        if(document.getElementById(showDivId).style.display == "none")
            document.getElementById(showDivId).style.display = "block";
        parentButtonOn = true;
    }
}

// Shows the Tab SubMenu naviation
function showTabSubNav()
{
    clearTimeout(timerID);
    //subMenuHover = true;
    if(document.getElementById(divId).style.display == "none")
    {
        document.getElementById(divId).style.display = "block";    
        timerID = setTimeout("hideTabSubNav(true)",timeOut);
        setParentTabAttributesOn();
    }
}

// Hides the Tab SubMenu naviation
function hideTabSubNav(hideSubNav)
{
    if( (hideSubNav == true) && (parentButtonOn == false) )
    {
        document.getElementById(divId).style.display = "none";
        setParentTabAttributesOff(false, null, null);         
    }
}

// Turns the parent tab on while the submenu is selected
function setParentTabAttributesOn()
{ 
    if(parentHasSubMenu == 'true')
    {
        imgElem=document.getElementById(parentButtonId);		
	    	imgElem.setAttribute("src", parentButtonImageDir +"/" + parentButtonNameOn);
	}
}

function turnOffParentButton()
{
    if(document.getElementById(parentButtonId) != null)
    {
        imgElem=document.getElementById(parentButtonId);
        imgElem.setAttribute("src", parentButtonImageDir +"/" + parentButtonNameOff);
    }
}

// Turns the parent tab off while the submenu is selected
function setParentTabAttributesOff(parentClicked, parentId, myParentDivId)
{    
        
   if( (parentHasSubMenu == 'true') || (parentId != null) )
    {       
        
        // Turn off the active parent tab if the parent was clicked
        if(parentClicked == false)
        {
            turnOffParentButton();
        }
        else
        {        
            nullParentValues();
            parentButtonOn = true;            
            setTimeout("showSubNavDiv('"+ myParentDivId +"')", 1000); 
            parentMenuButtonId = parentId;  
            parentDivId = myParentDivId;          
            clearTimeout(timerID);
            
        }
         	    
	}	
}

//****************************************************************
// Toggle
//****************************************************************
var toggledImage
var blownUp = "false";
var previousImageId = null;
var w = null;
function toggleImage(toggledImage, largeImage, smallImage)
{ 
    if (navigator.appName == 'Netscape')
    {
        w = window.open(largeImage,'WebImage','width=600,height=425,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no, top=300, left=300');          
        w.focus();
    }
    else
    {
        if(blownUp == "false")
        { 
            toggledImage.setAttribute("src", largeImage);
            toggledImage.setAttribute("title", "Click here to close!");
            toggledImage.style.position = 'absolute';
            blownUp = "true";
            
            //darkenBackroundOn();
            //document.getElementById('divWait').style.display = 'none';                                 
        }
        else
        {             
            toggledImage.setAttribute("src", smallImage);
            toggledImage.setAttribute("title", "Click here to enlarge!");
            toggledImage.style.position = 'static';        
            blownUp = "false";                               
            //darkenBackroundOFF();
        }
        return blownUp;
    }
    
}