
Carrossel=function(opts){this.opts=opts;this.id=opts.id||'destaques';this.delay=opts.delay||6;this.width=opts.width||'400px';this.height=opts.height||'200px';this.data=opts.data||[];this.dom=$(opts.id);this.current=0;this.buildStage=function(){var target=typeof arguments[0]!=='undefined'?$(arguments[0]):document.getElementsByTagName('body')[0];var box=new Element('div',{id:this.id});box.style.width=this.width;box.style.height=this.height;box.style.overflow='hidden';target.appendChild(box);this.dom=box;};this.dumpData=function(){var img=false;var a=false;var databox=new Element('div');databox.className='rawdata';for(var i=0,len=this.data.length;i<len;i++){img=new Element('img',{src:this.data[i].img,alt:this.data[i].title,title:this.data[i].title});img.style.border='0';a=new Element('a',{href:unescape(this.data[i].url)});a.appendChild(img);databox.appendChild(a);}
this.dom.appendChild(databox);}.bind(this);this.buildControls=function(){if(this.data.length<=1){return;}
var controlBox=document.createElement('ul');controlBox.className='controls';var control=false;var lnk=false;for(var i=0,len=this.data.length;i<len;i++){control=new Element('li');lnk=new Element('a',{href:this.data[i].url,title:'#'+(i+1)+' '+this.data[i].title,onClick:'javascript:return false;',className:'choices'}).update(''+(i+1));Event.observe(lnk,'mousedown',this.switchTo.bindAsEventListener(this,i));control.appendChild(lnk);controlBox.appendChild(control);}
control=new Element('li');lnk=new Element('a',{href:'javascript:;',onClick:'javascript:return false;',title:'< anterior',className:'prev'}).update('&larr;');Event.observe(lnk,'mousedown',this.switchToPrev.bindAsEventListener(this));control.appendChild(lnk);controlBox.appendChild(control);control=new Element('li');lnk=new Element('a',{href:'javascript:;',onClick:'javascript:return false;',title:'seguinte >',className:'next'}).update('&rarr;');Event.observe(lnk,'mousedown',this.switchToNext.bindAsEventListener(this));control.appendChild(lnk);controlBox.appendChild(control);$(this.id).appendChild(controlBox);};this.switchTo=function(e){var index=arguments[1]||0;var lst=Element.select(this.dom,'.rawdata a');var target=lst[index];if(typeof target=='undefined'){return;}
var limelight=Element.select(this.dom,'.stage a')[0];limelight.parentNode.insertBefore(target.cloneNode(true),limelight);limelight.remove();var prevControl=Element.select(this.dom,'.controls a.current');if(prevControl.length!==0){Element.removeClassName(prevControl[0],'current');}
var controls=Element.select(this.dom,'.controls a');Element.addClassName(controls[index],'current');this.current=index;}.bind(this);this.switchToPrev=function(e){this.current=this.current==0?this.data.length-1:--this.current;this.switchTo(e,this.current);}.bind(this);this.switchToNext=function(e){this.current=this.current==this.data.length-1?0:++this.current;this.switchTo(e,this.current);}.bind(this);this.autoNext=function(){if(this.data.length<=1){return;}
var skip=arguments.length>0?arguments[0]:false;if(skip!==true){this.switchToNext();}
setTimeout(this.autoNext.bind(this),this.delay*1000);}.bind(this);};var destaques=false;if(typeof onDomReady=='undefined'){var onDomReady=[];}
onDomReady[onDomReady.length]=function(){destaques=new Carrossel({id:'mail-destaques',delay:8,width:'220px',height:'160px'});if(typeof rawData!='undefined'){destaques.data=rawData;destaques.dumpData();destaques.buildControls();destaques.switchTo(destaques.current);destaques.autoNext(true);}};
