﻿
// Check that the page has loaded
$(document).ready(function() {

    var timer;

    for (var count = 0; count < 20; count++) {
        setTimeout("resetInputs()", 50 * count);
    }
    timer = setInterval("resetInputs()", 250);

    // MAIN NAV GRAPHIC EQUALIZER

    // Starting state - selected +/- one item
    $('.mainNav .selected').prev('.mainNavItem').find('.mainNavOverlay').css({
        height: "11px",
        backgroundColor: '#48649a'
    });
    $('.mainNav .selected').next('.mainNavItem').find('.mainNavOverlay').css({
        height: "11px",
        backgroundColor: '#48649a'
    });

    // Animate current +/- one item
    $('.mainNav .mainNavItem A').mouseenter(

    // Mouseover
        function() {

            // Dequeue animations
            $('.mainNav .mainNavItem .mainNavOverlay').dequeue();

            // Animate this overlay to full height
            $(this).next('.mainNavOverlay').animate({
                height: "23px",
                backgroundColor: '#839bc2'
            }, 200);

            // Animate previous overlay to half height
            $(this).parent('.mainNavItem').prev('.mainNavItem').find('.mainNavOverlay').animate({
                height: "11px",
                backgroundColor: '#48649a'
            }, 200);

            // Animate next overlay to half height
            $(this).parent('.mainNavItem').next('.mainNavItem').find('.mainNavOverlay').animate({
                height: "11px",
                backgroundColor: '#48649a'
            }, 200);

            // Animate all other overlays to min height
            $('.mainNav .mainNavItem .mainNavOverlay')
                .not($(this).next('.mainNavOverlay')) // Dont animate current
                .not($(this).parent('.mainNavItem').prev('.mainNavItem').find('.mainNavOverlay')) // Dont animate previous
                .not($(this).parent('.mainNavItem').next('.mainNavItem').find('.mainNavOverlay')).css({ backgroundColor: '#314f8b' }) // Dont animate next
                .animate({
                    height: "6px"
                }, 0);

        }

    );


    // Animate selected when mouseout
    $('.mainNav').mouseleave(

    // Mouseover
        function() {

            // Animate this overlay to full height
            $('.mainNav .selected').find('.mainNavOverlay').animate({ opacity: 1.0 }, 200).dequeue().animate({
                height: "23px",
                backgroundColor: '#839bc2'
            }, 300);

            // Animate previous overlay to half height
            $('.mainNav .selected').prev('.mainNavItem').find('.mainNavOverlay').animate({ opacity: 1.0 }, 200).dequeue().animate({
                height: "11px",
                backgroundColor: '#48649a'
            }, 300);

            // Animate next overlay to half height
            $('.mainNav .selected').next('.mainNavItem').find('.mainNavOverlay').animate({ opacity: 1.0 }, 200).dequeue().animate({
                height: "11px",
                backgroundColor: '#48649a'
            }, 300);

            // Animate all other overlays to min height
            $('.mainNav .mainNavItem .mainNavOverlay')
                .not($('.mainNav .selected').find('.mainNavOverlay')) // Dont animate current
                .not($('.mainNav .selected').prev('.mainNavItem').find('.mainNavOverlay')) // Dont animate previous
                .not($('.mainNav .selected').next('.mainNavItem').find('.mainNavOverlay')) // Dont animate next
                .animate({ opacity: 1.0 }, 200).dequeue().animate({
                    height: "6px",
                    backgroundColor: '#314f8b'
                }, 200).css({
                    height: "6px",
                    backgroundColor: '#314f8b'
                });
        }

    );

    // SEARCH TABS

    // Hide Karaoke discs search by default
    $('#karaokeDiscsSearch').hide();

    // Show correct form and tab layout when clicked
    $('#productsSearchTab').click(function() {

        $('#search #searchTabs').css({ backgroundPosition: '0 -37px' });
        $('#karaokeDiscsSearch').hide();
        $('#productsSearch').show();

        return false;
    });
    
    // Show explanation when manufacturer is chosen
    $('.drop_manufacturer').change(function() {
        $('#explanation').show();
    });

    // Show correct form and tab layout when clicked
    $('#karaokeDiscsSearchTab').click(function() {

        $('#search #searchTabs').css({ backgroundPosition: '0 0' });
        $('#productsSearch').hide();
        $('#karaokeDiscsSearch').show();

        return false;
    });

    if (location.href.indexOf("karaoke") > 0 || location.href.toLowerCase().indexOf("discdetails") > 0 || location.href.toLowerCase().indexOf("packdetails") > 0) {
        $('#search #searchTabs').css({ backgroundPosition: '0 0' });
        $('#productsSearch').hide();
        $('#karaokeDiscsSearch').show();
    }

    $('.clearWhenClicked').live('click', function() {
        if ($(this).val() == "Track Title" || $(this).val() == "Artist" || $(this).val() == "Disc Code" ) {
            $(this).data('originalValue',$(this).val());
            $(this).val('');
        }
    });
    
    $('.clearWhenClicked').blur(function() {
        if ($(this).val() == "" ) {
            $(this).val($(this).data('originalValue'));
        }
    });

    // PRODUCT GALLERY

    // Remove margin for last Thumbnail
    $('.productGallery .thumbnails .thumbnail:last').css({ margin: '0' });

    // Load correct image on click
    $('.productGallery .thumbnails .thumbnail A').click(function() {

        var imgURL = $(this).attr('href');

        $('.productGallery .mainImg IMG').attr('src', imgURL);
        $('.productGallery .mainImg A').attr('href', imgURL.replace("img4", "img1"));

        return false;

    });

    // Lightbox
    $('.productGallery .mainImg A').lightBox();

    // Big target for related items
    $(".relatedProduct .thumbnail A").bigTarget({
        clickZone: '.relatedProduct' // jQuery parent selector
    });
    $('.relatedProduct').css({ 'cursor': 'pointer' });


    // DISC LISTING ROW STRIPING
    $('.discListing .discListingMiddle .row:odd').css({ backgroundColor: '#f1f6ff' });
    $('.discListing .discListingMiddle .row:odd .column5 A').css({ backgroundImage: 'url(i/discInfoArrow_white.gif)' });


    // Clear login box when focused
    $('.login_email').focus(function() {
        if ($(this).val() == "Your Email Address") {
            $(this).val('');
        }
    });
    $('.login_email').blur(function() {
        if ($(this).val() == "") {
            $(this).val('Your Email Address');
        }
    });
    $('.login_email').live('click', function() {
        if ($(this).val() == "Your Email Address") {
            $(this).val('');
        }
    });

    // Services
    $('.content_selector a.studio').click(function() {
        $('#studio_information').show();
        $('.content_selector .studio').css("background", "url(/i/studio_ON.gif)");
        $('.content_selector .installations').css("background", "url(/i/installations_OFF.gif)");
        $('#installations_information').hide();
        return false;
    });

    $('.content_selector a.installations').click(function() {
        $('#installations_information').show();
        $('.content_selector .studio').css("background", "url(/i/studio_OFF.gif)");
        $('.content_selector .installations').css("background", "url(/i/installations_ON.gif)");

        $('#studio_information').hide();
        return false;
    });

    $('.faq .question').toggle(function() {
        $(this).find('p').show('fast')
        $(this).css('background-image', 'url(/i/FaqLev1On.gif)');
    }, function() {
        $(this).find('p').hide('fast')
        $(this).css('background-image', 'url(/i/FaqLev1Off.gif)');

    }
    );

    // Open close subcats
    $('.subCatClosed').parent().click(function(){
        if ($(this).find('.subCatClosed').html() == "+") {
            if ($('body').is('.browserIE7') || $('body').is('.browserIE7')) {
                $(this).next().show();
            }
            else {
                $(this).next().slideDown('fast');
            }
            $(this).find('.subCatClosed').html("-")
        }
        else {
            if ($('body').is('.browserIE7') || $('body').is('.browserIE7')) {
                $(this).next().hide();
            }
            else {
                $(this).next().slideUp('fast');
            }
            $(this).find('.subCatClosed').html("+")
        }
        return false;
    });

});

function resetInputs(){
    $('input[type=text]').css("background-color", "#f1f6ff");
    $('input[type=password]').css("background-color", "#f1f6ff");
}

function clear_checkboxes(myID) {
    var frm = document.forms[0];
    for (i = 0; i < frm.length; i++) {
        if (frm.elements[i].id != myID) {
            frm.elements[i].checked = false;
            $('input').next().removeClass('selected');
        }
    }
}