﻿
// Check that the page has loaded
$(document).ready(function () {

    // Show newletter categories
    $('.newsletterAgree INPUT').change(function () {
        if ($(this).is(':checked')) {
            $('.newsletterCats').show();
        }
        else {
            $('.newsletterCats').hide();
        }
    });

    // Big target for productList
    $(".productList .product .title A").bigTarget({
        clickZone: '.product' // jQuery parent selector
    });
    $('.product').css({ 'cursor': 'pointer' });

    // PRODUCT GALLERY

    // Select first image as default
    $('.productGallery .thumbnails A:first').append('<div class="selected"></div>')

    // Rollover hightlight
    $('.productGallery .thumbnails A').hover(

    // mouseover
        function () {
            $(this).append('<div class="rollover"></div>');
        },

    // mouseout
        function () {
            $(this).find('.rollover').remove();
        }

    );

    // Thumbnail click
    //    $('.productGallery .thumbnails A').click(function () {

    //        // Remove previous selected highlight
    //        $('.productGallery .thumbnails A').find('.selected').remove();

    //        // Add selected to correct thumbnail
    //        $(this).append('<div class="selected"></div>');

    //        // Change image
    //        $('.productGallery .mainImg IMG').attr('src', $(this).attr('href'));

    //        return false;

    //    });

    // Thumbnail click
    $('.productGallery .thumbnails A').click(function () {

        $('.productGallery .thumbnails A').find('.selected').remove();
        $(this).append('<div class="selected"></div>');

        //Get the index of the thumbnail
        var index = $(".productGallery .thumbnails A").index(this);

        //Get the src of the main image (the medium sized image)
        var imgSrc = $(this).attr('href');

        //Remove the currently displayed main image
        $('.mainImg A IMG').remove();

        //Get the main image with the matching index and append an image with the src from the thumbnail
        var matchingA = $('.mainImg A').eq(index);

        $(matchingA).append('<img src="' + imgSrc + '" />');

        $('.mainImg A IMG').bind('load', function () {
            var h = $(matchingA).children('IMG').height() + 10;

            $('.mainImg').animate({
                height: h
            }, 250, function () {

                $(matchingA).children('IMG').fadeIn('fast');

            });
        });

        return false;

    });

    if ($('.productGallery .thumbnails A').length != 0) {
        $('.productGallery .thumbnails A').eq(0).click();
    }

    $('.specialOffer').hover(function () {

        $(this).children('.info').slideDown('fast');

    }, function () {

        $(this).children('.info').stop(true, true).slideUp('fast');
    
    });

    //// Login

    // Clear login box when focused
    $('.login_email').focus(function () {
        if ($(this).val() == "Email Address") {
            $(this).val('');
        }
    });
    $('.login_email').blur(function () {
        if ($(this).val() == "") {
            $(this).val('Email Address');
        }
    });
    $('.login_email').live('click', function () {
        if ($(this).val() == "Email Address") {
            $(this).val('');
        }
    });

    // Hide fake password box and show real one on focus
    $('.login_password').focus(function () {
        $(this).hide();
        $('.login_passwordReal').show()
        $('.login_passwordReal').focus();
    });

    //Fix google toobar autocomplete
    var timer;

    for (var count = 0; count < 20; count++) {
        setTimeout("resetInputs()", 50 * count);
    }
    timer = setInterval("resetInputs()", 250);

    $('.fancybox').fancybox({
        padding: 20,
        overlayColor: '#0d1e39',
        overlayOpacity: 0.85
    });
});

function resetInputs() {
   $('#mainCol input[type=text]').css("background-color", "#ffffff");
   $('#mainCol input[type=password]').css("background-color", "#ffffff");
   $('#mainCol select').css("background-color", "#ffffff");
}

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');
        }
    }
}
