/*
 * 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);
		
		self.wrap("<span id='inputSearch-"+i+"'></span>");
		$("span#inputSearch-"+i)
			.append("<span class='inputSearch'></span>")
			.append("<span class='placeholder'>"+c.placeholder+"</span>")
			.addClass("inputSearch-group");
		
		var group = $("span#inputSearch-"+i).css("height",self.attr("offsetHeight")),
			btn = $("span.inputSearch",group).css("height",group.height()),
			placeholder = $("span.placeholder","#inputSearch-"+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();
		});
		
	});
}

