/*
 * jQuery PlaceHolder 1.0.2
 * http://www.kegles.com.br/placeholder/
 *
 * Copyright 2011, Nataniel Kegles
 * Free to use and abuse under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Octuber 2011
 *
 * ****************
 * ** HOW TO USE **
 * ****************
 * - Add holder="text" to inputs
 * - Use input.holder CSS class to style holdered fields
 *
 * ****************
 * ** CHANGELOG! **
 * ****************
 * Version: 1.0.2 - Date: 2011-10-31
 * - Improved search for holding fields with "holder!=''"
 * - Solved compatibility issues with jQuery.meiomask
 * - Added password fields compatibility
 *
 */

//search by holder fields
$(document).ready(function() {
    /*
	$("input[type=text,type=password][holder!='']").each(function(){
			var field = $(this);
			var ffield = $(field).attr("id")+"__jquery_placeholder_passwordFakeField";
			//replace password fields with a fake field
			if ($(field).attr("type") == "password") {
                return;
			}
			//bind focus event
			$(field).bind("focus",function() {
				if ($(field).hasClass("holder")) {
					$(field).val("");
					$(field).removeClass("holder");
				}
			});
			//bind blur event, if is a password field and value='' show the fakefield
			$(field).bind("blur",function() {
				if ($(field).val() == "") {
					if ($(field).attr("type") == "password") {
						$(field).hide();
						$("#"+ffield).show();
					}
					else {
						$(field).val($(field).attr("holder"));
						$(field).addClass("holder");
					}
				}
			});
	});
    */  
    
    $("textarea[holder!='']").each(function(){
            var field = $(this);
            var ffield = $(field).attr("id")+"__jquery_placeholder_passwordFakeField";
            //replace password fields with a fake field
            if ($(field).attr("type") == "password") {
                return;
            }
            //bind focus event
            $(field).bind("focus",function() {
                if ($(field).hasClass("holder")) {
                    $(field).val("");
                    $(field).removeClass("holder");
                }
            });
            //bind blur event, if is a password field and value='' show the fakefield
            $(field).bind("blur",function() {
                if ($(field).val() == "") {
                    if ($(field).attr("type") == "password") {
                        $(field).hide();
                        $("#"+ffield).show();
                    }
                    else {
                        $(field).val($(field).attr("holder"));
                        $(field).addClass("holder");
                    }
                }
            });
    });
    
	setTimeout("__jquery_placeholder_goTitling()",100);
});

//change the holding values
function __jquery_placeholder_goTitling() {
	$("input[type=text][holder!=''][value='']").each(function(){
		$(this).val($(this).attr("holder"));
		$(this).addClass("holder");
	});
}

