$(function(){
    
    /*
     * Pretty forms
     */
    $('form.prettyform input[type*=radio]').css('border','none');
    $('form.prettyform input[type*=checkbox]').css('border','none');
    if($.browser.mozilla) { prettyform(); }
    
    /*
     * LI hover fix for IE6
     */
    $('#navigation ul li').each( function(){
        $(this).mouseover( function(){ $(this).addClass('hover'); } ).mouseout( function(){ $(this).removeClass('hover'); } );
    });
    
    /*
     * Blur on focus
     */
    $('a').focus(function() { this.blur(); });
    $('input[type*=submit]').focus(function() { this.blur(); });
    $('input[type=text], input[type=password]').addClass("input");
    $('.required').append(" <span>*</span>"); 
    
    $('#navigation ul li li a').last().css('background-image', 'none');
    
    $('#rotator .images').cycle();
    
    // Check for search box, use title as default if exists
    $('#searchText').val( ( $('#searchText').val() == '' ? 'Name' : $('#searchText').val() ) );
    $('#searchText').focusin(function() {
    	$(this).val( $(this).val() == 'search' ? '' : $(this).val() );
    });
    $('#searchText').focusout(function() {
    	$(this).val( $(this).val() == '' ? 'search' : $(this).val() );
    });
    
    // Newsletter signup    
    $('#cm-name').val( ( $('#cm-name').val() == '' ? 'Name' : $('#cm-name').val() ) );
    $('#cm-nkjjtu-nkjjtu').val( ( $('#cm-nkjjtu-nkjjtu').val() == '' ? 'Email' : $('#cm-nkjjtu-nkjjtu').val() ) );
    
    $('#cm-name').focusin(function() {
    	$(this).val( $(this).val() == 'Name' ? '' : $(this).val() );
    });
    $('#cm-name').focusout(function() {
    	$(this).val( $(this).val() == '' ? 'Name' : $(this).val() );
    });
    $('#cm-nkjjtu-nkjjtu').focusin(function() {
    	$(this).val( $(this).val() == 'Email' ? '' : $(this).val() );
    });
    $('#cm-nkjjtu-nkjjtu').focusout(function() {
    	$(this).val( $(this).val() == '' ? 'Email' : $(this).val() );
    });
    
    $('#subForm').submit(function(e) {
    	e.preventDefault();
    	
    	var error = '';
    	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    	
    	if( $('#cm-name').val() == '' || $('#cm-name').val() == 'Name' ) {
    		error += "* Please enter your name.\n";
    	}
    	
    	if( !emailReg.test( $('#cm-nkjjtu-nkjjtu').val() ) ) {
    		error += "* Please enter a valid email address.\n";
    	}
    	
    	if( error == '' ) {
    		$('#subForm').submit();
    	} else {
    		alert(error);
    	}
    });
});


/*
 * Pretty forms
 */
function prettyform(){
  /*
   * Hide forms
   */
  $( 'form.prettyform' ).hide().end();
  /*
   * Label & list formatting
   */
  $( 'form.prettyform' ).find( 'label' ).not( '.noprettyform' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = '';
    this.appendChild( labelSpan );
  } ).end();
  
  /*
   * Show forms
   */
  $( 'form.prettyform' ).show().end();
}
