(function($) {
		  
	$.fn.jSuggest = function(options) {
		// merge users option with default options
		var opts = $.extend({}, $.fn.jSuggest.defaults, options);		
		var jH = ".jSuggestHover";
		var jsH = "jSuggestHover";
		var iniVal = this.value;
		var textBox = this;
		var textVal = this.value;	
		var jC = "#jSuggestContainer";
		
		var orgVal=$("#txtKeywords").val()
		var c=$("#txtKeywords");
		
		$(jC).hide();
		$(this).bind("keyup click", function(e){
			if (c.val() == orgVal) {
				c.val("")
			}
			textBox = this;
			textVal = this.value;
			if (this.value.length >= opts.minchar && $.trim(this.value)!="Search Terms") {
				var offSet = $(this).offset();
				$(jC).css({
					position: "absolute",
					top: offSet.top + $(this).outerHeight() + "px",
					left: offSet.left-1,
					width: $(this).outerWidth() + "px",
					opacity: opts.opacity,
					zIndex: 500000
				}).show();
				
				// if escape key
				if (e.keyCode == 27 ) {
					$(jC).hide();
				}
				
				// new query detected
				else if (textBox.value != iniVal){
					iniVal = textBox.value;
					
					$(".jSuggestLoading").show();
					$(jC).find('ul').remove();
					
				}
			}
			// if text is too short do nothing and hide everything
			else {
				$(jH).removeClass(jsH);
				$(jC).hide();
				/*if (c.val() == "") {
					c.val(orgVal)
				}*/
			}
			
			// no bubbling, click is binded to textBox to prevent document bind from firing
			return false;
		});
		
		// why no use $(this).blur ?, because jSuggest box is hidden before click fires so this is the only way to do it
		// alternate way is to say that text blur will fire before$("#jSuggestContainer ul li") click.
		$(document).bind("click", function(){
			$(jC).hide();
			iniVal = textBox.value;
			if (c.val() == "") {
				c.val(orgVal)
			}
		});

	};
	
	$.fn.jSuggest.defaults = {
		minchar: 0,
		opacity: 1.0,
		zindex: 20000,
		delay: 2500,
		loadingImg: 'ajax-loader.gif',
		loadingText: 'Loading...',
		autoChange: false,
		url: "",
		type: "GET",
		data: ""
	};
		
	
		  

})(jQuery);
$(function(){

	$("#txtKeywords").jSuggest({
		url: "suggestion.html",
		type: "GET",
		data: "Keywords",
		autoChange: true
	});

});