﻿/*
 * jQuery Placeholder Plug-in
 *
 * Copyright (c) 2010 Max Davis
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: 1
 * Version: 0.1
 *
 * v0.1
 * - First public release
 *
*/

(function($){
	
	$.fn.placeholder = function( color ) {

  if ($(this).length > 0)
  {

    if ($(this).get(0).tagName == "INPUT") {

			var original_pass_field = $(this);
      var original_pass_field_color = original_pass_field.css('color');

		if($(this).attr("type") == "password") {


			if(original_pass_field.val() == "") {
				$("<input type=\"text\" value=\""+ $(this).attr("title") +"\" name=\"pass_placeholder\" class=\"form-text\" style=\"color:" + color + ";\" id=\"pass_placeholder\" />").insertAfter($(this)); //.css('color', original_pass_field_color);
				$(this).css("display","none");
			}

			var original_pass_field = $(this);

			$("#pass_placeholder").focus(function() {
				if(original_pass_field.val() == "") {
					$("#pass_placeholder").css("display","none");
					original_pass_field.css("display","");
					original_pass_field.focus();
				}
			});

			original_pass_field.blur(function() {
				if(original_pass_field.val() == "") {
					$("#pass_placeholder").css("display","");
					original_pass_field.css("display","none");
				}
			});

		} else {

			if($(this).val() === "") {
				$(this).val($(this).attr("title"));
				$(this).css("color", color);
			}

			$(this).focus(function() {
				if($(this).val() === $(this).attr("title")) {
					$(this).css("color", original_pass_field_color);
					$(this).val("");
				}
			}).blur(function() {
				if($(this).val() === "") {
				  $(this).css("color", color);
					$(this).val($(this).attr("title"));
				}
			});
		}

    }

    else if ($(this).get(0).tagName == "TEXTAREA") {
      $(this).text($(this).attr("title"));
      $(this).focus(function() { if ($(this).text() === $(this).attr("title")) $(this).text(''); });
    }

	}}
	
})(jQuery);
