var d=document;
$ = function(id) {
	if(!arguments[1]) return document.getElementById(id);
	else document.getElementById(id).style[arguments[1]]=arguments[2];
}

bannerhref='';
function delChamada(arr,Chamada){
for(;Chamada<arr.length;Chamada++) arr[Chamada]=arr[Chamada + 1];
arr.length=arr.length-1;
} function goURL(){
if (bannerhref!='') {window.open(bannerhref)} else {
(Chamada[atual][3].indexOf('_blank')!=-1) ? window.open(Chamada[atual][3].substring(0,Chamada[atual][3].indexOf(' '))) : location.href=Chamada[atual][3];
}
} function startSlide(){ 
loadImages();
if(!paused) timeoutId=setTimeout('changeImg(1)',6000);
} function inicializar(){
timeoutId=0;
textareaContent=d.formulario.select_editavel.value.split(/[\r\n]/i);
Chamada = new Array();
for(x=0,y=0;x<textareaContent.length;x++){ 
	if(textareaContent[x].length>30) Chamada[y++]=textareaContent[x].split('|');
	}
for(i=Chamada.length-1;i>=0;i--){
	Chamada[i][0]=Chamada[i][0].replace(/([ \n\t\r])+/, " ");
	Chamada[i][4]=(Chamada[i][4].length<3) ? '' : '<img src="http://img.terra.com.br/i/beleza_novo/'+Chamada[i][4]+'" border="0" style="margin-left:4px;" />';
	if(Chamada[i][1].length<3||Chamada[i][3].length<3||Chamada[i][2].length<3||Chamada[i][0].length<2) delChamada(Chamada,i);
	}
if(Chamada.length==1) d.write('<style>#anterior,#proximo,#pause{visibility:hidden;}</style>');
atual = Math.random().toString().substring(2,6) % Chamada.length;
} function startPanel(){
usaCredito = '';
inicializar();
if(arguments.length>0){
	if(!isNaN(arguments[0])) atual = arguments[0];
	}
if(paused) {imgpause='on'; altpause='alt="Play" title="Play"';}
else {imgpause='off'; altpause='alt="Parar" title="Parar"';}
d.write('<div id="to-blend">'+usaCredito+'<a href="javascript:goURL()"><img src="'+Chamada[atual][1]+'" id="imgslide" name="img1" border="0" title="'+Chamada[atual][0]+'" alt="'+Chamada[atual][0]+'"></a>');
d.write('<h2><a href="javascript:goURL()" id="p-link"><span id="txt1">'+Chamada[atual][2]+'</span><span id="icon-area">'+Chamada[atual][4]+'</span></a></h2></div>');
d.write('<div id="botoes"><a href="javascript:void(0)" id="anterior" onclick="if(okToGo)changeImg(-1)"><img src="http://img.terra.com.br/i/beleza_novo/ant.gif" border="0" /></a>');
d.write('<img src="http://img.terra.com.br/i/beleza_novo/pause-'+imgpause+'.gif" onclick="pausar()" id="pause" '+altpause+' />');
d.write('<a href="javascript:void(0)" id="proximo" onclick="if(okToGo)changeImg(1)"><img src="http://img.terra.com.br/i/beleza_novo/pro.gif" border="0" /></a><div id="banner-painel"></div></div>');
} function pausar(){
if(paused){
//	$('pause').src='pause-off.gif';
//	$('pause').title='Parar'; $('pause').alt = 'Parar';
	paused=false;
	startSlide();
}else{
	clearTimeout(timeoutId);
//	$('pause').src='pause-on.gif';
//	$('pause').title='Ligar'; $('pause').alt = 'Ligar';
	paused = true;
} }

var okToGo=false;
var paused= false;
onload=startSlide;

// Slide //
var cont=0;
var showBanner = false;

function changeOpac(opacity){
//var obj = $('to-blend').style;
//obj.opacity=(opacity/101);
obj.MozOpacity=(opacity/101);
//obj.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 changeImg(id){
clearTimeout(timeoutId);
cont++;
//if(cont>1) { showBanner(id); return; }
atual+=parseInt(id);

if(atual>Chamada.length-1) atual=0;
if(atual<0) atual=Chamada.length-1;
if(imgDsp[atual].complete==false){
	atual--;
	timeoutId = setTimeout('changeImg('+id+')',500);
	return;
	} 
if(d.all && navigator.userAgent.indexOf('Opera')==-1){
	try {
	oDiv = $('to-blend');
	oDiv.style.filter="blendTrans(duration=0.7)";
   	oDiv.filters.blendTrans.apply();
    oDiv.filters.blendTrans.play();
	changeContent();
	} catch(e) { changeContent(); }
} else { blend(); }
if(!paused) timeoutId=setTimeout('changeImg(1)',6000);
} 

var mostrabanner=0;
function loadImages(){
imgDsp = new Array();
for(n=0;n<Chamada.length;n++){
	imgDsp[n]=new Image();
	imgDsp[n].src=Chamada[n][1];
	}
okToGo = true;

}
function changeContent(){
if(cont>3&&showBanner&&mostrabanner==1) {
	$('proximo').style.display = $('anterior').style.display = $('pause').style.display = 'none';	
	$('txt1').innerHTML='';
	if(usaCredito!='') $('credito').innerHTML='';
	$('icon-area').innerHTML='';
	atual--;
	cont=0;
} else {
	d.img1.style.height = 'auto';
	$('proximo').style.display = $('anterior').style.display = $('pause').style.display = 'block';	
	d.img1.src=imgDsp[atual].src;
	bannerhref='';
	d.img1.alt=d.img1.title=Chamada[atual][0];
	$('txt1').innerHTML=Chamada[atual][2];
	if(usaCredito!='') $('credito').innerHTML=Chamada[atual][0];
	$('icon-area').innerHTML=Chamada[atual][4];
 }


}