﻿/**
* TextBox(input/textaera) plugin
*
* Copyright (c) 2010 uonun (udnz.com)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*
* Example:
*		add an attribute named "init" with the value you want to show automaticly.
*		<input type="text" id="id1" init="default note text" />
*
*/
(function($) { // hide the namespace

    function InputLoader() {
        //You can change this value to apply your own css for default style
        this.InitedCSS = "grayInput";
    };

    $.extend(InputLoader.prototype, {
        Apply: function(defaultCssName) {
            $("input[init],textarea[init]").each(function() {
                var val = $(this).attr("init");
                if (val.length > 0) {
                    this.value = val;
                    $(this).addClass(defaultCssName);
                    $(this).focus(function() {
                        if (this.value == val) this.value = "";
                        $(this).removeClass(defaultCssName);
                    }).blur(function() {
                        if (this.value == "") {
                            this.value = val;
                            $(this).addClass(defaultCssName);
                        }
                    });
                }
            });
        }
    });

    /* Initialise the InputLoader. */
    $(document).ready(function() {
        var __loader = new InputLoader();
        __loader.Apply(__loader.InitedCSS);
    });

})(jQuery);

