/*
   * inputSearch - Delete target input's value & placeholder
   * Original - delval.js
   * 5509 - norimania[at]gmail.com
   * License - MIT
   * Archive - http://moto-mono.net/delval
   * Required - jQuery
   * Date - 09-06-10 02:47
   */

$.fn.inputSearch = function(options){

  var c = $.extend({
    placeholder: "search..."
  },options);

$(this).each(function(i){

    var self = $(this);
    var self_name = $(this).attr('id');
    self.wrap("<span id='"+self_name+"-"+i+"'></span>");
    $("span#"+self_name+"-"+i)
    .append("<span class='inputSearch'></span>")
    .append("<span class='placeholder'>"+c.placeholder+"</span>")
    .addClass("inputSearch-group");

    var group = $("span#"+self_name+"-"+i).css("height",self.attr("offsetHeight")),
    btn = $("span.inputSearch",group).css("height",group.height()),
    placeholder = $("span.placeholder","#"+self_name+"-"+i);

    if(self.val().length<1){
    btn.hide();
    }else{
    placeholder.hide();
    }

    self.focus(function(){
      placeholder.hide();
      }).blur(function(){
        if(self.val().length<1) placeholder.show();
        });

    placeholder.click(function(){
        self.focus();
        });

    self.keyup(function(){
        if(self.val().length>0) btn.show();
        else btn.hide();
        });

    btn.click(function(){
        self.val("");
        btn.hide();
        self.focus();
        });

});
}
