﻿$(document).ready(function () {
    /*$('#mainnav li').each(function() {
    $(this).find('ul').prev().attr('class', 'stub').parent().bind('mouseover', function() {
    var o = $(this);
    if(o.attr('action')) clearTimeout(o.attr('action'));
    o.attr('action', setTimeout(function() { $(o).find('ul:first').css('visibility', 'visible'); }, 400));
    }).bind('mouseout', function() {
    var o = $(this);
    if(o.attr('action')) clearTimeout(o.attr('action'));
    o.attr('action', setTimeout(function() { $(o).find('ul:first').css('visibility', 'hidden'); }, 400));
    });
    });*/

    jQuery.fn.fadeToggle = function (speed, easing, callback) {
        return this.animate({ opacity: 'toggle' }, speed, easing, callback);
    };

    // Select FIRST LEVEL children ONLY, exclude the first child as it's just a link
    $('ul#mainnav > li > a:not(:first, .leave)').click(function (event) {
        event.preventDefault();

        // Remove all classes
        $('ul#mainnav > li > ul').removeClass("selected");

        // Set the class and toggle the selected item
        $(this).parent().find(">ul").addClass("selected").fadeToggle();

        // Hide everything except the selected item
        $('ul#mainnav > li > ul:not(.selected)').hide();
    });

    $('#q').bind('focus', function () { if (this.value == 'Keyword/Product Code') this.value = ''; });
    $('#q').bind('blur', function () { if (this.value == '') this.value = 'Keyword/Product Code'; });
    $('#NewsletterEmail').bind('focus', function () { if (this.value == 'Your email address') this.value = ''; });
    $('#NewsletterEmail').bind('blur', function () { if (this.value == '') this.value = 'Your email address'; });

    $('#newsletterlink').bind('click', function () {
        $('#newsletter').css('top', $(this).position().top - 238);
        return false;
    });
});
