/**
 * @author gold
 */

var UOLLib=window.UOLLib||{};
	UOLLib.rotativoDeChamadas={
	painel:null,itens:null,botoes:null,botoesTxts:{
		next:"proximo",prev:"anterior",stop:"parar",play:"executar"
		},botoesRefClickUOL:"",ativado:0,anterior:0,proximo:0,navMSIE:!!navigator.userAgent.match(/MSIE/g),timeOut:null,timer:6,animando:false,banner:document.createElement("div"),showBanner:false,contaTrocas:0,init:
		function(A){
			this.painel=document.getElementById(A["id"]);
			this.timer=A["timer"]||this.timer;
			this.botoesRefClickUOL=A["botoesRefClickUOL"]||this.botoesRefClickUOL;
			this.botoesTxts=A["botoesTxts"]||this.botoesTxts;
			if(typeof mostrabanner=="undefined"){
				mostrabanner=0
				}
			this.showBanner=showBanner=(document.cookie.indexOf("rotativoDeChamadasNoBanner=1")==-1)?true:false;
			this.itens=this.painel.getElementsByTagName("li");
			this.setNavegacao(this.ativado);
			this.aplicarSombras();
			if(this.itens.length==1){
				A["startOff"]=true
				}
				else
				{
					this.montarBotoes()
				}
				if(document.cookie.indexOf("rotativoDeChamadasStop=1")!=-1){
					A["startOff"]=true
					}
					if(!A["startOff"]){this.stopPlay()
					}
					else
					{
						this.setBtStopPlay("play")
						}
					}
					,events:{
						preventDefault:
						function(A){
							if(A.preventDefault){
								A.preventDefault()
								}
								else
								{
									A.returnValue=false
									}
									}
									,add:
									function(C,B,A){
										if(document.attachEvent){C.attachEvent("on"+B,A)}
										else
										{
											if(document.addEventListener){
												C.addEventListener(B,A,true)}}}},stopPlay:
												function(A){
													if((!A&&this.timeOut==null)||(A&&this.timeOut!=null)){
														clearInterval(this.timeOut);
														this.timeOut=setInterval(function(){
															UOLLib.rotativoDeChamadas.navegar(1)},UOLLib.rotativoDeChamadas.timer*1000);
															document.cookie="rotativoDeChamadasStop=0; path=/";
															this.setBtStopPlay("stop")
															}
															else
															{
																document.cookie="rotativoDeChamadasStop=1; path=/";clearInterval(this.timeOut);
																this.timeOut=null;
																this.setBtStopPlay("play")}},setBtStopPlay:
																function(A){
																	if(this.botoes!=null){
																		var B=this.botoes.getElementsByTagName("a")[1];
																		B.className="bt"+A;B.innerHTML=this.botoesTxts[A]}},setNavegacao:
																		function(A){
																			this.ativado=(parseInt(A)+(this.ativado||this.itens.length))%this.itens.length;this.anterior=((this.ativado||this.itens.length)-1)%this.itens.length;this.proximo=((this.ativado||this.itens.length)+1)%this.itens.length},fadeIO:
																			function(B,D,C){if(D){B.style.opacity=0;B.style.filter="Alpha(Opacity=0)"}else{B.style.opacity=1;B.style.filter="Alpha(Opacity=100)"}UOLLib.rotativoDeChamadas.animando=true;for(var A=1;A<=5;A++){setTimeout(function(E){return function(){if(UOLLib.rotativoDeChamadas.navMSIE){B.style.filter="Alpha(Opacity="+(D?20*E:100-20*E)+")"}else{B.style.opacity=(D?0.2*E:1-0.2*E)}if(E==5){UOLLib.rotativoDeChamadas.animando=false;if(UOLLib.rotativoDeChamadas.navMSIE){B.style.filter="none"}if(typeof C=="function"){C()}}}}(A),75*A)}},fecharBanner:function(){document.cookie="rotativoDeChamadasNoBanner=1; path=/";this.showBanner=false;clearTimeout(UOLLib.rotativoDeChamadas.bannerFadeOutTimer);this.bannerFadeOut()},bannerFadeOut:function(){this.fadeIO(this.banner,false,function(){UOLLib.rotativoDeChamadas.banner.style.display="none";UOLLib.rotativoDeChamadas.botoes.style.display="block"});this.fadeIO(this.botoes,true,null)},navegar:function(B){var A=this.ativado;this.removerBanner=false;this.contaTrocas++;if(mostrabanner==1&&this.showBanner&&this.contaTrocas>0&&this.contaTrocas%this.itens.length==0){this.banner.style.display="block";this.banner.className="banner";this.banner.innerHTML='<a href="'+mostrabannerLINK+'" target="_blank"><img src="'+mostrabannerIMG+'" border="0" /></a><div class="rodape"><img src="http://home.img.uol.com.br/h3/pub_h_120_b.gif" class="txtPublicidade" border="0" /><a href="javascript:void(0)" onclick="UOLLib.rotativoDeChamadas.fecharBanner()"><img src="http://home.img.uol.com.br/h3/banner-fechar.gif" border="0" /></div>';this.painel.appendChild(this.banner);this.fadeIO(this.banner,true,function(){UOLLib.rotativoDeChamadas.botoes.style.display="none"});this.fadeIO(this.botoes,false,null);if(this.timeOut!=null){UOLLib.rotativoDeChamadas.bannerFadeOutTimer=setTimeout(function(){UOLLib.rotativoDeChamadas.bannerFadeOut()},UOLLib.rotativoDeChamadas.timer*1000)}}else{this.setNavegacao(B);this.itens[this.ativado].className=this.itens[this.ativado].className.replace(/desativado/g,"");this.itens[this.ativado].style.zIndex=3;this.fadeIO(this.itens[this.ativado],true,function(){UOLLib.rotativoDeChamadas.itens[A].className="desativado"},true);this.itens[A].style.zIndex=2;this.writeBotoesHTML();if(this.timeOut==null){this.setBtStopPlay("play")}else{this.setBtStopPlay("stop")}}},montarBotoes:function(){this.botoes=document.createElement("div");this.botoes.className="botoesNavegacao";this.writeBotoesHTML();this.painel.appendChild(this.botoes)},aplicarSombras:function(){var B=document.createElement("div");B.className="sombra";for(var A=0;A<this.itens.length;A++){if(A>0){this.itens[A].className+=" desativado"}this.itens[A].appendChild(B.cloneNode(true))}},writeBotoesHTML:function(){this.botoes.innerHTML="<a rel='-1' href='"+this.itens[this.anterior].getElementsByTagName("a")[0].href+"' class='anterior' name='"+this.botoesRefClickUOL+"'>"+this.botoesTxts.prev+"</a>      <a rel='0' href='"+this.itens[this.ativado].getElementsByTagName("a")[0].href+"' class='' name='"+this.botoesRefClickUOL+"'></a>      <a rel='+1' href='"+this.itens[this.proximo].getElementsByTagName("a")[0].href+"' class='proximo' name='"+this.botoesRefClickUOL+"'>"+this.botoesTxts.next+"</a>";var B=this.botoes.getElementsByTagName("a");for(var A=0;A<B.length;A++){this.events.add(B[A],"click",function(C){UOLLib.rotativoDeChamadas.events.preventDefault(C);if(C.srcElement){C.target=C.srcElement}if(C.target.rel==0){UOLLib.rotativoDeChamadas.stopPlay()}else{if(UOLLib.rotativoDeChamadas.animando==false){UOLLib.rotativoDeChamadas.navegar(C.target.rel);UOLLib.rotativoDeChamadas.stopPlay(true)}}})}}}

