/************************************** Splendid *************************************
* Created By:		Steve Doggett
* Creation Date:	22nd July 2009
* Edited ----------------------------------------------------------------------------
*      By:              On:  
* Description -----------------------------------------------------------------------
*      This file handles the main navigation drop downs
*      Uses JQuery.
*      Example in all pages
*
* Functions -------------------------------------------------------------------------
*   initNavigation()             	// Handles the navigation initialisation 
*       
* Event Handlers --------------------------------------------------------------------
*   close()              		 	// Closes the sub navigation menu that is open
*   mainNavigation_onHoverOver()	// Handles the hoverover event for the main navigation
*
**************************************************************************************/


/********************************** Global Variables *********************************/
$(document).ready(function() {
    initNavigation();
});

timeout = null;

/************************************** Functions *************************************/
/****
 * Handles the navigation initialisation 
 ****/
function initNavigation() {
    // Hides drop downs and positions them absolute
    $(".dropDownMenu").css({
        "position": "absolute",
        "display": "none"
    });

    // Adds functionality to menu items
    $('.menu li').hover(
		function() {
		    // on hover over event
		    mainNavigation_onHoverOver(this);
		},
		function() {
		    // On hover out event
		    // There's a short delay before the sub menu needs to be hidden. This sets the timeout details.
		    timeout = setTimeout(close, 400);
		}
	);
}



/*********************************** Event Handlers ***********************************/

/****
 * Closes the sub navigation menu that is open
 ****/
function close() {
    clearTimeout(timeout);
    timeout = null;
    $(".dropDownMenu").fadeOut("fast");

    checkForDodgyIE6Elements("visible");
}

/****
 * Handles the hoverover event for the main navigation
 * Shows the sub navigation for the chosen area.
 ****/
function mainNavigation_onHoverOver(which) {
    if (timeout != null) {
        clearTimeout(timeout);
        timeout = null;
        
        $('.dropDownMenu').fadeOut("fast");
    }
    $('.dropDownMenu', which).fadeIn("fast");
    checkForDodgyIE6Elements("hidden");
}


