// 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();
	});

	//======= open / close functionality used for safety cap info ==================
	$('.btnOpen').click(function() {
	    $(this).parent("div").addClass('open').removeClass('close');
	});
	$('.btnClose').click(function() {
	    $(this).parent("div").parent("div").addClass('close').removeClass('open');
	});
	
    //======= 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 ==================
    $(".8oz,#8oz").mouseover(function() { $("#8oz").addClass('productTiphover'); });
    $(".500ml,#500ml").mouseover(function() { $("#500ml").addClass('productTiphover'); });
    $(".700ml-sport,#700ml-sport").mouseover(function() { $("#700ml-sport").addClass('productTiphover'); });
    $(".700ml,#700ml").mouseover(function() { $("#700ml").addClass('productTiphover'); });
    $(".20oz,#20oz").mouseover(function() { $("#20oz").addClass('productTiphover'); });
    $(".3lt,#3lt").mouseover(function() { $("#3lt").addClass('productTiphover'); });

    $(".8oz,#8oz").mouseout(function() { $("#8oz").removeClass('productTiphover'); });
    $(".500ml,#500ml").mouseout(function() { $("#500ml").removeClass('productTiphover'); });
    $(".700ml,#700ml").mouseout(function() { $("#700ml").removeClass('productTiphover'); });
    $(".700ml-sport,#700ml-sport").mouseout(function() { $("#700ml-sport").removeClass('productTiphover'); });
    $(".20oz,#20oz").mouseout(function() { $("#20oz").removeClass('productTiphover'); });
    $(".1g, #1g").mouseout(function() { $("#1g").removeClass('productTiphover'); });

    $(".1g,#1g").mouseover(function() { $("#1g").addClass('productTiphover'); });
    $(".3lt,#3lt").mouseover(function() { $("#3lt").addClass('productTiphover'); });
    $(".25lt,#25lt").mouseover(function() { $("#25lt").addClass('productTiphover'); });
    $(".35g,#35g").mouseover(function() { $("#35g").addClass('productTiphover'); });

    $(".3lt,#3lt").mouseout(function() { $("#3lt").removeClass('productTiphover'); });
    $(".25lt,#25lt").mouseout(function() { $("#25lt").removeClass('productTiphover'); });
    $(".35g,#35g").mouseout(function() { $("#35g").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="/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();
    });

});
