var setup_contact = function(){
  
  jQuery( function( $ ){
    
    var NAME = "Name", EMAIL = "E-mail", MESSAGE = "Message";

      // VALIDATE FORM:
    $( "#contact_form").validate({
      messages: {
  			name: {
  				required: "Please enter your name."
  			},
  			email: {
  			  required: "Please enter a valid email address."
  			},
  			message: {
  			  required: "Please enter your message."
  			}
  		},
      invalidHandler : function( e, validator ){
        var redo_name = false, redo_message = false;
        if ( $( "input#name" ).val() == NAME ) {
          $( "input#name" ).val( "" );
          redo_name = true;
        }
        if ( $( "input#email" ).val() == EMAIL ) {
          $( "input#email" ).val( "" );
        }
        if ( $( "textarea#message" ).val() == MESSAGE ) {
          $( "textarea#message" ).val( "" );
          redo_message = true;
        }
        if ( redo_name || redo_message ) {
          validator.checkForm();
        }
      },
      submitHandler: function( form ){
          // DISABLE SUBMIT BUTTON:
        $( "#submit" ).attr( "disabled", "disabled" );
          // DISPLAY RESPONSE:
        $( form ).ajaxSubmit({
          success: function( data, status, xhr ){
            if ( data == true ) {
              $( "#submit" ).hide();
              $( "#success" ).show();
            } else {
              $( "#submit" ).hide();
              $( "#failure" ).show();
            }
          }
        }); 
      }
    });


      // SETUP DEFAULT VALUES:
    var fields = new Array();
    fields.push( $( "input#name" ).val( NAME ) );
    fields.push( $( "input#email" ).val( EMAIL ) );
    fields.push( $( "textarea#message" ).val( MESSAGE ) );

    var focusHandler = function(){
      switch ( $( this ).val() ) {
        case NAME :
        case EMAIL :
        case MESSAGE :
          $( this ).val( "" );
          break;
      }
    };

    var blurHandler = function(){
      var val;
      if ( $( this ).val() == "" ) {
        switch ( $( this ).attr( "id" ) ) {
          case "name" :
            val = NAME;
            break;
          case "email" :
            val = EMAIL;
            break;
          case "message" :
            val = MESSAGE;
            break;
        }
        $( this ).val( val );
      }
    };

      // FIELD LISTENERS:
    $( fields ).each( function(){
      $( this ).bind( "focus", focusHandler );
      $( this ).bind( "blur", blurHandler );
    });
    
  });
  
}

