/* -------------------------------------------------- *
 * ToggleVal Plugin for jQuery                        *
 * Version 1.0                                        *
 * -------------------------------------------------- *
 * Author:   Aaron Kuzemchak                          *
 * URL:      http://kuzemchak.net/                    *
 * E-mail:   afkuzemchak@gmail.com                    *
 * Date:     8/18/2007                                *
 * -------------------------------------------------- *
 * Edited:   Martin Haller                            *
 * URL:      http://ziju.cz                           *
 * Date:     20/03/2008                               *
 * Expanded: Textarea, Password, DefaultClass		  *
 * -------------------------------------------------- */
 
jQuery.fn.toggleVal = function(defaultClass) {
	this.each(function() {
		// Pokud prvek nema atr nebo title tag nastaven tak to znamena ze tuto
		// neni treba mu nastavovat defaultni hodnotu
		if(!(this.tagName == "INPUT" && $(this).attr("alt") == null) &&
			!(this.tagName == "TEXTAREA" && $(this).attr("title") == null))
		{
			// U vsech prvku kteri maji defaultni hodnotu vytvorime 
			// div ktery bude zobrazovan nad timto prvkem
			$inputOffset = $(this).position();
			$divHelper = $('<div class="toggleValHelper"></div>')
			.css({
				position: "absolute",
				top: $inputOffset.top + 1 + "px",
				left: $inputOffset.left + "px",
				height: $(this).height() - 1 + "px",
				width: $(this).width() - 1 + "px",
				cursor: "text",
				zIndex: "25",
				padding: $(this).css("padding-top") + " " + $(this).css("padding-right") +
				 	" " + $(this).css("padding-bottom") + " " +$(this).css("padding-left")
			})
			.addClass(defaultClass)
			.hide();
			if(this.tagName == "INPUT") {
				$($divHelper).click(function() {$(this).hide().prev("input").focus();})
				.html($(this).attr("alt"))
			} 
			if(this.tagName == "TEXTAREA") {
				$($divHelper).click(function() {$(this).hide().prev("textarea").focus();})
				.html($(this).attr("title"))
			} 
			$(this).after($divHelper);

	    	// Nastavime vsem prvkum event focus, kterej znamena aby se skryl helper
			jQuery(this)
			.focus(function() {	$(this).next(".toggleValHelper").hide();})
			.blur(function() { if(this.value == ""){$(this).next(".toggleValHelper").show();}});	
			
			jQuery(this).trigger("blur");
		}
	});
}