﻿/************************************** 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("js/splendid-lib/splendid-utils.js");

/********************************** Global Variables *********************************/
$(document).ready(function() {
    initNavigation();
});

timeout = null;

/************************************** 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() {
		    // on hoveover event
		    mainNavigation_onHoverOver(this);
		},
		function() {
		    // 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;
    $("ul", e).fadeOut("fast");

    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 ul').fadeOut("fast");
    }
    $('ul', which).fadeIn("fast");
    checkForDodgyIE6Elements("hidden");
}

