jQuery.Engine.searchitems = function(options) {
	this.settings = jQuery.extend({}, jQuery.Engine.searchitems.defaults, options);
};
jQuery.extend(jQuery.Engine.searchitems, {
	defaults : {
		SEARCH_BOX_ID: '#searchitem',
		ITEMS_CONTAINER: '#items_container_ajax'
	},
	prototype: {
		initialize : function() {
			this.initSearchBox();
		},
		
		initSearchBox : function() {
			var SEARCH_BOX_ID = this.settings.SEARCH_BOX_ID;
			var ITEMS_CONTAINER = this.settings.ITEMS_CONTAINER;
			var submitObj = this;
			
			$(SEARCH_BOX_ID).blur(function() {
				setTimeout(function() {
					$(ITEMS_CONTAINER).slideUp('fast');
				}, 100);
			});
			
			$(SEARCH_BOX_ID).keyup(function(e) {
				if ($.browser.msie) { // IE
					if (e.keyCode == 13) return false;
				} else { // Netscape/Firefox/Opera
					if (e.which == 13) return false;
				}
				
				if (submitObj.timeout != null) {
					clearTimeout(submitObj.timeout);
					submitObj.timeout = null;
				}
				
				var searchVal = $(SEARCH_BOX_ID).val();
				var searchLen = searchVal.length;
				
				if (searchLen >= 3 || searchLen == 0) {		
					submitObj.timeout = setTimeout(function() {
						var msg = $.ajax({
							type: "POST",
							url: "http://www.celebsfreak.com/ajax/items_search_ajax",
							async: false,
							data: "search="+searchVal
						}).responseText;
						
						$(ITEMS_CONTAINER).show();
						$(ITEMS_CONTAINER).html(msg);
					}, 400);
				}
			});
		}
	}
});