
/* - tempobox.js - */
// http://www.conselhodeseguranca.al.gov.br/portal_javascripts/tempobox.js?original=1
var TempoBox=Class.create();TempoBox.prototype={photos:'#tempo-portlet img',citys:'#tempo-portlet .city',count:0,index:0,timeout:0,initialize: function(){this.photos=$$(this.photos);this.citys=$$(this.citys);this.count=this.citys.length;this.hideCitys();this.pe=new PeriodicalExecuter(this.checkImagesState.bind(this),0);var preLoad=document.createElement("div");preLoad.setAttribute('id','tempo-loading');$('tempo-portlet').appendChild(preLoad)},checkImagesState: function(){if(this.hasImagesLoaded()){this.pe.stop();$('tempo-loading').hide();this.show()}},show: function(){new Effect.Appear(this.citys[myTempoBox.index],{duration:0.5,afterFinishInternal: function(){this.timeout=setTimeout(function(){myTempoBox.fadeCity()},5000)}})},fadeCity: function(){new Effect.Fade(this.citys[myTempoBox.index],{duration:0.5,afterFinishInternal:function(){Element.hide(myTempoBox.citys[myTempoBox.index]);myTempoBox.index=(myTempoBox.index==myTempoBox.count-1)?0:myTempoBox.index+1;myTempoBox.show()}})},hideCitys: function(){this.citys.each(function(item){item.hide()})},hasImagesLoaded: function(){return this.photos.all(function(img){return(img.readyState=='complete'||img.complete||!(typeof img.naturalWidth!="undefined"&&img.naturalWidth==0))})}}
startTempoBox=function(){if($('tempo-portlet'))
myTempoBox=new TempoBox()}
Event.observe(document,"dom:loaded",startTempoBox);
