/*
--------------------------------------------------

3M Cuno
application.js

Joe Morrow [joe.morrow@acquitygroup.com]
11/14/2008

Copyright © 2008 Acquity Group LLC

--------------------------------------------------
*/


$(document).ready(function() {

    $('#print a').click(function() {
        window.print();
        return false;
    });

    // Tab Hovers
    $("#topnav li").hover(function() {
        $(this).addClass("hover");
    }, function() {
        $(this).removeClass("hover");
    });

    $(".menu-box").accordion({
        header: 'a.header',
        event: 'mouseover'
    });

    // Tabbed box navigation
    $("#tabset ul.tabs li a").click(function() {
        $("#tabset ul.tabs li, #tabset .tab-content").removeClass("selected");
        $(this).parent().addClass("selected");
        tabId = $(this).parent().attr("id");
        idNum = tabId.substring(tabId.length - 1);
        tabContentId = "#tabset contentTab" + idNum;
        $("#tabset #contentTab" + idNum).addClass("selected");
        return false;
    });

    // Handles Reference Name field toggling
    // Listens for change events (click on IE) on all <input>s with a ref-toggle class
    // Then grabs the final class on that element, which should be the ID of the <div> containing the Reference Name to show/hide
    $(".ref-toggle").bind((($.browser.msie) ? "click" : "change"), function() {
        var item = $("#" + $(this).attr('class').split(' ').slice(-1));
        ($(this).is(":checked")) ? item.show("fast") : item.hide("fast");
    });

    $("#pay-future-use").click(function(){
        // If checked
        if ($("#pay-future-use").is(":checked")) {
            $("#si-reference-name").show("fast");
        } else {
            $("#si-reference-name").hide("fast");
        }
    });

    // Auto-clearing of inline prompt text
    $("#qs-query, #gc-zip-code").click(function() {
        $(this).removeClass("inline-prompt");

        if ($(this).attr("id") == 'qs-query') {
            promptText = 'Enter Keyword';
        } else if ($(this).attr("id") == 'gc-zip-code') {
            promptText = 'Enter Zip Code';
        }

        if ($(this).val() == promptText) {
            $(this).removeClass("inline-prompt");
            $(this).val('');
        }
    });

    $("#qs-query, #gc-zip-code").blur(function() {

        if ($(this).val() == '') {
            if ($(this).attr("id") == 'qs-query') {
                promptText = 'Enter Keyword';
            } else if ($(this).attr("id") == 'gc-zip-code') {
                promptText = 'Enter Zip Code';
            }

            $(this).val(promptText);
            $(this).addClass("inline-prompt");
        }

    });


    // Switch the main product image
    // This code was inline in the PC04 template and has been relocated here.
    $("#product-image .thumb a img").bind("click", function() {
        var largeSrc = $(this).attr("rell");
        var regSrc = $(this).attr("relr");
        var videoSrc = $(this).attr("relv");
        var videoTitle = $(this).attr("desc");
        if (videoSrc == undefined) {

            // Load the still image
            $("#product-image .still img.main").attr("src", regSrc);
            if (largeSrc == undefined) {
                $("a.zoomButton").hide();
            } else {
                $("a.zoomButton").show();
                var popupSrc = "JavaScript:newPopup('";
                var popupEnd = "', 'height=577,width=756')";
                $("a.zoomButton").attr("href", popupSrc+largeSrc+popupEnd);
            }

            // Hide the video player
            $("#product-image .video:visible").each(function() {
                swfobject.removeSWF("player");
                $(this).addClass("hidden").empty().append('<div id="player"></div>');
                return false;
            });
            $("#product-image .still.hidden").removeClass("hidden");

        } else {

            // Load the video player
            $("#product-image .video.hidden").removeClass("hidden");

            if (videoTitle != undefined) {
            	videoParams = {quality: "high", allowfullscreen: "true", name: videoTitle, title: videoTitle, alt: videoTitle};
            	videoAttributes = {alt: videoTitle, title: videoTitle, name: videoTitle};
            }
            swfobject.embedSWF(videoSrc, "player", videoWidth, videoHeight, "7.0.19.0", "scripts/expressInstall.swf", videoFlashvars, videoParams, videoAttributes);

            // Hide the still image
            $("#product-image .still").not(".hidden").addClass("hidden");
        }

        return false;
    });

    // Preload the video config and player, if necessary
    var videoWidth = 380;
    var videoHeight = 320;
    var videoFlashvars = false;
    var videoParams = {quality: "high", allowfullscreen: "true"};
    var videoAttributes = false;
    $("#product-image .video").not(".hidden").each(function() {
        var videoSrc = $(this).children("#player").attr("relv");
        var videoTitle = $(this).children("#player").attr("desc");
        if (videoTitle != undefined) {
        	videoParams = {quality: "high", allowfullscreen: "true", name: videoTitle, title: videoTitle, alt: videoTitle};
        	videoAttributes = {alt: videoTitle, title: videoTitle, name: videoTitle};
        }
        if (videoSrc != undefined)
            swfobject.embedSWF(videoSrc, "player", videoWidth, videoHeight, "7.0.19.0", "scripts/expressInstall.swf", videoFlashvars, videoParams, videoAttributes);
    });

});
