var ModalDialog=$Class({_options:{fileCloseImage:"http://images.nciku.com.tw/static/img/imp/close.gif",contentPadding:0,modalDefaultSize:{width:400,height:300},displayType:{image:"image",page:"page",html:"html"}},currentType:"",$init:function(a){this._caption=a;this._oAgent=$Agent().navigator()},_createModalDialog:function(){var a=cssquery("body")[0];if(this._oAgent.ie&&this._oAgent.version<7){$Element(a).css({height:"100%",width:"100%"});$Element(cssquery("html")[0]).css({overflow:"hidden"});this.maskIframe=$("<iframe>");this.maskIframe.className="modalMaskIframe";a.appendChild(this.maskIframe)}this.maskLayer=$("<div>");this.maskLayer.className="modalMask";a.appendChild(this.maskLayer);this.container=$("<div>");this.container.className="modalDialog";a.appendChild(this.container)},_removeModalDialog:function(){var b=cssquery("body")[0];if(this._oAgent.ie&&this._oAgent.version<7){b.removeChild(this.maskIframe);$Element(b).css({height:"auto",width:"auto"});$Element(cssquery("html")[0]).css({overflow:""})}if(this.currentType==this._options.displayType.html){var a=this.container.removeChild(this.container.firstChild);a.style.display="none";document.body.appendChild(a)}b.removeChild(this.maskLayer);b.removeChild(this.container)},_showImage:function(a){this._createModalDialog();var b="<div class='modalTitle'><div class='modalTitleCaption'>"+this._caption+"</div><div class='modalTitleClose'><a href='#' title='Close'><img src='"+this._options.fileCloseImage+"' /></a></div></div><div class='modalContent'><img src='' /></div>";$Element(this.container).html(b);cssquery("div.modalTitle div.modalTitleClose a",this.container)[0].onclick=$Fn(this.end,this).bind();cssquery("div.modalContent",this.container)[0].style.padding=this._options.contentPadding+"px";this.preFetchImage=new Image();this.preFetchImage.onload=$Fn(this._loadImage,this).bind();this.preFetchImage.src=a},_showIframe:function(a){this._createModalDialog();var c="<div class='modalContent'><iframe scrolling='no' frameborder='0' width='100%' height='100px'></iframe></div>";$Element(this.container).html(c);this.container.style.opacity=0;this.container.style.filter="alpha(opacity=0)";var b=cssquery("iframe",this.container)[0];b.style.display="block";if(b.attachEvent){b.attachEvent("onload",$Fn(this.resizeIframe,this).bind())}else{if(b.addEventListener){b.addEventListener("load",$Fn(this.resizeIframe,this).bind(),false)}}b.setAttribute("src",a);this.container.oldHeight=-1;this.container.oldWidth=-1;this.container.style.display="block"},_showHtml:function(c){this._createModalDialog();var d=$(c);d.style.display="block";var b=d.offsetWidth;var a=d.offsetHeight;this.container.appendChild(d);this.showModalDialog(b,a)},start:function(b,a,c){this.currentType=b;switch(this.currentType){case this._options.displayType.image:this._showImage(a);break;case this._options.displayType.html:this._showHtml(a);break;case this._options.displayType.page:this._showIframe(a);break}$Event(c).stop()},end:function(a){$Element(this.container).css({display:"none"});$Element(this.maskLayer).css({display:"none"});this._removeModalDialog();$Event(a).stop()},_loadImage:function(){var b=this.preFetchImage.width;var a=this.preFetchImage.height;if(a>this._options.modalDefaultSize.height){a=this._options.modalDefaultSize.height;b=b*this._options.modalDefaultSize.height/this.preFetchImage.height}cssquery("div.modalContent img",this.container)[0].src=this.preFetchImage.src;cssquery("div.modalContent img",this.container)[0].setAttribute("width",b);cssquery("div.modalContent img",this.container)[0].setAttribute("height",a);this.showModalDialog(b+this._options.contentPadding*2,a+this._options.contentPadding*2)},showModalDialog:function(b,a){$Element(this.maskLayer).css({display:"block"});$Element(this.container).css({width:b+"px",display:"block"});if(!(this._oAgent.ie&&this._oAgent.version<7)){$Element(this.container).css({marginLeft:"-"+parseInt((b/2),10)+"px",marginTop:"-"+parseInt((a/2),10)+"px"})}},getScrollOffsets:function(){return{offX:window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft,offY:window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop}},resizeIframe:function(){var f=cssquery("iframe",this.container)[0];if(f.getAttribute("height")!="100px"){f.setAttribute("height","100px")}var b=f.contentWindow.document.body.scrollHeight;var g=f.contentWindow.document.documentElement.scrollHeight;var d=f.contentWindow.document.body.scrollWidth;var c=f.contentWindow.document.documentElement.scrollWidth;var a=Math.max(b,g);var e=Math.max(d,c);if(a!=0&&this.container.oldHeight==a&&this.container.oldWidth==e){clearTimeout(this.container.timer);f.setAttribute("height",a);this.showModalDialog(e,a);this.container.style.opacity="";this.container.style.filter="";this.container.oldHeight=-1;this.container.oldWidth=-1}else{this.container.oldHeight=a;this.container.oldWidth=e;this.container.timer=setTimeout($Fn(this.resizeIframe,this).bind(),10)}},Alpha:0,Endalpha:95,speed:10,fade:function(e){var b=this.Alpha;if((b!=this.Endalpha&&e==1)||(b!=0&&e==-1)){var c=this.speed;if(this.Endalpha-b<this.speed&&e==1){c=this.Endalpha-b}else{if(this.Alpha<this.speed&&e==-1){c=b}}this.Alpha=b+(c*e);this.container.style.opacity=this.Alpha*0.01;this.container.style.filter="alpha(opacity="+this.Alpha+")"}else{clearInterval(this.container.timer);if(e==-1){this.container.style.display="none"}}}});