/**
 * All intellectual property rights in this Software throughout the world belong to UK Radioplayer, 
 * rights in the Software are licensed (not sold) to subscriber stations, and subscriber stations 
 * have no rights in, or to, the Software other than the right to use it in accordance with the 
 * Terms and Conditions at www.radioplayer.co.uk/terms. You shall not produce any derivate works 
 * based on whole or part of the Software, including the source code, for any other purpose other 
 * than for usage associated with connecting to the UK Radioplayer Service in accordance with these 
 * Terms and Conditions, and you shall not convey nor sublicense the Software, including the source 
 * code, for any other purpose or to any third party, without the prior written consent of UK Radioplayer.
 *
 * @name RadioplayerQuickfind
 * @description search results data
 *
 *
 * 
 * @author Sergejs Vaskevics <sergejs.vaskevics@ubcmedia.com>
 */
radioplayer.models.RadioplayerQuickfind = function () {  };

radioplayer.models.RadioplayerQuickfind.prototype = {
		
		getData : function(searchString, callback){
			radioplayer.currentSearchString = escape(searchString);
			var self = this,			
				baseUrl = radioplayer.searchServerBaseUrl + "query.jsp?",
				parameters = "searchText=" + radioplayer.currentSearchString + "&stationID=" + radioplayer.currentStationID;
			glow.net.loadScript(baseUrl + parameters);
		},
		processSecondRequest : function(data){
			this.searchResponseData = data;
			glow.events.fire(document, 'quickfind:processResults', {data:data});
			delete radioplayer.currentSearchString;
		},				
		truncate: function (str, nMaxChars) {
		    if (str.length <= nMaxChars){
		    	return str;
		    }
		    var xLastSpace = str.lastIndexOf(' ', nMaxChars - 1 - 2);
		    if (xLastSpace == -1 || xLastSpace < str.length / 2){
		    	return str.substr(0, nMaxChars - 3) + "...";
		    }
		    return str.substr(0, xLastSpace) + "...";
		}
};


