// Header Drop down menu
$(document).ready(function() {

    //======= updated dropdown menu 8/20 ==================
    $("#topMenu li ul").hide();
    $("#topMenu li").hover(
        function() {
            $(this).children("ul").show();
            $(this).children("a").addClass("on");
        }, function() {
            $(this).children("a").removeClass("on");
            $(this).children("ul").hide();
    });
    //======= Header drop down menu ==================

    $("#divHeaderMenu li").hover(function() {
        var gettab = $(this).attr("tablink");
        if ($(this).attr("tablink")) {
            $("#divHeaderMenu li").removeClass("ui-ddHeaderProdBg").removeClass("ui-ddHeaderLiveWellBg").removeClass("ui-ddHeaderAboutBg");
            $(this).addClass(gettab);
            $(this).find('img').attr("src", '/images/spacer.gif');
            $("#divHeaderMenu li").find('ul').hide();
            var tabHtml = $("a", this).attr("alttxt");
            $('ul:first', this).show();
        }
        if (typeof ($(this).attr("tablink") == undefined)) {
            var imagePath = $('img', this).attr("src").replace("Default.png", "Active.png");
            $("img", this).attr("src", imagePath);
        }

    }, function() {
        if ($(this).attr("tablink")) {
            $("#divHeaderMenu li").removeClass("ui-ddHeaderProdBg").removeClass("ui-ddHeaderLiveWellBg").removeClass("ui-ddHeaderAboutBg");
            var imghtml = $(this).find('img').attr('dynsrc');
            $(this).find('img').attr('src', imghtml);
        }
        if (typeof ($(this).attr("tablink") == undefined)) {
            var imagePath = $('img', this).attr("src").replace("Active.png", "Default.png");
            $("img", this).attr("src", imagePath);
        }
        $('ul:first', this).hide();
        if ($.browser.msie) { $(this).find('ul').hide(0); return false; }

    });


    $("#divHeaderMenu li").click(function() {
        var pathname = $("a", this).attr("href");
        location.href = pathname;
    });


    //======= text box focus and blur js ==================
    $("input").filter('[txttype=zipCode]').focus(function() {
        var defaulttxt = $(this).attr("txt");
        if ($(this).val() == defaulttxt) {
            $(this).val('');
        }
    });
    $("input").filter('[txttype=zipCode]').blur(function() {
        var defaulttxt = $(this).attr("txt");
        if ($(this).val() == '') {
            $(this).val(defaulttxt);
        }
    });

    //======= Footer height js ==================
    var winheight = $(document).height();
    var getDocHeight = $(".ui-pageContainter").css("height");
    contareaHeight = winheight - parseInt(getDocHeight);
    $(".ui-FooterArea").height(contareaHeight);


    //======= Product page js ==================
    $(".330mL,#330mL").mouseover(function() { $("#330mL").addClass('productTiphover'); });
    $(".330mL,#330mL").mouseout(function() { $("#330mL").removeClass('productTiphover'); });
    $(".500mL,#500mL").mouseover(function() { $("#500mL").addClass('productTiphover'); });
    $(".500mL,#500mL").mouseout(function() { $("#500mL").removeClass('productTiphover'); });
    $(".710mL,#710mL").mouseover(function() { $("#710mL").addClass('productTiphover'); });
    $(".710mL,#710mL").mouseout(function() { $("#710mL").removeClass('productTiphover'); });
    $(".1L,#1L").mouseover(function() { $("#1L").addClass('productTiphover'); });
    $(".1L,#1L").mouseout(function() { $("#1L").removeClass('productTiphover'); });
    $(".1halfL,#1halfL").mouseover(function() { $("#1halfL").addClass('productTiphover'); });
    $(".1halfL,#1halfL").mouseout(function() { $("#1halfL").removeClass('productTiphover'); });
    $(".3L,#3L").mouseover(function() { $("#3L").addClass('productTiphover'); });
    $(".3L,#3L").mouseout(function() { $("#3L").removeClass('productTiphover'); });

    $(".viewNutritionalFacts").click(function() { $("#popUpwindow").show(); $("#facts").show(); });
    $(".factsClose").click(function() { $("#popUpwindow").hide(); $("#facts").hide(); });


    //======= Quiz js =================='

    $(".questionDiv").hide();

    $(".startQuizDiv a").click(function() {
        $(this).hide();
        $("#question_1").show();
    });

    $(".questionDiv a").click(function() {
        var rightAnswer = $(this).attr('QValue');
        if (rightAnswer == 'true') {
            $(".questionDiv p").slideUp(1000);
            $(this).parent().parent().find('p').slideDown(1000);
            $(this).parent().parent().find('.nextbtnBox').show();
            $(this).parent().parent().find(".trueBtnDiv").hide();
            $(this).parent().parent().find(".incorrectDiv").hide();
        } else {
            $(".incorrectDiv").slideDown(); $('.nextbtnBox').hide();
        }
    });

    $(".btnNext").click(function() {
        var currentId = $(this).parent().parent().attr('id');
        var idNumber = currentId.charAt(9);
        var getlength = $(".questionDiv").length;
        var newId = parseInt(idNumber) + 1;
        $(this).parent().parent().hide();
        $(".incorrectDiv").hide();
        $("#question_" + newId).slideDown();

        if (newId >= 6) {
            $(".questionsContainer").hide();
            $(".congartesDiv").slideDown(1000);
        }
    });

    $(".print").click(function() {
        PrintDiv();
    });

    function PrintDiv() {
        var divToPrint = document.getElementById('hydartionPageDiv');
        var popupWin = window.open('', '_blank', 'width=600,height=300');
        popupWin.document.open();
        popupWin.document.write('<html ><head><link rel="stylesheet" href="/sp/Content/printStyle.css"  type="text/css" /></head><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
        popupWin.document.close();
    }

    //======= Games Pop up window  js =================='

    $(".gamewindow").click(function() {
        $(".gamingPopupDiv iframe").attr('src', '');
        $(".gamingPopupDiv iframe").attr('width', '');
        $(".gamingPopupDiv iframe").attr('height', '');

        var URL = $(this).attr('theURL');
        var wWidth = $(this).attr('winWidth');
        var wHeight = $(this).attr('winHeight');
        var windHeight = $(document).height();
        var winWidth = $(window).width() - wWidth;
        var setLeft = winWidth / 2;

        $("#gamingOverlayDiv").height(windHeight);
        $(".gamingPopupDiv").css('width', wWidth);
        $("#gamingContainer").css('margin-left', setLeft);
        $(".gamingPopupDiv").show();
        $("#gamingOverlayDiv").show();
        $(".gamingPopupDiv iframe").attr('src', URL);
        $(".gamingPopupDiv iframe").attr('width', wWidth);
        $(".gamingPopupDiv iframe").attr('height', wHeight);
        return false;
    });

    $("#closegamingDiv").click(function() {
        $("#gamingOverlayDiv").hide();
        $(".gamingPopupDiv").hide();
    });
});
