(function(){var e,h,f,c,a,d,g;e={byId:function(b){return YAHOO.util.Dom.get(b)},query:function(){return YAHOO.util.Selector.query.apply(window,arguments)},addClass:function(i,b){return YAHOO.util.Dom.addClass(i,b)},hasClass:function(i,b){return YAHOO.util.Dom.hasClass(i,b)},removeClass:function(i,b){return YAHOO.util.Dom.removeClass(i,b)},setStyle:function(b,j,i){return YAHOO.util.Dom.setStyle(b,j,i)},isNull:function(b){return(b===null)},isArray:function(b){return YAHOO.lang.isArray(b)},isObject:function(b){return(typeof(b)==="object"&&!e.isArray(b)&&!e.isNull(b))},later:function(k,j,i,b,l){return YAHOO.lang.later(k,j,i,b,l)},jsonEncode:function(b){return YAHOO.lang.JSON.stringify(b)},connect:function(o,l,n,b){var k,m,j;if(e.isObject(b)){for(k in b){if(b.hasOwnProperty(k)){m=b[k];if(e.isObject(m)||e.isArray(m)){j+="&"+k+"="+e.jsonEncode(m)}else{j+="&"+k+"="+m}}}}else{j=b}return YAHOO.util.Connect.asyncRequest(o,l,n,j)},addEvent:function(k,j,i,l,b){return YAHOO.util.Event.addListener(k,j,i,l,b)},removeEvent:function(j,i,b){return YAHOO.util.Event.removeListener(j,i,b)},CreateEvent:function(b,i){return new YAHOO.util.CustomEvent(b,i)},createNode:function(b,i,j){var l,k=document.createElement(b);j=e.byId(j);for(l in i){if(i.hasOwnProperty(l)){k[l]=i[l]}}if(j){return j.appendChild(k)}return k},Animation:function(i,b,j,k){j=j||1;if(!k){k=null}return new YAHOO.util.Anim(i,b,j,k)},Easing:YAHOO.util.Easing,xmlGet:function(b,k,j){var i;if(!k){return false}i=k.getElementsByTagName(b);if(i.length===0){return false}return(j)?i[0]:i},xmlGetText:function(b,i){var j=e.xmlGet(b,i,true);return(j)?j.childNodes[0].nodeValue:null},getBrowser:function(){var m=document.getElementsByTagName("html")[0],k=["webkit","firefox","ie","opera"],n,o,l,b,j;for(l=0,b=k.length;l<b;++l){n=new RegExp("("+k[l]+")\\/*\\s*(\\d+)");o=n.exec(navigator.userAgent.toLowerCase());if(o&&o.length===3){return o[1]+o[2]}}return false}};h=function(b){this.cfg={};this.cfg.loadingImagePath="/BannerGadget/css/bin/loading_images.png";this.timer=null;this.isRendered=false;this.images=[];this.nodes={};this.nodes.domNode=e.byId(b);this.events={onReadXML:new e.CreateEvent("onReadXML"),onLoad:new e.CreateEvent("onLoad"),onRender:new e.CreateEvent("onRender"),onImageLoad:new e.CreateEvent("onImageLoad"),onTransitionStart:new e.CreateEvent("onTransitionStart"),onTransitionEnd:new e.CreateEvent("onTransitionEnd"),onImageShow:new e.CreateEvent("onImageShow"),onLegendShow:new e.CreateEvent("onLegendShow")};this._init()};h.prototype={_init:function(){var b=this;this.loadingImageLoaded=false;this.images.loadingImage=new Image();this._addEvents();this.images.loadingImage.onreadystatechange=function(i){if(this.readyState==="complete"||this.readyState==="loaded"){this.onreadystatechange=function(){};if(b.loadingImageLoaded===true){return}b.loadingImageLoaded=true;b._build()}};e.addEvent(this.images.loadingImage,"load",function(j,i){e.removeEvent(this,"load");if(i.loadingImageLoaded===true){return}i.loadingImageLoaded=true;i._build()},this,false);this.images.loadingImage.src=this.cfg.loadingImagePath;e.later(500,this,this._forceBuild,[],false);this.events.onLoad.fire(this)},_forceBuild:function(){if(!this.loadingImageLoaded){this.loadingImageLoaded=true;this._build()}},_build:function(){if(!this.nodes.domNode){return}this.nodes.images=e.createNode("div",{className:"gcb_image"},this.nodes.domNode);this.nodes.loadingImage=e.createNode("div",{className:"gcb_image_loading"},this.nodes.images);this.nodes.loadingImage.appendChild(this.images.loadingImage);this.nodes.loadingImageOverlay=e.createNode("div",{className:"gcb_image_loading_overlay"},this.nodes.loadingImage);this.nodes.firstImage=e.createNode("div",{className:"gcb_image_current"},this.nodes.images);this.nodes.secondImage=e.createNode("div",{className:"gcb_image_next"},this.nodes.images);this.nodes.legend=e.createNode("div",{className:"gcb_image_legend"},this.nodes.images);this.nodes.link=e.createNode("a",{className:"gcb_image_link"},this.nodes.images);this.nodes.navigation=e.createNode("div",{className:"gcb_navigation"},this.nodes.domNode);this.nodes.previousImage=e.createNode("div",{className:"gcb_navigation_arrow previous"},this.nodes.navigation);this.nodes.paginator=e.createNode("div",{className:"gcb_navigation_paginator"},this.nodes.navigation);this.nodes.nextImage=e.createNode("div",{className:"gcb_navigation_arrow next"},this.nodes.navigation);this.nodes.thumbnails=e.createNode("ul",{className:"gcb_navigation_paginator_thumbs"},this.nodes.paginator);this.isRendered=true;this.events.onRender.fire(this)},_addEvents:function(){this.events.onRender.subscribe(this._readXML,this,true);this.events.onRender.subscribe(this._createAnimations,this,true);this.events.onRender.subscribe(this._showLoading,this,true);this.events.onReadXML.subscribe(this._loadImages,this,true);this.events.onImageShow.subscribe(this._controller,this,true);this.events.onReadXML.subscribe(this._addPaginator,this,true)},_removeEvents:function(){e.removeEvent(window,"load",this._readXML)},_readXML:function(){var i,b,j;i=e.query("meta[name=bannerXML]","",true);if(!i){return}b=i.getAttribute("content");j={scope:this,timeout:3000,success:this._parseXML,failure:function(){}};e.connect("GET",b,j,"")},_parseXML:function(m){var p,b,n,r,q,l,j,o=[],s=[],k=0;p=m.responseXML;j=e.xmlGet("details",p,true);if(!j||!j.getAttribute("expositiontime")){this._hideGadget();return}this.nodes.domNode=this.nodes.domNode||e.query(".gcb_container","",true);if(!this.nodes.domNode){console.error("Dom node for banner gadget not found!");return}this.nodes.domNode.className=(this.nodes.domNode.className)?this.nodes.domNode.className+" gcb_container_sized":"gcb_container_sized";this.cfg.expositionTime=parseFloat(j.getAttribute("expositiontime"),10);this.cfg.transitionTime=parseFloat(j.getAttribute("transitionTime"),10);this.cfg.transitionType=j.getAttribute("transitionType");b=e.xmlGet("imagem",p);for(n=0,r=b.length;n<r;++n){q=b[n];if(q.isdefault){k=n}s.push(q)}if(k!==0){o=s.slice(k).concat(s.slice(0,k))}else{o=s}for(n=0,r=o.length;n<r;++n){q=o[n];l={path:q.getAttribute("img"),legend:q.getAttribute("leg"),link:q.getAttribute("picLink"),target:q.getAttribute("linkTarget"),type:"image"};if(l.legend.match(/(http|https):\/\/?/g)&&l.link===""){l.link=l.legend;l.legend="";l.target="_self"}this.images.push(l)}this.events.onReadXML.fire()},_loadImages:function(){var j,b,m,l,k=this;l=function(i){if(this.readyState==="complete"||this.readyState==="loaded"){this.onreadystatechange=function(){};k._controller()}};for(j=0,b=this.images.length;j<b;++j){m=this.images[j];m.file=new Image();m.file.src=m.path;m.file.onreadystatechange=l;if(m.file.readyState==="complete"||m.file.readyState==="loaded"){this._controller()}if(!m.file.readyState){e.addEvent(m.file,"load",this._controller,this,true)}}},_runTransition:function(b){var i=e.getBrowser();if(!this.cfg.transitionType||!this.transitions[this.cfg.transitionType]){this.cfg.transitionType="dissolve"}this._hideLoading();this.events.onTransitionStart.fire();this.isAnimated=true;if(i.indexOf("ie")<0){e.setStyle(this.nodes.legend,"opacity",0)}else{e.setStyle(this.nodes.legend,"visibility","hidden")}this.nodes.legend.innerHTML=b.legend;this.transitions[this.cfg.transitionType].call(this,b)},_createAnimations:function(){this.firstImageAnimation=new e.Animation(this.nodes.firstImage,{},this.cfg.transitionTime*1000,e.Easing.easeOut);this.secondImageAnimation=new e.Animation(this.nodes.secondImage,{},this.cfg.transitionTime*1000,e.Easing.easeOut);this.legendAnimation=new e.Animation(this.nodes.legend,{},this.cfg.transitionTime*1000,e.Easing.easeOut);this.firstImageAnimation.onComplete.subscribe(this._fireOnTransitionEnd,this,true);this.secondImageAnimation.onComplete.subscribe(this._fireOnTransitionEnd,this,true);this.legendAnimation.onComplete.subscribe(function(){e.setStyle(this.nodes.legend,"visibility","visible")},this,true)},transitions:{dissolve:function(b){var i;this.foreground=e.query(".gcb_image_current",this.nodes.domNode,true);this.background=e.query(".gcb_image_next",this.nodes.domNode,true);i=b.path;this._addLink(b);this.background.style.backgroundImage="url("+i+")";e.setStyle(this.background,"opacity",1);if(!this.firstImageAnimation){this._createAnimations()}if(this.foreground===this.firstImageAnimation.getEl()){this.firstImageAnimation.attributes={opacity:{to:0}};this.firstImageAnimation.animate()}else{this.secondImageAnimation.attributes={opacity:{to:0}};this.secondImageAnimation.animate()}}},_exposing:function(){this.timer=e.later(this.cfg.expositionTime*1000,this,this._fireOnImageShow)},_fireOnImageShow:function(){this.isAnimated=false;this.events.onImageShow.fire()},_showLegend:function(){var b=e.getBrowser();if(b.indexOf("ie")<0){this.legendAnimation.attributes={opacity:{to:1}}}this.legendAnimation.animate()},_fireOnTransitionEnd:function(){this.foreground.className="gcb_image_next";this.background.className="gcb_image_current";this._showLegend();this.events.onTransitionEnd.fire();this._exposing()},_controller:function(){var b;if(!this.nextImageIndex){this.nextImageIndex=0}b=this.images[this.nextImageIndex];if(!this.isRendered||this.isAnimated){return}this._runTransition(b);this._updatePaginator(this.nextImageIndex);this.nextImageIndex=(this.nextImageIndex+1)%this.images.length},next:function(i,b){if(b.timer&&b.timer.cancel){b.timer.cancel()}b._fireOnImageShow()},previous:function(i,b){if(b.timer&&b.timer.cancel){b.timer.cancel()}if(b.nextImageIndex-2>=0){b.nextImageIndex=(b.nextImageIndex-2)%b.images.length}else{b.nextImageIndex=b.images.length+b.nextImageIndex-2}b._fireOnImageShow()},goTo:function(b,i){if(i.scope.timer&&i.scope.timer.cancel){i.scope.timer.cancel()}i.scope.nextImageIndex=i.imageIndex%i.scope.images.length;i.scope._fireOnImageShow()},_showLoading:function(){this.nodes.loadingImage.style.display="block"},_hideLoading:function(){this.nodes.loadingImage.style.display="none"},_addPaginator:function(){var j,b,k,l;for(j=0,b=this.images.length;j<b;++j){k="";if(j===0){k="selected"}l=e.createNode("li",{className:k},this.nodes.thumbnails);this.nodes.thumbnails.appendChild(l);e.addEvent(l,"click",this.goTo,{scope:this,imageIndex:j},this,false)}e.addEvent(this.nodes.nextImage,"click",this.next,this,false);e.addEvent(this.nodes.previousImage,"click",this.previous,this,false)},_updatePaginator:function(j){var k,b,l=e.query("li",this.nodes.thumbnails);for(k=0,b=l.length;k<b;++k){if(k===j){e.addClass(l[k],"selected")}else{e.removeClass(l[k],"selected")}}},_addLink:function(b){if(b.link){this.nodes.link.setAttribute("href",b.link);this.nodes.link.setAttribute("target",b.target);e.setStyle(this.nodes.link,"display","block")}else{this.nodes.link.removeAttribute("href");this.nodes.link.removeAttribute("target");e.setStyle(this.nodes.link,"display","none")}},_hideGadget:function(){this.nodes.domNode.style.height=0;this.nodes.domNode.style.overflow="hidden"},destroy:function(){this._removeEvents()}};d=e.query(".gcb_container");for(f=0,c=d.length;f<c;++f){g=d[f];if(!e.hasClass(g,"bannerImage")){a=new h(g)}}}());
