﻿$(document).ready(function() {

    function megaHoverOverCompany() {
         if ($(this).find(".subCompany")) {
            $(this).find(".subCompany").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
            (function($) {
                //Function to calculate total width of all ul's
                jQuery.fn.calcSubWidth = function() {
                    rowWidth = 0;
                    //Calculate row
                    $(this).find("ul").each(function() { //for each ul...
                        rowWidth += $(this).width(); //Add each ul's width together
                    });
                };
            })(jQuery);
        }
    }
    function megaHoverOverInnovation() {
        if ($(this).find(".subInnovation")) {
            $(this).find(".subInnovation").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
            (function($) {
                //Function to calculate total width of all ul's
                jQuery.fn.calcSubWidth = function() {
                    rowWidth = 0;
                    //Calculate row
                    $(this).find("ul").each(function() { //for each ul...
                        rowWidth += $(this).width(); //Add each ul's width together
                    });
                };
            })(jQuery);
        }
    }
    function megaHoverOver() {
        if ($(this).find(".sub")) {
            $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
            (function($) {
                //Function to calculate total width of all ul's
                jQuery.fn.calcSubWidth = function() {
                    rowWidth = 0;
                    //Calculate row
                    $(this).find("ul").each(function() { //for each ul...
                        rowWidth += $(this).width(); //Add each ul's width together
                    });
                };
            })(jQuery);
        }
    }
    //On Hover Out
    function megaHoverOutCompany() {

        if ($(this).find(".subCompany")) {
            $(this).find(".subCompany").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
                $(this).hide();  //after fading, hide it
            });
        }
    }
    function megaHoverOutInnovation() {

        if ($(this).find(".subInnovation")) {
            $(this).find(".subInnovation").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
                $(this).hide();  //after fading, hide it
            });
        }
    }
    function megaHoverOut() {

            if ($(this).find(".sub")) {
            $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
                $(this).hide();  //after fading, hide it
            });
        }
    }
    var config = {
        sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
        interval: 5, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 400, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

    var configCompany = {
        sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
        interval: 5, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOverCompany, // function = onMouseOver callback (REQUIRED)
        timeout: 400, // number = milliseconds delay before onMouseOut
        out: megaHoverOutCompany // function = onMouseOut callback (REQUIRED)
    };

    var configInnovation = {
        sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
        interval: 5, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOverInnovation, // function = onMouseOver callback (REQUIRED)
        timeout: 400, // number = milliseconds delay before onMouseOut
        out: megaHoverOutInnovation // function = onMouseOut callback (REQUIRED)
    };
    
    $("ul#topnav li .sub").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    $("ul#topnav li .subCompany").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    $("ul#topnav li .subInnovation").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    $("ul#topnav li").hoverIntent(config); //Trigger Hover intent with custom configurations
    $("ul#topnav .company li").hoverIntent(configCompany); //Trigger Hover intent with custom configurations
    $("ul#topnav .innovation li").hoverIntent(configInnovation); //Trigger Hover intent with custom configurations
    //     $("ul#topnav li").hover(function() { //Hover over event on list item
    //		$(this).css({ 'background' : '#666666 repeat-x'}); //Add background color on hovered list item
    //		$(this).css({ 'background' : '-moz-linear-gradient(top, #CCCCCC, #666666)'}); //Add background color on hovered list item
    //		$(this).css({ 'background' : '-webkit-gradient(linear, left top, left bottom, from(#CCCCCC), to(#666666))'}); //Add background color on hovered list item
    //		$(this).css({ 'font-weight' : 'bold'}); //Add font-weight on hovered list item
    //		$(this).find("span").show(); //Show the subnav
    //	} , function() { //on hover out...
    //		$(this).css({ 'background' : 'none'}); //Ditch the background
    //		$(this).css({ 'font-weight' : 'normal'}); //Add font-weight on hovered list item
    //		$(this).find("span").hide(); //Hide the subnav
    //	});

//    $("#bottomnav li").prepend("<span></span>"); //Throws an empty span tag right before the a tag

//    $("#bottomnav li").each(function() { //For each list item...
//        var linkText = $(this).find("a").html(); //Find the text inside of the <a> tag
//        $(this).find("span").show().html(linkText); //Add the text in the <span> tag
//    });

//    $("#bottomnav li").hover(function() {	//On hover...
//        $(this).find("span").stop().animate({
//            marginTop: "-30" //Find the <span> tag and move it up 40 pixels
//        }, 5);
//    }, function() { //On hover out...
//        $(this).find("span").stop().animate({
//            marginTop: "0"  //Move the <span> back to its original state (0px)
//        }, 400);
//    });


});
