/**
 * @author Stanislav Kurinec
 * @extends jQuery()
 * @extends $()
 * @addon
 *
 */
(function(){
    jQuery.fn.extend(
        {
            /**
             * placeholder()
             * @return {jQuery} - unchanged current jQuery selection
             * @param {Object} options Optional, an object with focusClass, blurClass and placeholdValue fields
             */
            placeholder: function(){

			   if($.browser.safari){ return false; }

			   var $query = this; // this is a current jQuery selection

                var placeholdOptions = arguments[0] || {};

                var $inputs = $query.filter("input[placeholder]");

                $inputs
                    .each(
                        function(){
                           var $this = jQuery(this);
                           this.placeholdValue = placeholdOptions.placeholdValue || $.trim($this.attr("placeholder"));
                           $this.val(this.placeholdValue);
                           //$this.addClass(placeholdOptions.blurClass || "");
                        }
                    )
                   .bind("focus",function(){
                       var $this = jQuery(this);
                       var val = $.trim($this.val());
                       if(
                          val == this.placeholdValue ||
                          val == ""
                       )
                       {
                           $this
                               .val("")
                               .removeClass(placeholdOptions.blurClass || "")
                               .addClass(placeholdOptions.focusClass || "");
                       }
                   })
                   .bind("blur",function(){
                       var $this = jQuery(this);
                       var val = $.trim($this.val());
                       if(
                          val == this.placeholdValue ||
                          val == ""
                       )
                       {
                           $this
                               .val(this.placeholdValue)
                               .addClass(placeholdOptions.blurClass || "")
                               .removeClass(placeholdOptions.focusClass || "")
                       }


                   });
               return $query;

            }
        }
    )
})()
