/**
 * Unobtrusively set up placeholder behaviors on all text inputs for which
 * the title attribute has been set. The title text will be used as the
 * placeholder text.
 * @author Travis Miller
 * @link http://www.electrumdigital.com/
 */
$( function() {

	$("input[type=text][title],textarea[title]")
		.each( function() {
			var $control = $(this);
			showPlaceholder( $control ); // initialize each control on page load
			// if the form is submitted while the placeholder is being
			// displayed, remove the placeholder text before submitting
			$control.parents("form").submit( function() {
				if ( $control.hasClass("placeholder") ) {
					$control.val("");
				}
			} );
			
		} )
		.blur( function() {
			showPlaceholder( $(this) );
		} )
		.focus( function() {
			var $control = $(this);
			if ( $control.val() === $control.attr("title") ) {	
				$control.removeClass("placeholder");
				$control.val("");
			}
		} );

	function showPlaceholder( $control ) {
		var placeholderText = $control.attr("title");
		if ( $control.val() === "" || $control.val() === placeholderText ) {
			$control.addClass("placeholder");
			$control.val(placeholderText);
		}
	};

} );

