
/* - tickerbox.js - */
// http://www.cienciaetecnologia.al.gov.br/portal_javascripts/tickerbox.js?original=1
var Ticker=Class.create();Ticker.prototype={containerWidth:"400px",containerHeight:"52px",filePrevImage:"prevlabel.gif",fileNextImage:"nextlabel.gif",photos:"#tickerbox .ticker",countPhotos:0,index:0,timeout:0,initialize: function(){this.photos=$$(this.photos);this.countPhotos=this.photos.length;this.hideAllPhotos();this.pe=new PeriodicalExecuter(this.checkImagesState.bind(this),0);$('tickerbox').style.width=this.containerWidth;$('tickerbox').style.height=this.containerHeight;var tickerPreLoad=document.createElement("div");tickerPreLoad.setAttribute('id','ticker-loading');$('tickerbox').appendChild(tickerPreLoad);var prev=document.createElement("img");prev.setAttribute('id','prev');prev.setAttribute('src',this.filePrevImage);$('tickerbox').appendChild(prev);new Effect.Opacity(prev,{to:0.2,duration:0});prev.onmouseover=function(){new Effect.Opacity(prev,{to:1,duration:0})}
prev.onmouseout=function(){new Effect.Opacity(prev,{to:0.2,duration:0})}
var next=document.createElement("img");next.setAttribute('id','next');next.setAttribute('src',this.fileNextImage);$('tickerbox').appendChild(next);new Effect.Opacity(next,{to:0.2,duration:0});next.onmouseover=function(){new Effect.Opacity(next,{to:1,duration:0})}
next.onmouseout=function(){new Effect.Opacity(next,{to:0.2,duration:0})}
var comments=document.createElement("div");comments.setAttribute('id','comments');$('tickerbox').appendChild(comments);new Effect.Opacity($('comments'),{to:0.5,duration:0})},checkImagesState: function(){if(this.hasImagesLoaded()&&$('next')&&$('prev')){this.pe.stop();$('ticker-loading').hide();this.show()}},show: function(){this.lockButtons();$('comments').innerHTML=this.photos[this.index].alt;new Effect.Appear(this.photos[this.index],{duration:0.5,afterFinishInternal: function(){if(myTicker.photos[myTicker.index].alt!=""){Element.show('comments')
new Effect.Move('comments',{x:0,y:-50,duration:0.2,afterFinishInternal:function(){myTicker.unLockButtons()}})}else{myTicker.unLockButtons()}
myTicker.timeout=setTimeout(function(){myTicker.hide(false)},5000)}})},hide: function(prev){this.lockButtons();if(this.photos[this.index].alt!=""){new Effect.Move('comments',{x:0,y:50,duration:0.2,afterFinishInternal: function(){Element.hide('comments');myTicker.fadePhoto(prev)}})}else{myTicker.fadePhoto(prev)}},fadePhoto: function(prev){new Effect.Fade(this.photos[this.index],{duration:0.5,afterFinishInternal:function(){Element.hide(myTicker.photos[myTicker.index]);if(prev==true)
myTicker.index=(myTicker.index==0)?myTicker.countPhotos-1:myTicker.index-1;else
myTicker.index=(myTicker.index==myTicker.countPhotos-1)?0:myTicker.index+1;myTicker.show()}})},lockButtons: function(){$('prev').onclick=function(){}
$('next').onclick=function(){}},unLockButtons: function(){$('prev').onclick=function(){clearTimeout(myTicker.timeout);myTicker.hide(true)}
$('next').onclick=function(){clearTimeout(myTicker.timeout);myTicker.hide(false)}},hideAllPhotos: function(){this.photos.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))})}}
startTicker=function(){if($("tickerbox")){myTicker=new Ticker()}}
Event.observe(document,"dom:loaded",startTicker);
