(function($) {
	$.fn.placeholder = function() {  
		return this.each( function() {  
			
			var input1 		= $(this);
			var input2 		= $("<input type='text' />");
			var inputHold 	= false;
			
			var attrs = input1[0].attributes;
			
			for(var i=0; i<attrs.length; i++) {
				if (attrs[i].nodeName != "type" && attrs[i].nodeValue != "") {
					input2.attr(attrs[i].nodeName, attrs[i].nodeValue);
				}
			}
			
			if (!input1.attr("title")) {
				input1.attr("title", input1.attr("alt"));
			}
			
			input2.insertAfter(input1);
			input2.attr({
				"alt": "",
				"readonly": "readonly",
				"name":	"",
				"value": input1.attr("alt")
			});
			
			input1.hide();
			input2.show();
			
			input2.focus(function (e) {
			
				if (!inputHold) {
					input2.hide();
					input1.show().focus();
				}
				
			});
			
			input1.focus(function (e) {
				
				if (!inputHold) {
					input2.hide();
					input1.show();
					inputHold = true;
				}
				
			}).blur( function () {
			
				if (inputHold) {
					if ($(this).is("textarea") && $(this).html() == "") {
						input2.show();
						input1.html("").hide();
						inputHold = false;
					} else if ($(this).val() == "") {
						input2.show();
						input1.val("").hide();
						inputHold = false;
					}
				}
				
			});
			
			input1.trigger("focus");
			input1.trigger("blur");
			
		});
	};  
})(jQuery);  

$(function() {
	$("input[type=text][alt!=''], input[type=password][alt!='']").placeholder();
});
