YAHOO.namespace("com.thecodecentral");
YAHOO.com.thecodecentral.Lightbox=function(a){this.conf=a==null?{}:a;
this._init();
this._initLoader();
this._initLightbox();
this._loadData()
};
YAHOO.com.thecodecentral.Lightbox.prototype._init=function(){YAHOO.util.Dom.addClass(document.body,"yui-skin-sam")
};
YAHOO.com.thecodecentral.Lightbox.prototype._loadData=function(){var c=this.conf.dataSource;
for(var b in c){var d=function(h,i){var f=function(q,l){l.self.lightboxLoader.hide();
while(l.self._resizeBtnCon.firstChild){l.self._resizeBtnCon.removeChild(l.self._resizeBtnCon.firstChild)
}YAHOO.util.Event.purgeElement(l.self.showImgPanel.header,false,"dblclick");
l.self.conf.dataSource[l.imgId].width=l.image.width;
l.self.conf.dataSource[l.imgId].height=l.image.height;
var r=l.self.conf.dataSource[l.imgId].width;
var p=l.self.conf.dataSource[l.imgId].height;
var s=YAHOO.util.Dom.getViewportWidth()-50;
var m=YAHOO.util.Dom.getViewportHeight()-70;
if(r>250&&p>250&&(r>s||p>m)){var n=function(u,v){v.image.width=v.self.conf.dataSource[v.imgId].width;
v.image.height=v.self.conf.dataSource[v.imgId].height;
v.self.showImgPanel.cfg.setProperty("width",(parseInt(v.self.conf.dataSource[v.imgId].width)+20)+"px");
v.self.showImgPanel.cfg.setProperty("x",5);
v.self._setResizeButton("restore");
v.self.showImgPanel.showState="maximum"
};
YAHOO.util.Event.on(l.self._btnMaximum,"click",n,l);
var j=function(u,v){v.self._setResizeButton("maximum");
v.self._autoFit(v.image,v.imgId);
v.self.showImgPanel.showState="restore"
};
YAHOO.util.Event.on(l.self._btnRestore,"click",j,l);
var k=function(u,v){if(v.self.showImgPanel.showState=="maximum"){v.onBtnRestoreClick("dblclick",v)
}else{v.onBtnMaximumClick("dblclick",v)
}};
YAHOO.util.Event.on(l.self.showImgPanel.header,"dblclick",k,{self:l.self,image:l.image,imgId:l.imgId,onBtnMaximumClick:n,onBtnRestoreClick:j});
l.self.showImgPanel.showState="restore";
l.self._setResizeButton("maximum")
}var t;
if(l.self.conf.dataSource[l.imgId].title==null||l.self.conf.dataSource[l.imgId].title.length==0){t="&nbsp;"
}else{t=l.self.conf.dataSource[l.imgId].title
}l.self.showImgPanel.setHeader(t);
l.self.showImgPanel.show();
l.self._autoFit(l.image)
};
while(i.self._imgHolder.firstChild){i.self._imgHolder.removeChild(i.self._imgHolder.firstChild)
}var g=document.createElement("img");
i.self._imgHolder.appendChild(g);
YAHOO.util.Event.on(g,"load",f,{self:i.self,image:g,imgId:i.imgId});
i.self.lightboxLoader.show();
g.src=c[i.imgId].url
};
var a=YAHOO.util.Dom.get(b);
YAHOO.util.Event.on(a,"click",d,{self:this,imgId:b});
YAHOO.util.Dom.setStyle(a,"cursor","pointer")
}};
YAHOO.com.thecodecentral.Lightbox.prototype._autoFit=function(f){var b=f.width;
var e=f.height;
var d=YAHOO.util.Dom.getViewportWidth()-50;
var g=YAHOO.util.Dom.getViewportHeight()-70;
if(b>=250||e>=250){if(b>d||e>g){var c=b/e;
var a=d/g;
if(c<=a){f.height=g;
f.width=b*(g/e)
}else{f.width=d;
f.height=e*(d/b)
}}this.showImgPanel.cfg.setProperty("width",(f.width+20)+"px")
}else{this.showImgPanel.cfg.setProperty("width","250px")
}this.showImgPanel.center()
};
YAHOO.com.thecodecentral.Lightbox.prototype._initLoader=function(){var a=new YAHOO.widget.Panel("tcc_lightboxLoader",{width:"240px",fixedcenter:true,close:false,draggable:false,modal:true,visible:false});
a.setHeader("Loading, please wait...");
var b=document.createElement("img");
b.src=this.conf.imageBase+"/progressBar.gif";
a.setBody(b);
a.render(document.body);
this.lightboxLoader=a
};
YAHOO.com.thecodecentral.Lightbox.prototype._initLightbox=function(){var c=new YAHOO.widget.Panel("tcc_showImgPanel",{width:"400px",visible:false,draggable:true,modal:true});
var b=document.createElement("div");
b.id="tcc_showImgPanelImgHolder";
YAHOO.util.Dom.setStyle(b,"text-align","center");
c.setBody(b);
c.setHeader("&nbsp;");
c.render(document.body);
var e=function(i,j){j.hide()
};
YAHOO.util.Event.on(c.body,"click",e,c);
YAHOO.util.Dom.setStyle(c.body,"cursor","pointer");
var f=function(i,j){this.sizeMask()
};
c.moveEvent.subscribe(f);
var g=YAHOO.util.Dom.get("tcc_showImgPanel");
var a=document.createElement("div");
a.id="tcc_showImgPanelResizeBtnCon";
YAHOO.util.Dom.setStyle(a,"position","absolute");
YAHOO.util.Dom.setStyle(a,"right","35px");
YAHOO.util.Dom.setStyle(a,"top","5px");
g.appendChild(a);
var h=document.createElement("img");
h.src=this.conf.imageBase+"/maximum.gif";
var d=document.createElement("img");
d.src=this.conf.imageBase+"/restore.gif";
this._resizeBtnCon=a;
this._btnRestore=d;
this._btnMaximum=h;
this._imgHolder=b;
this.showImgPanel=c
};
YAHOO.com.thecodecentral.Lightbox.prototype._setResizeButton=function(a){while(this._resizeBtnCon.firstChild){this._resizeBtnCon.removeChild(this._resizeBtnCon.firstChild)
}if(a=="maximum"){this._resizeBtnCon.appendChild(this._btnMaximum)
}else{this._resizeBtnCon.appendChild(this._btnRestore)
}};
