// JavaScript Document wybierak
	var globalIndex=0;
	var lastIndex=0;
	var radioList=new Array();
	var tmpRadio=new Array();
	var radioFilter=false;
	var radioNames=new Array('','Roxy Fresh','Roxy Rewind','Infomuzyka FM','Z³ote Przeboje 80','Radio Smooth Jazz cafe','Kiss The Beat' ,'Kiss The Flow','Roxy FM','Z³ote Przeboje','Pierwsze Radio Informacyjne','','Blue FM','Roxy Alternative','Roxy UK','Z³ote Przeboje Klasyka Rocka','Z³ote Przeboje 60','Z³ote Przeboje 70','Z³ote Przeboje po Polsku','Kiss FM','Blue Party','Radio Å»yrafa','Radio Baobab','Z³ote Przeboje festiwali','','Z³ote Przeboje Love Songs','Z³ote Przeboje Madonny','Z³ote Przeboje Chill Out','Z³ote Przeboje Film','WWWJazz','Radio Kotek.fm', 'Radio Plotek.fm','Radio Chopin', 'Metro Stacja', 'Radio Chopin', '¦wiêta id±');
	var radioLinks=new Array('','fresh','rewind','infomuzyka_fm','80','radio_smooth_jazz_cafe','kiss_the_beat','kiss_the_flow','roxy','zlote_przeboje','tok_fm','','blue_fm','alternative','uk','klasyka_rocka','60','70','po_polsku','kiss_fm','blue_party','radio_zyrafa','radio_baobab','festiwali','','love_songs','madonna','chillout','film','wwwjazz','kotek_fm','plotek_fm','radio_chopin','metrostacja', 'radiochopin','swieta');
	var radioNew=new Array();
	for(var i = 1; i < radio.length; i++){
		radioNew[radioLinks[i]]=radio[i];
	}
function hrefIt(hrefId){
	var subdomain = 'www';
	if(hrefId==29 || hrefId==28 || hrefId==9 || hrefId==4 || hrefId==18 || hrefId==15 || hrefId==25 || hrefId==16 || hrefId==17 || hrefId==23 || hrefId==26 || hrefId==27){
	var subdomain = 'player.zloteprzeboje';
	}else if(hrefId==2 || hrefId==8 || hrefId==1 || hrefId==14 || hrefId==13){
		var subdomain = 'player.roxy';
	}
	var href = 'http://'+subdomain+'.tuba.fm/'+radioLinks[hrefId];
	return href;
}
	
function move(goWhere){
	switch(goWhere)
	{
		case 'next':
			globalIndex=globalIndex+6
			if(globalIndex>=radioList.length){globalIndex=lastIndex+1;}
			chooserMake(radioList,globalIndex);
			break;
		case 'back':
			globalIndex=globalIndex-6
			if(globalIndex<0){globalIndex=(radioList.length)+globalIndex;}
			chooserMake(radioList,globalIndex);
			break;
		default:
			alert('move error');
			break;
	}		
}
function chooseReload(index,radioIndex){		
		document.getElementById('anchore-'+index+'-'+radioIndex).innerHTML = '<span><strong>'+radio[radioIndex][3]+'</strong><br/>'+radio[radioIndex][4]+'<br/></span>';
		document.getElementById('anchore-'+index+'-'+radioIndex).title = 'Radio Internetowe, S³uchaj: '+radio[radioIndex][3]+' &ndash; '+radio[radioIndex][4];
		document.getElementById('anchore-'+index+'-'+radioIndex).style.backgroundImage = 'url('+radio[radioIndex][2]+')';
}

function chooseChange(){
	if(!radioFilter){
		for(var i=0;i<tmpRadio.length;i++){
			if(tmpRadio[i][0]!=10 && tmpRadio[i][0]!=21 && radio[tmpRadio[i][0]][3].toUpperCase()!=tmpRadio[i][1].toUpperCase() && radio[tmpRadio[i][0]][4].toUpperCase()!=tmpRadio[i][2].toUpperCase()){
				chooseReload(tmpRadio[i][3],tmpRadio[i][0]);
				tmpRadio[i]	= new Array(tmpRadio[i][0],radio[tmpRadio[i][0]][3],radio[tmpRadio[i][0]][4],tmpRadio[i][3]);		
			}
		}
	}
}


function chooserMake(radioList,globalIndex){
	document.getElementById('chooseandgo').style.height='700px';
	var tmpIndex=0;
	var htmlInjection='';
	var stopWhile=true;
	tmpRadio=new Array();
	var classRadio='';
	if(radioFilter){classRadio=' Radio';}
	while (tmpIndex<6 && stopWhile)
	{		
		
		if(globalIndex>=radioList.length){globalIndex=0;}
		
		if(isEven(tmpIndex)){htmlInjection+='<div>';}
		var href = hrefIt(radioList[globalIndex]);
		htmlInjection+='<a href="'+href+'" class="Player'+classRadio+'" rel="new" title="Radio Internetowe, S³uchaj: '+radio[radioList[globalIndex]][3]+' &ndash; '+radio[radioList[globalIndex]][4]+'" id="anchore-'+tmpIndex+'-'+radioList[globalIndex]+'"><span><strong>'+radio[radioList[globalIndex]][3]+'</strong><br/>'+radio[radioList[globalIndex]][4]+'<br/></span></a>';
		
		if(radioList.length<6 && globalIndex==radioList.length-1){stopWhile=false;}
		
		if(!isEven(tmpIndex) || !stopWhile){htmlInjection+='</div>';}
		
		tmpRadio.push(new Array(radioList[globalIndex],radio[radioList[globalIndex]][3],radio[radioList[globalIndex]][4],tmpIndex));
		
		tmpIndex++;
		
		if(tmpIndex<6){globalIndex++;}							
	}
	lastIndex=globalIndex;
	
	if(radioList.length<6){
		document.getElementById('back').style.display='none';
		document.getElementById('next').style.display='none';
	}else{
		document.getElementById('back').style.display='block';
		document.getElementById('next').style.display='block';
		document.getElementById('back').onclick=function(){
					move('back');
					return false;
		}		
		document.getElementById('next').onclick=function(){
					move('next');
					return false;
		}
		document.getElementById('hide').onclick=function(){
					chooseHide();
					return false;
		}
	}
	document.getElementById('hide').style.display='block';
	document.getElementById('choosecontent').innerHTML = htmlInjection;
	externalLinks();
}
function chooseHide(){
	document.getElementById('chooseandgo').style.height='72px';
	document.getElementById('choosecontent').style.margin='0';
	document.getElementById('choosecontent').innerHTML = '';
	document.getElementById('back').style.display='none';
	document.getElementById('next').style.display='none';
	document.getElementById('hide').style.display='none';	
	externalLinks();
}
function openPlayer(goTo){
	var win=window.open(goTo,"TubaFM",'width=714,height=642,resizable=no,scrollbars=no,menubar=no,outerWidth=714' );
 	win.focus();
}
function chooseFilter(filter){
	filter=filter.toLowerCase();
	radioFilter=false;
	switch(filter)
	{
		case 'wszystko':			
			radioList=new Array(31,30,29,28,9,8,4,27,18,15,2,5,25,19,16,17,1,12,14,23,20,13,6,7,3,26,21);
			break;
		case 'pop':
			radioList=new Array(31,30,28,9,4,27,18,5,25,19,12,23,20,6,7,3,26,21);
			break;
		case 'rock':
			radioList=new Array(31,30,8,15,2,16,17,1,14,13,3);
			break;
		case 'best of':
			radioList=new Array(28,29,9,4,27,18,15,2,5,25,16,17,23,21);
			break;
		case 'party':
			radioList=new Array(31,30,25,19,12,23,20,6,7,3);
			break;			
		case 'jazz':
			radioList=new Array(29,5,22,27);
			break;
		case 'kids':
			radioList=new Array(30,29,21,5,22,27);
			break;
		case 'inne':
			radioList=new Array(31,30,29,28,10,21,22,27);
			break;
		case 'zlote przeboje':
			radioList=new Array(29,28,9,4,18,15,25,16,17,23,26,27);
			radioFilter=true;
			break;
		case 'roxy':
			radioList=new Array(8,2,1,14,13);
			radioFilter=true;
			break;
		case 'kiss':
			radioList=new Array(19,6,7);
			radioFilter=true;
			break;
		case 'blue':
			radioList=new Array(12,20);
			radioFilter=true;
			break;
		default:
			radioList=new Array(31,30,29,28,9,8,4,27,18,15,2,5,25,19,16,17,1,12,14,23,20,13,6,7,3,25,21,27);
			break;
	}
	globalIndex=0;
	chooserMake(radioList,globalIndex);
}
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var areas = document.getElementsByTagName("area");
 var anchors = document.getElementsByTagName("a");
 if(anchors.length>0){
	 for(var i=0; i<anchors.length; i++){
		 var anchor = anchors[i];
			if(anchor.getAttribute("classname") || anchor.getAttribute("class")){
			if(anchor.getAttribute('classname')){var anchorClass = anchor.getAttribute('classname');}
			if(anchor.getAttribute('class')){var anchorClass = anchor.getAttribute('class');}
			if((anchorClass.match('Player') || anchorClass.match('Player')) && anchor.getAttribute("rel")=="new"){
				if( anchor.getAttribute('id') != null && anchor.getAttribute('id').match('-')){
					var anchorIndex = anchor.getAttribute('id').split('-');
					if(!radioFilter){
						var imageName = 'http://images.tuba.fm/'+radio[anchorIndex[2]][2];
						if(anchorIndex[2]==10 || anchorIndex[2]==22){
							var imageName = 'http://images.tuba.fm/images/logoRadia'+anchorIndex[2]+'.png';
						}
					}						
					if(radioFilter){
						imageName = 'http://images.tuba.fm/images/logoRadia'+anchorIndex[2]+'.png';
						anchor.innerHTML = '<span><strong>'+radioNames[anchorIndex[2]]+'</strong><br/>'+radio[anchorIndex[2]][1]+'</span>';
						anchor.title = 'S³uchaj: '+radioNames[anchorIndex[2]]+' - '+radio[anchorIndex[2]][1];
					}					
					/*alert(imageName);*/
					anchor.style.backgroundImage = 'url('+imageName+')';
				}				
				anchor.onclick = function(){
					openPlayer(this.getAttribute("href"));					
					return false;
				}
		 	}else if(anchor.getAttribute("classname")=="Filter" || anchor.getAttribute("class")=="Filter"){
				anchor.onclick=function(){
					chooseFilter(this.getAttribute("title"));
					if(document.getElementById('filterSelected')){document.getElementById('filterSelected').id='';}					
					this.id='filterSelected';
					return false;					
				}
		 	}else if((anchorClass.match('Player2') || anchorClass.match('Player2')) && anchor.getAttribute("rel")=="new"){
			 	
				anchor.onclick = function(){
					openPlayer(this.getAttribute("href"));					
					return false;
				}
			}else{
			
			}
		 }      
	 }
 }
 if(areas.length>0){
	 for(var i=0; i<areas.length; i++){
		 var area = areas[i];
			if(area.getAttribute("classname") || area.getAttribute("class")){
			if(area.getAttribute('classname')){var areaClass = area.getAttribute('classname');}
			if(area.getAttribute('class')){var areaClass = area.getAttribute('class');}
			if((areaClass.match('Player2') || areaClass.match('Player2'))){
			 	area.onclick = function(){
					openPlayer(this.getAttribute("href"));					
					return false;
				}
			}else{
			
			}
		 }      
	 }
 }
}
function openPlayer(tuba){		
	var win=window.open(tuba,"TubaFM",'width=714,height=642,resizable=no,scrollbars=no,menubar=no,outerWidth=714' );
	var href=tuba.split(',');
	if(href[0].match('//')){
		href=href[0].split('//');
		href=href[1].split('/');
		href[0]=href[1];
	}
	if(href[0]!='roxy' && href[0]!='zlote_przeboje' && href[0]!='tok_fm' && href[0]!='radio_baobab' && href[0]!='madonna' && href[0]!='infomuzyka_fm' && href[0]!='swieta' && href[0]!='kiss_tv'){
		window.location.assign('http://www.tuba.fm/index.php?id=radio&pid='+href[0]);
	}
 	win.focus();
	return false;
}
function initiate(){
	externalLinks();
	var defaultRadioList = new Array(29,30,9,8,4,27,18,15,2,5,25,19,16,17,1,12,14,23,20,13,6,7,3,25,21,10,24);
	radioList = defaultRadioList;
	chooserMake(radioList,globalIndex);
}
function isEven(num) {
  return !(num % 2);
}
//window.onload = externalLinks;