if (typeof(VERSION_CHECK) != 'undefined' && VERSION_CHECK){

   VERSION_ = "1.0";

} else {

	sc_pls = 'http://yp.shoutcast.com/sbin/tunein-station.pls?id=';
	
	aacp_enabled = top.psp.sysRadioCapabilityCheck(0) ? true : false;

	
var makeList = {

	parseXML : function (xml) {

		if (top.myXML.xmlParseFunction(xml)){

			if (top.myXML.xmlObject.stationlist && top.myXML.xmlObject.stationlist.station){
				
				top.playerModule.ex_module_var = top.myXML.xmlObject.stationlist.station;

			} else {
			
				top.playerModule.ex_module_var = 'NOT FOUND';
			}
			
			top.playerModule.start('shoutcast');
		
		}
	
	}
	
};


var playRandom = {
	
	play : function (xml) {

		if (top.myXML.xmlParseFunction(xml)){
		
			if (typeof(top.myXML.xmlObject.stationlist.station) && !/array/i.test(top.myXML.xmlObject.stationlist.station.constructor.toString())){

				if (top.myXML.xmlObject.stationlist.station.mt.match(/aacp/) && !aacp_enabled){

					playRnd();
				
				} else {
				
					pls = sc_pls + top.myXML.xmlObject.stationlist.station.id;
					top.KKplayer.playURL(pls);
				}

			} else {

				this.errorFlash('Stream error!');
			}
		}
	}
};

	

	html = '';
	html +='<form name="shoutcastsearch"><table cellpadding="0" cellspacing="0" width="100%" class="sc-searchbar"><tr>';
	html +='<td><input class="sc-random-button" type="button" onclick="playRnd();" value="RANDOM"></td>';
	html +='<td align="right">&nbsp;Keyword:</td><td><input type="text" name="keyword" id="keyword" class="keyword" onmousedown="top.keyboard.inputText(this);"></td>';
	html +='<td align="right">&nbsp;Bitrate:</td><td><select name="bitrate" id="bitrate" class="bitrate"><option>ANY</option><option>256</option><option>192</option><option>128</option><option>96</option><option>64</option><option>56</option><option>32</option><option>24</option></select></td>';
	html +='<td align="right">&nbsp;Max:</td><td><select name="limit" id="limit" class="limit"><option>10</option><option>25</option><option>50</option><option>100</option></select></td>';
	html +='<td align="right"><input class="sc-search-button" type="button" onclick="search_SC();" value="SEARCH"></td></tr></table></form>';
	
	if (top.playerModule.ex_module_var == ''){
	
		html +='<div class="shoutcast-disclaimer-div"><br><br>SHOUTcast is a <u>dynamic</u> Internet audio broadcasting database, which means that if you save SHOUTcast stream or playlist it might stop working, eventually. You can either search SHOUTcast again and save new link for your favourite station or find and save direct stream from the station\'s website, if available.</div>';
	}

	list = false;
	if (top.playerModule.ex_module_var != ''){
		
		if (top.playerModule.ex_module_var != 'NOT FOUND'){	
		
			stations = top.playerModule.ex_module_var;
			sl = stations.length;
			is_array = true;
			
			if (!/array/i.test(stations.constructor.toString())){
			
				sl=1;
				is_array = false;
			}
		
			top.statusMod.showProgress(1, 'Preparing the list...');	
			k=0;
			html +='<table class="sc-results-table" cellspacing="0" cellpadding="0" width="100%">';
			
				for (i=0; i<sl; i++){
				
					mt = (is_array)?stations[i].mt:stations.mt;
					
					if (!(mt.match(/aacp/) && !aacp_enabled)){
				
						k++;
						mt = (mt.match(/aacp/))?'AAC+':'MP3';
						html+='<tr><td class="sc-station-td" colspan="3"><b>#'+k+'</b>. ['+((is_array)?stations[i].genre:stations.genre)+'] <b>'+((is_array)?stations[i].name:stations.name)+'</b></td></tr><tr><td class="sc-playbutton-td"><input type="button" class="sc-play-button" onclick="top.KKplayer.playURL(\''+sc_pls+((is_array)?stations[i].id:stations.id)+'\');" value="PLAY"></td><td class="sc-song-td">('+((is_array)?stations[i].lc:stations.lc)+') '+((is_array)?stations[i].ct:stations.ct)+'</td><td class="sc-stream-td">'+((is_array)?stations[i].br:stations.br)+'/'+mt+'</td></tr>';
					}
				}

			html+='</table>';
			
			list=true;
			
			
		} else {
		
			html += 'The search returned no results';	
			top.playerModule.ex_module_var = '';

		}
		
	
	} 

	document.write(html+top.styleVars.BOTTOM_BIT());
	delete html;
	top.statusMod.showProgress(0);	
	top.KKplayer.lockMode(0);
	document.shoutcastsearch.keyword.focus();
	
}

function playRnd() {

	url = 'http://yp.shoutcast.com/sbin/newxml.phtml?random=1'+((aacp_enabled)?'':'&mt=mpeg');
	top.httpGet.sendUrlContentToFunction(url, 'top.frames[\'mainframe\'].playRandom.play');

}



function search_SC() {

	keyword = document.shoutcastsearch.keyword.value;
	keyword = keyword.replace(/[^\w ]/g,'').replace(/(\w)\s+(\w)/g,'$1+$2').replace(/\s/g,'').toLowerCase();
	
	index_br = document.shoutcastsearch.bitrate.selectedIndex;
	bitrate = document.shoutcastsearch.bitrate.options[index_br].text;
	if (bitrate == 'ANY'){ bitrate = '';}
	else {bitrate = '&br=' + bitrate;}
	
	index_max = document.shoutcastsearch.limit.selectedIndex;
	limit = ((keyword != '')?'&limit=':'')+document.shoutcastsearch.limit.options[index_max].text;
	
	keyword = (keyword != '')?'search='+keyword:'random=';
	
	mt = (aacp_enabled)?'':'&mt=mpeg';
	sc_search = 'http://yp.shoutcast.com/sbin/newxml.phtml?'+keyword+limit+bitrate+mt;

	top.httpGet.sendUrlContentToFunction(sc_search, "top.frames['mainframe'].makeList.parseXML");
		
	
}


