$(document).ready(function() {

    // Optional message for form fields
    // --------------------------------
    $(".OptionalInput").each(function() {
        $(this).val($(this).attr("title"));
        $(this).css({ color: "#999999" });
    });

    $(".OptionalInput").focus(function() {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            $(this).css({ color: "#666666" });
        }

    }).blur(function() {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
            $(this).css({ color: "#999999" });
        }
    });

    // Popular Products Links
    // --------------------------------
    $(".PopularProducts li a img").hover(function() {
        $(this).parent().siblings().addClass("Hover");
    }, function() {
        $(this).parent().siblings().removeClass("Hover");
    });


    // Sub-Category Rollover
    // --------------------------------
    $(".SubCategory").mouseenter(function() {
        $(this).children(".Inner").html($(this).children(".Outer").html());
        $(this).children(".Inner").show();
    }).mouseleave(function() {
        $(this).children(".Inner").html("");
        $(this).children(".Inner").hide();
    });


    // Responsive JS Check
    // --------------------------------
    function setResponsiveJS() {
        var zNum = $("#Responsive").height();

        if (zNum == "1") {
            //full
            $('.fb_iframe_widget iframe').width('400');
            $('.fb_iframe_widget iframe').height('29');
            
            //Order Summary
            $('#Receipt td.Totals').attr('colspan',2);
            $('#Receipt td.Totals.Last').attr('colspan',1);
            $('#Receipt tr#GrandTotalRow td').attr('colspan',2);
            $('#Receipt tr#GrandTotalRow td.Last').attr('colspan',1);
        }
        else if (zNum == "2") {
            //tablet
            $('.fb_iframe_widget iframe').width('330');
            $('.fb_iframe_widget iframe').height('40');
            
            //Order Summary
            $('#Receipt td.Totals').attr('colspan',2);
            $('#Receipt td.Totals.Last').attr('colspan',1);
            $('#Receipt tr#GrandTotalRow td').attr('colspan',2);
            $('#Receipt tr#GrandTotalRow td.Last').attr('colspan',1);
        }
        else if (zNum == "3") {
            //landscape
            $('.fb_iframe_widget iframe').width('440');
            $('.fb_iframe_widget iframe').height('29');
            
            //Order Summary
            $('#Receipt td.Totals').attr('colspan',2);
            $('#Receipt td.Totals.Last').attr('colspan',1);
            $('#Receipt tr#GrandTotalRow td').attr('colspan',2);
            $('#Receipt tr#GrandTotalRow td.Last').attr('colspan',1);
        }
        else if (zNum == "4") {
            //portrait
            $('.fb_iframe_widget iframe').width('280');
            $('.fb_iframe_widget iframe').height('40');
            
            //Order Summary
            $('#Receipt td.Totals').attr('colspan',4);
            $('#Receipt td.Totals.Last').attr('colspan',1);
            $('#Receipt tr#GrandTotalRow td').attr('colspan',4);
            $('#Receipt tr#GrandTotalRow td.Last').attr('colspan',1);
        }
    }

    $(window).resize(function() {
        setResponsiveJS();
    });

    $(window).load(function() {
        setResponsiveJS();
    });
});
