﻿/*
 * jQuery Watermark plugin
 * Version 0.9 (17-JUL-2009)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://mario.ec/projects/jqwatermark/
 * Copyright (c) 2009 Mario Estrada
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */

(function($) {
	$.fn.watermark = function(text, css_options){
		css = $.extend({
			color : '#999',
			left: 4
		}, css_options);
		
		return this.each(function()
		{
			var input_marked = $(this);
			var label_text = text === undefined ? $(this).attr('title') : title;
			var watermark_label = $('<span class="watermark">' + label_text + '</span>');
			
			var height = $(this).outerHeight();

			checkVal($(this).val(), watermark_label);

			watermark_label.click(function() {
				$(this).next().focus();
			})

			$(this).before(watermark_label).focus(function() {
				checkVal($(this).val(), watermark_label);
				
				if ($.browser.msie) {
					watermark_label.css("color","#CCC");
				} else {
					watermark_label.animate({ opacity : 0.4}, 250);
				}
			}).blur(function(){
				checkVal($(this).val(), watermark_label);
				if ($.browser.msie) {
					watermark_label.css("color","#333")
				} else {
					watermark_label.animate({ opacity : 1}, 250);
				}
			}).keydown(function(e){
				$(watermark_label).hide();
			});
		});
	};
	
	checkVal = function(val, elem) {
		if(val == '') $(elem).show();
		else $(elem).hide();
	};

	$(document).ready(function(){
		$("div.form input[type=text], div.form input[type=password]").each(function(){
			$(this).watermark();
		});
	});
})(jQuery);
