function UpdateDailyStr()
{
	this.reqWidgetQueue= new Array(); //queue with the widgets that made a request through this controller object
	var self=this;
	this.suggestInputReff = null;
	this.suggestRequestId = null
	this.suggestInterval = null;
	this.lastSuggestId = null;
	this.lastSuggestSolution = null;
	this.suggestNumber = 0;
	this.suggestPosition = -1;
	this.suggestNavId = 0;
	this.suggestLength = 0;
	this.lastSuggestType = null;
	this.bitSocialSoundtrack = 0;
	
	this.artist_id = null;
	this.artist_name = null;
	this.input_id = null;
	this.wasAlbumSelected=false;
	

	this.handleResponse	= function (managerIndex) {
	//var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
					var width = 235;
					if (this.bitSocialSoundtrack == "1"){
						width = 235;	
					}

					var sEl = _e("small_suggest");

					sEl.style.display = "block";

					//sEl.style.left = getLeft(this.suggestInputReff)+"px";
					//trace("left: "+ sEl.style.left);
					if(Config.browserName=="safari")
					{
					//	sEl.style.top = (getTop(this.suggestInputReff)+19)+"px";
					}
					else
					{
					//	sEl.style.top = (getTop(this.suggestInputReff)+18)+"px";
					}
					if(navigator.appVersion.indexOf("MSIE 6.0") > -1) {
						sEl.style.left= "-330px";
					}
					//trace("top: "+ sEl.style.top);
					try {
						
						var rez = RequestManager.getInstance().getRequestObj(managerIndex).getResponseContent();

					}
					catch (err)
					{
						trace(err);
					}
					
	//				trace("suggest response");
					try
					{
						
						if(rez.length>0 & rez != "null")
						{

							try
							{
								this.artist_id=null;
								this.album_id=null;
								var tmpArr1=rez;
								var tmpArr2='';
								this.suggestLength = 0;
								
								// alert(tmpArr1[0][0]);
								// alert(tmpArr1[0][1][0]); // ==> Artist Name
								// alert(tmpArr1[0][1][1]); // ==> Artist Id
								for (var i=1;i<11 && i<tmpArr1.length+1;i++) {
									artist_name = tmpArr1[i-1][1][0];
									escaped_artist = artist_name.replace(/"/g, "&quot;");
									//escaped_artist = escaped_artist.replace(/&/g, "and");
									//escaped_artist = escaped_artist.replace(/'/g, "&#146;");
									if (escaped_artist.length > 35) { // trim string at 28 chars
										tmpArr2+="<div style='width:"+width+"px;' id='suggest_entry_" + (i-1) + "' href='#' onmousemove='UpdateDailyStr.getInstance().setSuggest("+(i-1)+");' onmouseout='UpdateDailyStr.getInstance().setSuggest(-1);' onmousedown=\"this.blur();UpdateDailyStr.getInstance().suggestAction('" + this.cleanText(escaped_artist) + "','" + tmpArr1[i-1][1][1] + "');return false;\">" + escaped_artist.slice(0,30) + "...</div>";
									}
									else {
										tmpArr2+="<div style='width:"+width+"px;' id='suggest_entry_" + (i-1) + "' href='#' onmousemove='UpdateDailyStr.getInstance().setSuggest("+(i-1)+");' onmouseout='UpdateDailyStr.getInstance().setSuggest(-1);' onmousedown=\"this.blur();UpdateDailyStr.getInstance().suggestAction('" + this.cleanText(escaped_artist) + "','" + tmpArr1[i-1][1][1] + "');return false;\">" + escaped_artist + "</div>";
									}
									this.suggestLength++;
								}		 
								sEl.innerHTML =tmpArr2; 
								sEl.style.display="block";
								//highlight the first item by default if possible
								//_e(UpdateDailyStr.SUGGEST_ID_PREFIX+0).style.width =  width+'px';
								_e(UpdateDailyStr.SUGGEST_ID_PREFIX+0).className = "typeahead_suggestion typeahead_selected";
								
								this.suggestPosition=0;
								
								for(var i=1;i<11 && i<tmpArr1.length+1;i++){
									//_e(UpdateDailyStr.SUGGEST_ID_PREFIX+i).style.width =  width+'px';
									_e(UpdateDailyStr.SUGGEST_ID_PREFIX+i).className = "typeahead_suggestion typeahead_not_selected";
								}
								
							}
							catch(err) {
							 
							}
							
						}
						else {
							sEl.innerHTML = "<div class='typeahead_message'>No matches found</div>";
						}
						
					}
					catch(err)
					{
						sEl.innerHTML = "<div class='typeahead_message'>Loading...</div>";
					}
				
			

	}

	this.cleanText 		= function cleanText(str) {
		return str.replace(/'/g, "\\" + "'");
	}	 
	this.register		= function() {	
		var rqid=RequestManager.getInstance().createRequest(UpdateDailyStr.getInstance(),Config.baseURL+"content.php?module=track_fix&action=main_template");
		// insert the widget in the queue and start the request
		self.reqWidgetQueue[rqid]=widget;
		RequestManager.getInstance().startRequest(rqid);
		return rqid;
	}
	
	this.setSuggest 	= function setSuggest(index) {
			
		this.selectedindex=(index<=-1)?-1:index;
		var nodes=_e('small_suggest').childNodes;

		for(var i=0;i<nodes.length;i++)
		{
			if(this.selectedindex==i)
			{
				nodes[i].className=nodes[i].className.replace(/\btypeahead_not_selected\b/,'typeahead_selected');
			}
			else
			{
				nodes[i].className=nodes[i].className.replace(/\btypeahead_selected\b/,'typeahead_not_selected');
			}
		}
		
	
	}
	
	
	this.closeSuggest 	= function () {
		var sEl = _e("small_suggest");
		sEl.style.display = "none";
	}

	this.queSuggest   	= function (inputReff) {
		var argv = arguments;
		var argc = arguments.length;
		var evnt = null;
		
		//we have an event
		if(argc>=2)
		{
			if(argv[1])
			{
				evnt = argv[1];
			}
			else
			{
				evnt = window.event;
			}
			if(argv[2]){this.bitSocialSoundtrack = argv[2];}
			if(evnt!=null)
			{
				if((evnt.keyCode == 13)&&(this.suggestPosition>=0))
				{
					_e(UpdateDailyStr.SUGGEST_ID_PREFIX+this.suggestPosition).onmousedown();
					return false;
				}

				//arrow navigation on small suggest
				if((_e("small_suggest").style.display == "block")&&((evnt.keyCode==KEY_DOWN)||(evnt.keyCode==KEY_UP)))
				{
					

					//trace(SearchAreaController.SUGGEST_ID_PREFIX+this.suggestPosition);
					try
					{
						_e(UpdateDailyStr.SUGGEST_ID_PREFIX+this.suggestPosition).className = "typeahead_suggestion typeahead_not_selected";
					}
					catch (err) {}

						
					switch(evnt.keyCode)
					{
						case KEY_DOWN :
							if(this.suggestPosition<this.suggestLength-2) this.suggestPosition++;
							else this.suggestPosition = this.suggestLength-1;
							
							//else this.suggestPosition = 0;
						break;
						case KEY_UP :
							if(this.suggestPosition>0) this.suggestPosition --;
							else this.suggestPosition = 0;
						break;
					}
					_e(UpdateDailyStr.SUGGEST_ID_PREFIX+this.suggestPosition).className = "typeahead_suggestion typeahead_selected";
					return false;
				}
			}
		}

		if(inputReff.value=="")
		{
			clearTimeout(this.suggestInterval);
			this.closeSuggest();
			return false;
		}
		this.suggestInputReff = inputReff;
		if(this.suggestInterval!=null) {
			clearTimeout(this.suggestInterval);
		}
		this.suggestInterval = setTimeout("UpdateDailyStr.getInstance().runSuggest()",300);
	}



	this.runSuggest   	= function () {
		var search_key = this.suggestInputReff.value;

		_e("small_suggest").innerHTML = "<div class='typeahead_message'>Loading...</div>";

		this.suggestInterval = null;

		//if we have a request in progress we clear it
		if(this.suggestRequestId!=null)
		{
			RequestManager.getInstance().removeRequest(this.suggestRequestId);
		}

		var more = "";

		search_key = search_key.replace(/&/g, "%26");
		more +="term="+search_key;

		more += "&max=10&format=json";
		this.suggestRequestId=RequestManager.getInstance().createRequest(UpdateDailyStr.getInstance(),"/as/"+"search?"+more);
		RequestManager.getInstance().startRequest(this.suggestRequestId);
	}

	
	this.suggestAction 	= function(data,id) {
		data = data.replace(/&quot;/g, "\"");
		this.closeSuggest();
		this.artist_id   = id;
		currentArtistId  = id;
		this.artist_name = data;
		_e("suggested_artist").value = data;
		_e("the_id").value = id;
		return true;
	}

}


UpdateDailyStr.SUGGEST_ID_PREFIX = "suggest_entry_";

UpdateDailyStr.__instance__=null;

UpdateDailyStr.getInstance=function()
{
	if(UpdateDailyStr.__instance__==null)
	{
		UpdateDailyStr.__instance__=new UpdateDailyStr();
	}
	return UpdateDailyStr.__instance__;
}
