﻿
// 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;

    });

    //// 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);
});

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');
        }
    }
}