﻿function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}
function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}


$(document).ready(function () {

    var formWrapper = $("#contestFormWrapper");
    if (formWrapper.length > 0) {
        $('.contestFieldWrapper input', formWrapper).each(function (ix, el) {
            var rel = "";
            switch (el.parentNode.parentNode.id) {
                case 'contestFormFirstNameWrapper':
                    rel = "First Name";
                    break;
                case 'contestFormLastNameWrapper':
                    rel = "Last Name";
                    break;
                case 'contestFormEmailWrapper':
                    rel = "Email Address";
                    break;
            }
            el.rel = rel;
            el = $(el);
            el.css({ color: '#777' });
            el.focus(function () { if (this.value == this.rel) this.value = ""; this.select(); this.style.color = "#000"; });
            el.blur(function () { if (this.value == "") { this.value = this.rel; this.style.color = "#777"; } else { this.style.color = "#000"; } });
            el.blur();
        });
    }

    // hide for articles with more link
    $(".moreContent").hide();

    $(".moreClick").click(function (event) {
        event.preventDefault();
        $(this).next(".moreContent").slideDown(100);
        $(this).hide();
    });

    $(".lessClick").click(function (event) {
        event.preventDefault();
        $(this).parent().parent().find(".moreClick").show();
        $(this).parent().slideUp(100);
    });


    // navigation menu
    $('li.headlink').hover(
	    function () {
	        $(this).children('.sublink').show();
	        $("#topMenus").focus();
	    },
	    function () {
	        $(this).children('.sublink').hide();
	        //$('ul', this).css('display', 'none');
	    });


    // correct photo repeater width on pro staff pages
    var numImages = $('#photoRepeater').children('a').length;
    // image width plus padding
    var imageWidth = 73;
    $('#photoRepeater').css('width', numImages * imageWidth);


    // product detail tabs
    //if this is not the first tab, hide it
    $(".tab:not(:first)").hide();

    //to fix u know who
    $(".tab:first").show();
    $(".tab:first").addClass("tab_on");

    $(".htabs a:first span").addClass("tab_on");

    //when we click one of the tabs
    $(".htabs a").click(function () {
        $(".htabs a span").removeClass("tab_on");
        $(this).children("span").addClass("tab_on");
        //$(this).addClass("tab_on");

        //get the ID of the element we need to show
        stringref = $(this).attr("href").split('#')[1];
        //hide the tabs that doesn't match the ID
        $('.tab:not(#' + stringref + ')').hide();
        //fix
        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            $('.tab#' + stringref).show();
        }
        else
        //display our tab fading it in
            $('.tab#' + stringref).fadeIn();
        //stay with me
        return false;
    });

    // fix product detail tabs fill
    var totalItemsWidth = 0;

    var searchClass;

    if ($(".htabs").length > 0) { searchClass = ".htabs"; }
    if ($(".otabs").length > 0) { searchClass = ".otabs"; }

    $(searchClass).children("li:not(.fill)").each(function () {
        totalItemsWidth += $(this).width();
    });

    var parentwidth;
    parentwidth = $(searchClass).parent().width();

    $(".fill").width(parentwidth - totalItemsWidth - 25);

    $("a.more").click(function () {
        //get the ID of the element we need to show
        stringref = $(this).attr("href").split('#')[1];
        $(searchClass + " a span").removeClass("tab_on");
        $(searchClass + " li a#_" + stringref + " span").addClass("tab_on");

        //hide the tabs that doesn't match the ID
        $('.tab:not(#' + stringref + ')').hide();
        //fix
        if (jQuery.browser.msie && jQuery.browser.version.substr(0, 3) == "6.0") {
            $('.tab#' + stringref).show();
        }
        else
        //display our tab fading it in
            $('.tab#' + stringref).fadeIn();
    });


    //Initialize search textbox events
    var el = $('input.search');

    if (el) {
        var searchDefaultText = 'Search';
        el.val((el.val() == '') ? searchDefaultText : el.val());
        el.focus(function (e) {
            if (el.val() == searchDefaultText)
                el.val('');
        });

        el.blur(function (e) {
            if (el.val() == '')
                el.val(searchDefaultText);
        });
    }
});
