YAHOO.namespace("com.thecodecentral");var $E=YAHOO.util.Event;var $=YAHOO.util.Dom.get;var $D=YAHOO.util.Dom;var $TCC=YAHOO.com.thecodecentral;YAHOO.com.thecodecentral.empty=function(a){while(a.firstChild){a.removeChild(a.firstChild)}};YAHOO.com.thecodecentral.countAsc=function(c){var b=0;for(var d in c){b++}return b};YAHOO.com.thecodecentral.LoadingPanel=function(a){if(a==undefined){a=new Array()}if(a.id==undefined){a.id="loadingPanel"}if(a.header==undefined){a.header="Cargando imagen..."}if(a.width==undefined){a.width="240px"}this.conf=a;this.init()};YAHOO.com.thecodecentral.LoadingPanel.prototype={init:function(){this.loadingPanel=new YAHOO.widget.Panel(this.conf.id,{width:this.conf.width,fixedcenter:true,close:false,draggable:false,modal:true,visible:false,zindex:"150"});this.loadingPanel.setBody(this.conf.header+'<img src="http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif" />');this.loadingPanel.render(document.body);$D.addClass(this.loadingPanel.id,"tcc_lightboxLoader");var a=document.createElement("a");$D.setStyle(a,"cursor","pointer");a.appendChild(document.createTextNode("Cancelar"));$E.on(a,"click",function(b,c){c.self.hide()},{self:this.loadingPanel});this.loadingPanel.appendToBody(document.createElement("br"));this.loadingPanel.appendToBody(a);$D.setStyle(this.loadingPanel.body,"text-align","center")},show:function(a){if(a!=undefined){this.loadingPanel.setHeader(a)}else{this.loadingPanel.setHeader(this.conf.header)}this.loadingPanel.show()},hide:function(){this.loadingPanel.hide()},getInstance:function(){return this.loadingPanel}};YAHOO.com.thecodecentral.ImageLoader=function(a){this.url=a;this.image=null;this.loadEvent=new YAHOO.util.CustomEvent("onLoad",this)};YAHOO.com.thecodecentral.ImageLoader.prototype={load:function(){this.image=document.createElement("img");$E.on(this.image,"load",function(a,b){b.fire()},this.loadEvent);this.image.src=this.url},getImage:function(){return this.image}};YAHOO.com.thecodecentral.ImageGallery=function(b,a){this.dataSource=b;this.lightboxPanel=a;this.init();this.lightboxPanel.gallery=this;this.initKeyboardShortcut()};YAHOO.com.thecodecentral.ImageGallery.prototype={init:function(){var b=new YAHOO.com.thecodecentral.ImageGalleryList(this.dataSource,true);var f=document.createElement("div");f.title="Siguiente";$D.addClass(f,"tcc_slideShowCtrlNext");var c=document.createElement("div");c.title="Anterior";$D.addClass(c,"tcc_slideShowCtrlPrev");var g=document.createElement("div");g.title="Cerrar galeria";$D.addClass(g,"tcc_slideShowCtrlClose");var i=document.createElement("div");i.title="Redimensionar";$D.addClass(i,"tcc_slideShowCtrlResize");var j=document.createElement("div");j.title="Mostrar/Ocultar info";$D.addClass(j,"tcc_slideShowCtrlInfo");var l=document.createElement("div");l.title="Mostrar/Ocultar ayuda";$D.addClass(l,"tcc_slideShowCtrlHelp");var k=document.createElement("div");k.title="Mover barra de herramientas";k.id=this.lightboxPanel.showImgPanel.id+"Dragger";$D.addClass(k,"tcc_slideShowCtrlDrag");var h=function(m,n){if(n.dir=="next"){n.self.forward()}else{n.self.backward()}};$E.on(f,"click",h,{self:this,dir:"next"});$E.on(c,"click",h,{self:this,dir:"prev"});$E.on(g,"click",function(m,n){n.self.lightboxPanel.showImgPanel.hide()},{self:this});$E.on(i,"click",function(m,n){n.self.lightboxPanel.switchSize()},{self:this});$E.on(l,"click",function(m,n){n.self.lightboxPanel.toggleHelpPanel()},{self:this});$E.on(j,"click",function(m,n){n.self.lightboxPanel.toggleTooltip()},{self:this});var d=new YAHOO.widget.Panel("tcc_slideShowCtrl"+this.lightboxPanel.showImgPanel.id,{visible:false,close:false,draggable:false,underlay:"none"});d.appendToBody(c);d.appendToBody(f);d.appendToBody(g);d.appendToBody(j);d.appendToBody(l);d.appendToBody(i);d.appendToBody(k);var e=new YAHOO.util.DD(d.id+"_c");var a=this.lightboxPanel.showImgPanel;e.endDrag=function(m){a.sizeMask()};e.setHandleElId(this.lightboxPanel.showImgPanel.id+"Dragger");d.render(document.body);$D.addClass(d.id,"tcc_slideShowCtrl");$D.setStyle(d.id+"_c","opacity",this.lightboxPanel.conf.ctrlOpacity);d.bringToTop();this.slideShowCtrl=d;this.dockToolbar(true);this.lightboxPanel.loadingPanel.getInstance().showEvent.subscribe(function(n,m,p){p.slideShowCtrl.hide()},this);this.lightboxPanel.loadingPanel.getInstance().hideEvent.subscribe(function(n,m,p){if(p.lightboxPanel.conf.ctrlVisible){p.slideShowCtrl.show()}},this);this.lightboxPanel.showImgPanel.showEvent.subscribe(function(n,m,p){if(p.lightboxPanel.conf.ctrlVisible){d.show();d.bringToTop()}},this);this.lightboxPanel.showImgPanel.hideEvent.subscribe(function(n,m,p){d.hide()});this.galleryList=b;if(this.lightboxPanel.conf.ctrlVisible){$E.on(window,"scroll",function(n){var m=$D.getRegion(document.body);d.moveTo($D.getDocumentScrollLeft()+$D.getClientWidth()/2-100,$D.getDocumentScrollTop()+$D.getClientHeight()-75)})}},forward:function(){this.lightboxPanel.placeImage(this.galleryList.forward())},backward:function(){this.lightboxPanel.placeImage(this.galleryList.backward())},initKeyboardShortcut:function(){var a=this.lightboxPanel.showImgPanel;var b={};b.escapeKey=new YAHOO.util.KeyListener(document,{keys:27},{fn:this.lightboxPanel.showImgPanel.hide,scope:this.lightboxPanel.showImgPanel,correctScope:true});a.cfg.queueProperty("keylisteners",b.escapeKey);b.leftKey=new YAHOO.util.KeyListener(document,{keys:37},{fn:this.backward,scope:this,correctScope:true});a.cfg.queueProperty("keylisteners",b.leftKey);b.upKey=new YAHOO.util.KeyListener(document,{keys:[38,32]},{fn:this.lightboxPanel.switchSize,scope:this.lightboxPanel,correctScope:true});a.cfg.queueProperty("keylisteners",b.upKey);b.rightKey=new YAHOO.util.KeyListener(document,{keys:39},{fn:this.forward,scope:this,correctScope:true});a.cfg.queueProperty("keylisteners",b.rightKey);b.downKey=new YAHOO.util.KeyListener(document,{keys:40},{fn:this.lightboxPanel.toggleTooltip,scope:this.lightboxPanel,correctScope:true});a.cfg.queueProperty("keylisteners",b.downKey);b.f1Key=new YAHOO.util.KeyListener(document,{keys:112},{fn:this.lightboxPanel.toggleHelpPanel,scope:this.lightboxPanel,correctScope:true});this.navKeys=b;a.showEvent.subscribe(function(d,c,f){f.self.setKeyboardEnabled(true);$E.on(document,"keydown",function(g,h){$E.preventDefault(g)})},{self:this});a.hideEvent.subscribe(function(d,c,f){f.self.setKeyboardEnabled(false);$E.purgeElement(document,false,"keydown")},{self:this})},dockToolbar:function(b){if(!this.lightboxPanel.conf.ctrlVisible){return}b=b==undefined?false:b;var a=$D.getRegion(this.slideShowCtrl.id);if(!b&&((this.lightboxPanel.pageScrollTopValue+$D.getClientHeight()>a.bottom+5)&&(this.lightboxPanel.pagepageScrollLeftValue+$D.getClientWidth()>a.right+5))){return}window.scroll(0,this.lightboxPanel.pageScrollTopValue);this.slideShowCtrl.cfg.setProperty("x",$D.getViewportWidth()/2-(a.right-a.left)/2);this.slideShowCtrl.center();this.slideShowCtrl.cfg.setProperty("y",$D.getViewportHeight()+$D.getDocumentScrollTop()-75)},setKeyboardEnabled:function(b){if(b==true){for(var a in this.navKeys){this.navKeys[a].enable()}}else{for(var a in this.navKeys){this.navKeys[a].disable()}}},getList:function(){return this.galleryList}};YAHOO.com.thecodecentral.ImageGalleryList=function(b,a){this.list=new Array();this.curIndex=0;this.isCircular=a==undefined?false:a;this.dataSource=b;this.doIndex()};YAHOO.com.thecodecentral.ImageGalleryList.prototype={doIndex:function(){for(var a in this.dataSource){this.list.push(a)}},getFirst:function(){return this.list[0]},getLast:function(){return this.list[this.getSize()-1]},getCurrent:function(){return this.list[this.curIndex]},getCurrentIndex:function(){return this.curIndex},setCurrentIndex:function(a){a=parseInt(a);if(a>this.getSize()){this.curIndex=this.getSize()-1}else{if(a<0){this.curIndex=0}else{this.curIndex=a}}},getIndexByImageId:function(a){for(var b in this.list){if(this.list[b]==a){return b}}return -1},getNextIndex:function(){var a;if(this.curIndex+1<this.getSize()){a=this.curIndex+1}else{if(this.isCircular){a=0}else{a=this.curIndex}}return a},getNext:function(){return this.list[this.getNextIndex()]},getPreviousIndex:function(){var a;if(this.curIndex>0){a=this.curIndex-1}else{if(this.isCircular){a=this.getSize()-1}else{a=0}}return a},getPrevious:function(){return this.list[this.getPreviousIndex()]},forward:function(){this.curIndex=this.getNextIndex();return this.getCurrent()},backward:function(){this.curIndex=this.getPreviousIndex();return this.getCurrent()},getSize:function(){return this.list.length},toString:function(){var b="";for(var a in this.list){b+=a+":"+this.list[a]+" "}return b}};YAHOO.com.thecodecentral.LightboxPanel=function(a){this.STATE_MAX=0;this.STATE_FIT=1;this.conf=a==null?{}:a;this.conf.hasThumbnails=a.hasThumbnails==null?true:a.hasThumbnails;this.conf.effect=a.effect==null?true:a.effect;this.conf.effectDuration=a.effectDuration==null?1:a.effectDuration;this.conf.ctrlVisible=a.ctrlVisible==null?true:a.ctrlVisible;this.conf.ctrlOpacity=a.ctrlOpacity==null?0.5:a.ctrlOpacity;this.conf.id=a.id==null?"tcc_showImgPanel":a.id;this.conf.tooltip=a.tooltip==null?true:a.tooltip;this.conf.tooltipOpacity=a.tooltipOpacity==null?0.9:a.tooltipOpacity;this.imgCache={};this.gallery=null;this.init()};YAHOO.com.thecodecentral.LightboxPanel.prototype={init:function(){this.preloadStartEvent=new YAHOO.util.CustomEvent("preloadStartEvent",this);this.preloadCompleteEvent=new YAHOO.util.CustomEvent("preloadCompleteEvent",this);this.preloadAllCompleteEvent=new YAHOO.util.CustomEvent("preloadAllCompleteEvent",this);this.loadingPanel=new YAHOO.com.thecodecentral.LoadingPanel();this.initLightbox();if(this.conf.hasThumbnails){this.prepareThumbnails()}this.pageScrollTopValue=0;this.pageScrollLeftValue=0;if(this.conf.effect==true){this.imgPanelFadeIn=new YAHOO.util.Anim(this.showImgPanel.id,{opacity:{from:0,to:1}},this.conf.effectDuration,YAHOO.util.Easing.easeOut)}for(var a in this.conf.dataSource){if(this.conf.dataSource[a].state==undefined){this.conf.dataSource[a].state=this.STATE_FIT}}$D.addClass(document.body,"yui-skin-sam")},prepareThumbnails:function(){var c=this.conf.dataSource;for(var b in c){var d=function(f,g){g.self.show(g.imgId)};var a=$(b);$D.setStyle(a,"cursor","pointer");$E.on(a,"click",d,{self:this,imgId:b})}},preloadImage:function(b,c,d){d=d==null?false:d;this.preloadStartEvent.fire({imageId:b,ds:this.conf.dataSource[b]});if(c==undefined){c={}}if(c.progressBar==undefined){c.progressBar=true}var a=new YAHOO.com.thecodecentral.ImageLoader(this.conf.dataSource[b].url);a.loadEvent.subscribe(function(h,f,i){i.self.loadingPanel.hide();var g=this.getImage();i.self.imgCache[i.imgId]=g;i.self.conf.dataSource[i.imgId].width=g.width;i.self.conf.dataSource[i.imgId].height=g.height;if(!d){i.self.show(i.imgId)}i.self.preloadCompleteEvent.fire({imageId:i.imgId,ds:i.self.conf.dataSource[i.imgId]});if($TCC.countAsc(i.self.conf.dataSource)==$TCC.countAsc(i.self.imgCache)){i.self.preloadAllCompleteEvent.fire($TCC.countAsc(i.self.conf.dataSource))}},{self:this,imgId:b,conf:c});if(c.callback!=undefined){a.loadEvent.subscribe(c.callback,c.param)}if(c.progressBar&&!d){this.loadingPanel.show("Loading image ...")}a.load()},preloadAll:function(){var a=new Array();for(var b in this.conf.dataSource){a.push(b)}a.reverse();this.preloadImage(a.pop(),null,true);this.preloadCompleteEvent.subscribe(function(d,c,f){if(a.length>0){f.self.preloadImage(f.queue.pop(),null,true)}},{self:this,queue:a})},setOpacity:function(a){$D.setStyle(this.showImgPanel.id,"opacity",a)},savePageScrollPosition:function(){this.pageScrollLeftValue=$D.getDocumentScrollLeft();this.pageScrollTopValue=$D.getDocumentScrollTop()},restorePageScrollPosition:function(){window.scroll(this.pageScrollLeftValue,this.pageScrollTopValue)},show:function(a){this.savePageScrollPosition();if(a==null){a=this.gallery.galleryList.getFirst()}this.placeImage(a)},placeImage:function(a){this.gallery.dockToolbar();this.gallery.galleryList.setCurrentIndex(this.gallery.galleryList.getIndexByImageId(a));var c=this.imgCache[a];this.gallery.setKeyboardEnabled(false);if(c==undefined){this.preloadImage(a);return}this.gallery.setKeyboardEnabled(true);if(this.conf.effect==true){this.imgPanelFadeIn.stop();this.setOpacity(0);this.imgPanelFadeIn.animate()}$TCC.empty(this._imgHolder);this.restorePageScrollPosition();$E.purgeElement(this.showImgPanel.body,false,"dblclick");$E.on(this.showImgPanel.body,"dblclick",function(g,h){h.self.restorePageScrollPosition();h.self.switchSize()},{imgId:a,self:this,image:c});var f;var e;var b="";if(this.conf.dataSource[a].title==null||this.conf.dataSource[a].title.length==0){f="&nbsp;"}else{f=this.conf.dataSource[a].title}if(this.conf.dataSource[a].text==null||this.conf.dataSource[a].text.length==0){e="&nbsp;"}else{e=this.conf.dataSource[a].text}this.setTooltipText(f,e);this.showImgPanel.show();var d=document.createElement("img");d.src=c.src;this._imgHolder.appendChild(d);this._autoFit(c,a);this.sizeMask()},sizeMask:function(){$D.setStyle(this.showImgPanel.id+"_mask","width",$D.getClientWidth()+"px");$D.setStyle(this.showImgPanel.id+"_mask","height",$D.getClientHeight()+"px");this.showImgPanel.sizeMask()},switchSize:function(){this.gallery.dockToolbar();var a=this.gallery.getList().getCurrent();var b=$(this._imgHolder.id).getElementsByTagName("img")[0];if(this.conf.dataSource[a].state==this.STATE_MAX){this._autoFit(b,a)}else{this._maximize(b,a)}this.sizeMask()},_autoFit:function(){var c=this.gallery.getList().getCurrent();this.conf.dataSource[c].state=this.STATE_FIT;var g=$(this._imgHolder.id).getElementsByTagName("img")[0];var b=this.conf.dataSource[c].width;var f=this.conf.dataSource[c].height;var e=$D.getViewportWidth()-50;var h=$D.getViewportHeight()-50;if(b>e||f>h){var d=b/f;var a=e/h;if(d<=a){g.height=h;g.width=b*(h/f)}else{g.width=e;g.height=f*(e/b)}}this.showImgPanel.cfg.setProperty("width",(g.width+20)+"px");this.showImgPanel.center()},_maximize:function(){var a=this.gallery.getList().getCurrent();var b=$(this._imgHolder.id).getElementsByTagName("img")[0];this.conf.dataSource[a].state=this.STATE_MAX;b.width=this.conf.dataSource[a].width;b.height=this.conf.dataSource[a].height;this.showImgPanel.cfg.setProperty("width",(parseInt(this.conf.dataSource[a].width)+20)+"px");this.showImgPanel.cfg.setProperty("x",5);this.showImgPanel.center()},initLightbox:function(){var d={width:"100px",visible:false,draggable:false,modal:true,close:false};if(this.conf.modal!=undefined&&this.conf.modal==false){d.modal=false}var a=new YAHOO.widget.Panel(this.conf.id,d);var h=document.createElement("div");h.id=a.id+"ImgHolder";$D.setStyle(h,"text-align","center");a.setBody(h);a.render(document.body);$D.addClass(a.id,"tcc_showImgPanel");var b=false;$E.on(a.body,"click",function(j,k){if(!b){a.hide()}b=false},{self:this});var e=new YAHOO.util.DD(a.id+"_c");e.startDrag=function(j){b=true};e.endDrag=function(j){a.sizeMask()};$E.on(a.id+"_mask","click",function(j,k){k.self.showImgPanel.hide()},{self:this});a.beforeShowEvent.subscribe(function(){this.sizeMask()});a.moveEvent.subscribe(function(){this.sizeMask()});var g=function(k,j,l){l.self.imageTooltip.bringToTop();if(l.self.conf.maskOpacity!=undefined){$D.setStyle(this.id+"_mask","opacity",l.self.conf.maskOpacity)}if(l.self.conf.maskBgColor!=undefined){$D.setStyle(this.id+"_mask","background-color",l.self.conf.maskBgColor)}};a.showEvent.subscribe(g,{self:this});this.loadingPanel.getInstance().showEvent.subscribe(g,{self:this});a.beforeHideEvent.subscribe(function(k,j,l){l.self.restorePageScrollPosition();l.self._autoFit()},{self:this});a.hideEvent.subscribe(function(k,j,l){l.self.imageTooltip.hide();l.self.helpPanel.hide()},{self:this});this._imgHolder=h;this.showImgPanel=a;var c=new YAHOO.widget.Dialog(this.showImgPanel.id+"Tooddtip",{width:"180px",close:false,draggable:false,visible:false});c.setBody("&nbsp;");c.render(document.body);$D.addClass(c.id,"tcc_imageTooltip");$D.setStyle(c.id,"opacity",this.conf.tooltipOpacity);$E.on(window,"scroll",function(k){var j=$D.getRegion(document.body);c.moveTo($D.getDocumentScrollLeft()+15,$D.getDocumentScrollTop()+15)});var f=new YAHOO.util.DD(c.id+"_c");f.endDrag=function(j){a.sizeMask()};f.endDrag=function(j){a.sizeMask()};this.imageTooltip=c;var i=new YAHOO.widget.Panel(this.showImgPanel.id+"HelpPanel",{width:"250px",close:false,draggable:false,visible:false,fixedcenter:true,effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.1}});i.setBody(" ");i.render(document.body);$D.addClass(i.id,"tcc_imageHelPanel");$E.on(i.body,"click",function(){i.hide()});this.helpPanel=i;this._setHelpPanelBody()},_setHelpPanelBody:function(){this.helpPanel.setBody('<div class="tcc_helpPanelTitle">Funcionamiento:</div><strong>Click</strong> para cerrar la galer&iacute;a<br/><strong>Arrastrar</strong> para mover la galer&iacute;a<br/><br/><div class="tcc_helpPanelTitle">Con el teclado:</div><strong>Izquierda</strong> - Foto anterior<br/><strong>Arriba / Espacio</strong> - Maximizar / restaurar foto<br/><strong>Derecha</strong> - Foto siguiente<br/><strong>Abajo</strong> - Mostrar / ocultar info.<br/><strong>Escape</strong> - Cerrar galer&iacute;a<br/><strong>F1</strong> - Mostrar ayuda<br/><br/>Click sobre este panel para cerrarlo.<br/>')},toggleTooltip:function(){this.conf.tooltip=!this.conf.tooltip;if(this.imageTooltip.cfg.getProperty("visible")==true&&!this.conf.tooltip){this.imageTooltip.hide()}else{this.imageTooltip.show();this.imageTooltip.bringToTop()}},toggleHelpPanel:function(){if(this.helpPanel.cfg.getProperty("visible")==true){this.helpPanel.hide()}else{this.helpPanel.show();this.helpPanel.bringToTop()}},setTooltipText:function(b,a){b=(b==null||b=="&nbsp;")?"":b;a=(a==null||a=="&nbsp;")?"":a;if(b.length==0&&a.length==0){this.imageTooltip.hide()}else{if(this.conf.tooltip){this.imageTooltip.show()}this.imageTooltip.setBody('<div class="tcc_imageTooltipTitle" id=".'+this.imageTooltip.id+'Title">'+b+'</div><div class="tcc_imageTooltipText" id=".'+this.imageTooltip.id+'Text">'+a+"</div>")}}};YAHOO.com.thecodecentral.Lightbox=function(b,a){this.init(b,a)};YAHOO.com.thecodecentral.Lightbox.prototype={init:function(b,a){a=a==null?{}:a;a.dataSource=b;this.conf=a;this.lightboxPanel=new YAHOO.com.thecodecentral.LightboxPanel(a);this.imageGallery=new YAHOO.com.thecodecentral.ImageGallery(a.dataSource,this.lightboxPanel)},show:function(a){this.lightboxPanel.show(a)},preloadAll:function(){this.lightboxPanel.preloadAll()},setDataSource:function(a){this.lightboxPanel.conf.dataSource=a;this.lightboxPanel.imgCache={};this.imageGallery.dataSource=a;this.imageGallery.galleryList=new YAHOO.com.thecodecentral.ImageGalleryList(a,true)},dispose:function(){this.lightboxPanel.showImgPanel.destroy();this.lightboxPanel.imageTooltip.destroy();this.imageGallery.slideShowCtrl.destroy();this.lightboxPanel.loadingPanel.loadingPanel.destroy();this.lightboxPanel.helpPanel.destroy()}};