function delItem(arr,item)
{
for (;item<arr.length;item++) arr[item] = arr[item + 1];
arr.length=arr.length-1;
}

// pop radio 
function pop(url) {
clk = url.replace(/(.*&u=).*/,"$1");
if(arguments[0].indexOf('abreradio.htm')!=-1) {
	url = clk+"http://app.radio.musica.uol.com.br/radiouol/player/frameset.php?opcao=playlist&nomeplaylist="+arguments[0].replace(/.*?canal=([0-9]*)/i,'$1')
	window.open(url,'popplaylist','width=480,height=350,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
} else if (arguments[0].indexOf('play.htm')!=-1) {
	player = ((arguments[1].indexOf("_128")!=-1) ? arguments[1].slice(0,-4) : arguments[1].slice(0,-3));
	url = clk+"http://radio.musica.uol.com.br/players/detector.htm?au="+arguments[1]+"&htm="+player+"_player";
	feat = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,title=yes,resizable='+((navigator.appName.indexOf("Explorer")!=-1) ? 'no' : 'yes')+',width=215,height=380';
	window.open(url,'audio_'+arguments[1],feat);
} else {
	return false; //uolhome
} }

function goURL()
{
 if(Item[atual][3].indexOf('_blank')!=-1) { window.open(Item[atual][3].substring(0,Item[atual][3].indexOf(' '))); }
 else if (Item[atual][3].indexOf('player')!=-1 || Item[atual][3].indexOf('abreradio')!=-1) { pop(Item[atual][3]); } 
 else { location.href=Item[atual][3]; }
}

function changeContent() 
{
document.img1.src = imgDsp[atual].src;
document.img1.alt = document.img1.title = Item[atual][0];
document.getElementById('txt1').innerHTML = Item[atual][2];
if(usaCredito!='') document.getElementById('credito').innerHTML = Item[atual][0];
document.getElementById('icon-area').innerHTML = Item[atual][4];
}

function changeImg(id)
{
clearTimeout(timeoutId);
atual+=parseInt(id);
if(atual>Item.length-1) atual = 0;
if(atual<0) atual = Item.length-1;
if(imgDsp[atual].complete==false) {
	atual--;
	timeoutId = setTimeout('changeImg('+id+')',500); 
	return; 
	} 
if(document.all && navigator.userAgent.indexOf('Opera')==-1) {
	try {
		document.images.img1.style.filter='blendTrans(duration=1)';
		document.images.img1.filters.blendTrans.Apply();
		document.images.img1.filters.blendTrans.Play();
		changeContent();
		} catch(e) { changeContent(); }
	}
else { blend(); }

timeoutId = setTimeout('changeImg(1)',6000)
}

function startSlide()
{ 
loadImages();
timeoutId = setTimeout('changeImg(1)',6000); 
}

function loadImages()
{
imgDsp = new Array();
for(n=0;n<Item.length;n++) {
	imgDsp[n] = new Image();
	imgDsp[n].src = Item[n][1];
	}
okToGo = true;
}

function initialize()
{
timeoutId = 0;
textareaContent = document.form_cr.select_cr.value.split(/[\r\n]/i);
Item = new Array();
for(x=0,y=0;x<textareaContent.length;x++) { 
	if(textareaContent[x].length>30) Item[y++] = textareaContent[x].split('|'); 
	}
for(i=Item.length-1;i>=0;i--) { // remove arrays com informação faltando
	Item[i][0] = Item[i][0].replace(/([ \n\t\r])+/, " ");
	Item[i][4] = (Item[i][4].length<3) ? '' : '<img src="'+Item[i][4]+'" border="0" style="margin-right:4px;">'; // preenche as chamadas com/sem icone
	if(Item[i][1].length<3||Item[i][3].length<3||Item[i][2].length<3||Item[i][0].length<2) delItem(Item,i);
	}
if(Item.length==1) document.write('<style>#anterior,#proximo{visibility:hidden;}</style>'); // se só tem 1 imagem, remove proximo/anterior
atual = Math.random().toString().substring(2,6) % Item.length; // escolhe uma imagem inicial randomicamente
}

function changeOpac(opacity) 
{
var object = document.getElementById('to-blend').style; 
object.opacity = (opacity / 101);
object.MozOpacity = (opacity / 101);
object.KhtmlOpacity = (opacity / 101);
}

function blend(imagefile)
{
var speed = 7;
var timer = 0;
for(i = 100; i > 0; i-=2) setTimeout('changeOpac('+i+')', timer++ * speed);
setTimeout('changeContent()', timer * speed);
for(i = 0; i <= 100; i+=2) setTimeout('changeOpac('+i+')', timer++ * speed);
}

function startPanel()
{
usaCredito = '';
initialize();
if(arguments.length>0) {
	if(!isNaN(arguments[0])||!isNaN(arguments[1])) atual = arguments[0]; // para setar qual foto entra primeiro (sem ser randomico)
	if(arguments[0]=='com-credito'||arguments[1]=='com-credito') usaCredito = '<div id="credito">'+Item[atual][0]+'</div>';
	}
document.write('<div id="to-blend">'+usaCredito+'<a href="javascript:goURL()"><img src="'+Item[atual][1]+'" id="imgslide" name="img1" border="0" title="'+Item[atual][0]+'" alt="'+Item[atual][0]+'"></a>'); 
document.write('<h2><a href="javascript:goURL()" id="p-link"><span id="icon-area">'+Item[atual][4]+'</span><span id="txt1">'+Item[atual][2]+'</span></a></h2></div>');
document.write('<a id="anterior" onclick="if(okToGo)changeImg(-1)"><img src="http:\/\/ba.i.uol.com.br/botao_anterior.gif" border="0"></a>');
document.write('<a id="proximo" onclick="if(okToGo)changeImg(1)"><img src="http:\/\/ba.i.uol.com.br/botao_proximo2.gif" border="0"></a>');
}

okToGo = false;
onload = startSlide;
