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(B){var A=0;for(var C in B){A++}return A};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="Loading, please wait..."}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("Cancel"));$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="Forward";$D.addClass(F,"tcc_slideShowCtrlNext");var C=document.createElement("div");C.title="Backward";$D.addClass(C,"tcc_slideShowCtrlPrev");var G=document.createElement("div");G.title="Close this gallery";$D.addClass(G,"tcc_slideShowCtrlClose");var I=document.createElement("div");I.title="Resize";$D.addClass(I,"tcc_slideShowCtrlResize");var J=document.createElement("div");J.title="Toggle tooltip";$D.addClass(J,"tcc_slideShowCtrlInfo");var L=document.createElement("div");L.title="Toggle Help";$D.addClass(L,"tcc_slideShowCtrlHelp");var K=document.createElement("div");K.title="Move toolbar";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",{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,O){O.slideShowCtrl.hide()},this);this.lightboxPanel.loadingPanel.getInstance().hideEvent.subscribe(function(N,M,O){if(O.lightboxPanel.conf.ctrlVisible){O.slideShowCtrl.show()}},this);this.lightboxPanel.showImgPanel.showEvent.subscribe(function(N,M,O){if(O.lightboxPanel.conf.ctrlVisible){D.show();D.bringToTop()}},this);this.lightboxPanel.showImgPanel.hideEvent.subscribe(function(N,M,O){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,E){E.self.setKeyboardEnabled(true);$E.on(document,"keydown",function(F,G){$E.preventDefault(F)})},{self:this});A.hideEvent.subscribe(function(D,C,E){E.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(E,F){F.self.show(F.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(G,E,H){H.self.loadingPanel.hide();var F=this.getImage();H.self.imgCache[H.imgId]=F;H.self.conf.dataSource[H.imgId].width=F.width;H.self.conf.dataSource[H.imgId].height=F.height;if(!D){H.self.show(H.imgId)}H.self.preloadCompleteEvent.fire({imageId:H.imgId,ds:H.self.conf.dataSource[H.imgId]});if($TCC.countAsc(H.self.conf.dataSource)==$TCC.countAsc(H.self.imgCache)){H.self.preloadAllCompleteEvent.fire($TCC.countAsc(H.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,E){if(A.length>0){E.self.preloadImage(E.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">Basic Operations:</div><strong>Click</strong> to close the lightbox<br/><strong>Drag</strong> to move the lightbox<br/><br/><div class="tcc_helpPanelTitle">Keyboard Shortcuts:</div><strong>Arrow Left</strong> - Previous photo<br/><strong>Arrow Up/Space bar</strong> - Toggle maximize/restore<br/><strong>Arrow Right</strong> - Next photo<br/><strong>Arrow Down</strong> - Toggle tooltip<br/><strong>Escape</strong> - Close gallery<br/><strong>F1</strong> - Show help<br/><br/>Click this panel to close<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()}}