if(typeof(ReqSong) == "undefined") {
	var ReqSong = {
		input : null,
		input_id : null,
		suggestionList : null,
		WAIT_TIME : 200,
		sendRequest : false,
		localCache : new Array(),
		init : function(inputID) {
			var _T = this;
			_T.input_id = inputID;
			
			this.input = $("#"+_T.input_id).focus(function() {
				if (this.input_id == 'searchMusicForm')	$(this).addClass("focus");
				$(this).val("").unbind("focus").focus(function() {
					_T.getSuggestion();
				});;
			}).keyup(function(e) {
				_T.getSuggestion();
			}).keypress(function(e) {
				if(13 == event.keyCode && this.value.length > 0)
					if (_T.input_id == 'searchMusicForm')	searchMusicBugs(1);
					else	ilike.searchAll(_T.input_id, 1, 1);
			}).blur(function() {
				this.suggestionList.hide();
			}.bind(this));
			
			this.suggestionList = $("#suggestionList").focus(function() {
				$(this).show();
			});
		},
		showSuggestion : function(data) {
			$("#suggestionList > ul").remove();
				
			if(!data.length) {
				this.suggestionList.hide();
				return;
			}
			
			var _T = this;
			
			var ul = $("<ul></ul>").addClass("keywordList");
			for(var i = 0; i < data.length; i++) {
				var html = "<a href=\"#none\">" + this.replaceSrchText(data[i][0]) + "</a>";
				$("<li></li>").html(html).appendTo(ul).find("a").focus(function() {
					_T.suggestionList.show();
				}).attr("trackId", data[i][1][0]).click(function() {
					_T.input.val($(this).text());
					$("#suggestionList").hide();

					if (_T.input_id == 'searchMusicForm')	searchMusicBugs(1);	//_T.input.val($(this).text());	
					else	ilike.searchAll(_T.input_id, 1, 1);
				});
			}
			
			$("#suggestionList").append(ul).show();
		},
		getSuggestion : function() {
			var q = this.input.val();
			if(this.localCache[q]) {
				this.showSuggestion(this.localCache[q]);
				return;
			}
			
			if(this.sendRequest) {
				setTimeout(function() {
					this.getSuggestion();
				}.bind(this), this.WAIT_TIME);
				return;
			}
			
			this.sendRequest = true;
			$.getJSON(_staticUrl + "/station/board/getReqSongSuggestion", {q : q}, function(data) {
				this.localCache[q] = data;
				this.showSuggestion(data);
				
				this.sendRequest = false;
			}.bind(this));
		},
		replaceSrchText : function ( getText )
		{
			//if (this.input_id == 'searchMusicForm')	getText = getText.substring(0, 33);
			//else	getText = getText.substring(0, 14);
			
			var q = this.input.val();
			
			var ret = getText.replace(q, "<strong>"+q+"</strong>");
			if (ret != getText)	return ret;
			
			var pos = getText.toUpperCase().indexOf(q.toUpperCase());
			var len = q.length;
			if (pos >= 0 )ret = getText.substring(0, pos-1)+"<strong>"+getText.substr(pos, len)+"</strong>"+getText.substring(pos+len, getText.length);
			
			return ret;
		}
	};
}
