/************************************** 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 -------------------------------------------------------------------------
*       
* Event Handlers --------------------------------------------------------------------
*   quantityMinus_onClick()             // Function to decrease the quantity input value
*   quantityPlus_onClick()              // Function to increase the quantity input value
**************************************************************************************/

/************************************** Includes *************************************/
$.include("/inc/splendid-lib/splendid-utils.js");

/********************************** Global Variables *********************************/
$(document).ready(function() {
    initNavigation();
});

timeout = null;
var preDisplayTimeout;
var preDisplayTimeoutDelay = 600;

/************************************** Functions *************************************/
/****
 * Handles the navigation initialisation 
 ****/
function initNavigation() {
    // Hides drop downs and positions them absolute
    //$("#mainNav ul").css({
    //    "position": "absolute",
    //    "display": "none"
    //});

    // Adds functionality to menu items
	$('#mainNav li.hasLink').hover(
		function() {

			clearTimeout($(this).data('preDisplayTimeout'));
			$(this).data('preDisplayTimeout', null);

			(function(elm) {
				preDisplayTimeout = setTimeout(function() {
					mainNavigation_onHoverOver(elm);
				}, preDisplayTimeoutDelay)
			})(this);

			$(this).data('preDisplayTimeout', preDisplayTimeout);
		},
		function() {
			clearTimeout($(this).data('preDisplayTimeout'));
			$(this).data('preDisplayTimeout', null);
			// On hoverout event
			// There's a short delay before the sub menu needs to be hidden. This sets the timeout details.
			timeout = setTimeout('close("#' + this.id + '")', 400);
		}
	);
}

/****
 * Closes the sub navigation menu that is open
 ****/
function close(e) {
    clearTimeout(timeout);
    timeout = null;
    $(".rolloverTop", e).hide();

    checkForDodgyIE6Elements("visible");
}


/*********************************** Event Handlers ***********************************/

/****
 * 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;
        
        $('#mainNav .rolloverTop').hide();
    }
    $('.rolloverTop', which).show();
    checkForDodgyIE6Elements("hidden");
}


