/**
*   File: dropdown.js
*   Creator: Edward Boot (www.pghwebs.com)
*   Created: March 8, 2010
*   Revised: March 8, 2010
*   Purpose:
*   This file creates drop down menu links on a website using an HTML list.
*   It is cross browser compatible and uses a series of hover on's and off's
*   to hide the links in a spedified matter.
*
*   LICENSE:
*   This file may NOT BE REDISTRIBUTED OR COPIED IN ANY WAY. Any similar
*   duplication or alteration of this script will result in punishment by law
*   of the accused.
*/

var count = 0;              // Used to count seconds
var time_nav;               // Used with the timeout function
var nav_timer_is_on = 0;    // Used to determine if the timer is started
var highlighted = false;    // Determines if a submenu link is highlighted
var masterElement = '';     // The master element stores the ID of the menu
var activateTimer = false;  // Used to shut the timer after the mouse leaves
var previousLink = null;    // The previous menu highlighted

/** Infinite timer that is used to keep objects on the screen for a specified
* amount of time after the mouse has left the primary link. */
function timedNavigationCount()
{
    if (activateTimer)
    {
        // Show the navigation item for two seconds
        count =count + 1;
        if (count >= 2)
        {
            // If two seconds passed hide the menu
            menu = document.getElementById(masterElement);
            menu.style.display = 'none';
            count = 0;
            activateTimer = false;
        }
    }
    // Set the timeout for two seconds, 1000 milliseconds in seconds
    time_nav = setTimeout("timedNavigationCount()",400);
}

/** The actual function called to start the timer. */
function menuTimer(element)
{
  //Set the master element
  masterElement = element;

  // Start the timer processing
    if (!nav_timer_is_on)
    {
        nav_timer_is_on = 1;
        timedNavigationCount();
    }
}

/** This function displays a hidden drop down menu and all of it's links and
* parameters.
* @param element the HTML ID of the dropdown item. */
function display_dropdown(element)
{
    // Before anything, determine if another menu was opened
    if(previousLink != null)
    {
        if (previousLink == element)
        {
            // We are on the same menu
            // Get the element ID
            menu = document.getElementById(element);

            // Disable the timer if it was running
            activateTimer = false;

            // Show the drop down menu
            menu.style.display = 'block';
        }
        else
        {
            // We are on a new menu, hide the old one
            document.getElementById(previousLink).style.display = 'none';

            // Get the element ID
            menu = document.getElementById(element);

            // Disable the timer if it was running
             activateTimer = false;

            // Show the drop down menu
            menu.style.display = 'block';
        }
    }
    else
    {
        // First time on any links, act normal
        // Get the element ID
        menu = document.getElementById(element);

        // Disable the timer if it was running
        activateTimer = false;

        // Show the drop down menu
        menu.style.display = 'block';
    }

    // Set the pervious link variable
    previousLink = element;
}

/** This method hides a dropdown menu.
* @param elmeent the HTML ID of the element being hidden. */
function hide_dropdown(element)
{
    // Get the element ID
    menu = document.getElementById(element);

    // Activate the timer
    activateTimer = true;

    // Hide the drop down menu ater so many seconds
    menuTimer(element);
}
