var d=document;
/*
$ = function(id) 
{
	if(!arguments[1]) 
		return document.getElementById(id);
	else 
		document.getElementById(id).style[arguments[1]]=arguments[2];
}
*/
function delItem(arr,item)
{
	for(;item<arr.length;item++) arr[item]=arr[item + 1];
	arr.length=arr.length-1;
} 

function startPainelSlide()
{
	loadImages(); 
	if(!paused)
		timeoutId = setTimeout('changeImg(1)', 6000);
} 

function viewNot()
{
	(Item[atual][1].indexOf('_blank')!=-1) ? window.open(Item[atual][1].substring(0,Item[atual][1].indexOf(' '))) : location.href=Item[atual][1];
} 

function maxImg()
{
	window.open('show_img.htm?img='+Item[atual][5],'','width='+Item[atual][6]+',height='+Item[atual][7]);
} 

function initialize()
{
	timeoutId=0;
	textareaContent=d.form_painel.select_painel.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--)
	{
		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-left:4px;" />';
// Se nao tem foto e nem link
		if(Item[i][0].length < 3 || Item[i][1].length < 3) 
			delItem(Item,i);
	}
	if(Item.length==1) 
		d.write('<style>#anterior,#proximo,#pause{visibility:hidden;}</style>');
	atual = Math.random().toString().substring(2,6) % Item.length;
} 

function startPanel()
{
	usaCredito = '';
	initialize();

	if(arguments.length > 0)
	{
		if(!isNaN(arguments[0])) 
			atual = arguments[0];
	}
	if(paused) 
	{
		imgpause='on'; 
		altpause='alt="Ligar" title="Ligar"';
	}
	else 
	{
		imgpause='off'; 
		altpause='alt="Parar" title="Parar"';
	}
	
	d.write('<div style="padding-left:9px; padding-bottom:3px;"><span id="txt1" class="tit_painel"><a href="javascript:viewNot()" class="tit_painel">'+Item[atual][2]+'</a></span></div><span id="icon-area"></span>');
	d.write('<div id="to-blend"><div id="painel_image"><a href="javascript:viewNot()"><img src="'+Item[atual][0]+'" id="imgslide" name="img1" border="0"></a></div>');
	d.write('</div>');
/*	d.write('<div id="fotog_painel" class="fotog_painel" align="right">'+Item[atual][0]+'</div>');*/
/*	d.write('<div style="padding-top:5px;"><h3><a href="javascript:viewNot()" id="p-link"><span id="txtresumo">'+Item[atual][8]+'</span></a></h3></div>'); */
	d.write('<div id="prox-ant"><a href="javascript:void(0)" id="anterior" onclick="if(okToGo)changeImg(-1)"><img src="images/seta1.jpg" border="0" /></a>');
	d.write('<a href="javascript:void(0)" id="proximo" onclick="if(okToGo)changeImg(1)"><img src="images/seta4.jpg" border="0" /></a></div>');
} 
function pauseSlide()
{
	if(paused)
	{
		$('pause').src='images/player/botao-pause1-off.gif';
		$('pause').title='Parar'; $('pause').alt = 'Parar';
		d.cookie="COOKIEpause=0;domain=.com.br;expires=Thu, 2 Aug 1970 20:47:11 UTC;"; 		
		paused=false;
		startPainelSlide();
	}
	else
	{
		clearTimeout(timeoutId);
		d.cookie="COOKIEpause=1;domain=.com.br;expires=Thu, 2 Aug 2222 20:47:11 UTC;"; 	
		$('pause').src='images/player/botao-pause1-on.gif';
		$('pause').title='Ligar'; $('pause').alt = 'Ligar';
		paused = true;
	} 
}

var okToGo=false;
var paused=(d.cookie.indexOf('COOKIEpause=1')!=-1) ? true : false;
var painelScrollStart = 1;

// painel rotativo //
function changeOpac(opacity)
{
	var obj = $('to-blend').style;
	obj.opacity = (opacity / 50);
	obj.MozOpacity = (opacity / 50);
	obj.KhtmlOpacity = (opacity / 50);
} 

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);
	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(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 
	{ 
		if(Item.length!=1) 
			blend(); 
	}

	if(!paused) 
		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][0];
	}
	okToGo = true;
}

function processReqChange ()
{
	if (request.readyState == 4 && request.status == 200)
		$('painel_image').innerHTML = '<center>'+request.responseText+'</center>';
}

var url;
var request;

function changeContent()
{
//	d.getElementById('fotog_painel').innerHTML=Item[atual][0];
//	if(usaCredito!='') $('credito').innerHTML=Item[atual][0];
//	$('icon-area').innerHTML=Item[atual][4];

	if( Item[atual][3] == 'img' ) {
		$('txt1').innerHTML='<span id="txt1" class="tit_painel"><a href="javascript:viewNot()" class="tit_painel">'+Item[atual][2]+'</a></span>';
		$('painel_image').innerHTML = '<a href="javascript:viewNot()"><img src="'+Item[atual][0]+'" id="imgslide" name="img1" border="0"></a>';
		d.img1.src=imgDsp[atual].src;
//		d.img2.alt=d.img2.title="Veja a foto ampliada";
//		$('txtresumo').innerHTML=Item[atual][8];
	}
	else {
		$('txt1').innerHTML = '';
		$('txtresumo').innerHTML = '';
		url = 'banner_player.php';
		request = new XMLHttpRequest();
		request.onreadystatechange = processReqChange;
		request.open("GET", url, true);
		request.send("");
	}
}
function checkLupa() {
	if(!Item[atual][6]) d.getElementById('lupaa').style.visibility = 'hidden';
	else
		d.getElementById('lupaa').style.visibility = 'visible';
}

var scrollGaleria;
window.onload = function () {
	startPainelSlide(); 
	if (scrollGaleria)
	{	
		initScrLyr();
		scrollGaleria = 0;
	}
}

