/**
* Form Styles and Descriptions
*
* @package js
* @author Tim Carr
* @version 1
* @copyright n7 Studios 2009
*/ 
$(document).ready(function() {
    // Default strings
    var search = "Enter author, title or ISBN";
    
    // Search: as Javascript is enabled and the search box contains the default string, change colour
    if ($('input[name=search]').length > 0 && $('input[name=search]').val() == search) {
        $('input[name=search]').addClass('description');
    }
    
    // Search: remove description class on focus
    $('input[name=search]').bind('focus', function(e) {
        if ($(this).val() == search) {
            $(this).val('');
            $(this).removeClass('description');   
        }
    });
            
    // Search: reinstate default text and description class on blur
    $('input[name=search]').bind("blur", function(e) {
        if ($(this).val() == '') {
            $(this).val(search);
            $(this).addClass('description');    
        }
    });
    
    // Newsletter: as Javascript is enabled and the search box contains the default string, change colour
    // Only applies to newsletter page, not inline popup (see popup.js)
    if ($('input[name=name]').length > 0 && $('input[name=name]').val() == 'Your Name') {
        $('input[name=name]').addClass('description');
    }
    if ($('input[name=from]').length > 0 && $('input[name=from]').val() == 'Your Email Address') {
        $('input[name=from]').addClass('description');
    }
    
    // Newsletter: remove description class on focus
    $('input[name=name]').live('focus', function(e) {
        if ($(this).val() == 'Your Name') {
            $(this).val('');
            $(this).removeClass('description');   
        }
    });
    $('input[name=from]').live('focus', function(e) {
        if ($(this).val() == 'Your Email Address') {
            $(this).val('');
            $(this).removeClass('description');   
        }
    });
    
    // Newsletter: reinstate default text and description class on blur
    $('input[name=name]').live("blur", function(e) {
        if ($(this).val() == '') {
            $(this).val('Your Name');
            $(this).addClass('description');    
        }
    });
    $('input[name=from]').live("blur", function(e) {
        if ($(this).val() == '') {
            $(this).val('Your Email Address');
            $(this).addClass('description');    
        }
    });
});