var _ERROR_MESSAGE="Oops.. there was a problem with your request.<br /><br />Please try again.<br /><br /><em>Click anywhere to close.</em>";var _RESIZE_DURATION=200;var _INITIAL_WIDTH=520;var _INITIAL_HEIGHT=250;var _CONTENTS_WIDTH=500;var _CONTENTS_HEIGHT=400;var _DEF_CONTENTS_WIDTH=500;var _DEF_CONTENTS_HEIGHT=400;var _ANIMATE_CAPTION=true;var _EVAL_SCRIPTS=false;var _EVAL_RESPONSE=false;var MOOdalBox={init:function(a){this.options=Object.extend({resizeDuration:_RESIZE_DURATION,initialWidth:_INITIAL_WIDTH,initialHeight:_INITIAL_HEIGHT,contentsWidth:_CONTENTS_WIDTH,contentsHeight:_CONTENTS_HEIGHT,defContentsWidth:_DEF_CONTENTS_WIDTH,defContentsHeight:_DEF_CONTENTS_HEIGHT,animateCaption:_ANIMATE_CAPTION,evalScripts:_EVAL_SCRIPTS,evalResponse:_EVAL_RESPONSE},a||{});this.anchors=[];$A($$("a")).each(function(c){if(c.rel&&c.href&&c.rel.test("^moodalbox","i")){c.onclick=this.click.pass(c,this);this.anchors.push(c)}},this);this.eventKeyDown=this.keyboardListener.bindWithEvent(this);this.eventPosition=this.position.bind(this);this.overlay=new Element("div").setProperty("id","mb_overlay").injectInside(document.body);this.center=new Element("div").setProperty("id","mb_center").setStyles({width:this.options.initialWidth+"px",height:this.options.initialHeight+"px",marginLeft:"-"+(this.options.initialWidth/2)+"px",display:"none"}).injectInside(document.body);this.contents=new Element("div").setProperty("id","mb_contents").injectInside(this.center);this.bottom=new Element("div").setProperty("id","mb_bottom").setStyle("display","none").injectInside(document.body);this.closelink=new Element("a").setProperties({id:"mb_close_link",href:"#"}).injectInside(this.bottom);this.caption=new Element("div").setProperty("id","mb_caption").injectInside(this.bottom);new Element("div").setStyle("clear","both").injectInside(this.bottom);this.error=new Element("div").setProperty("id","mb_error").set("html",_ERROR_MESSAGE);this.closelink.onclick=this.overlay.onclick=this.close.bind(this);var b=this.nextEffect.bind(this);this.fx={overlay:new Fx.Tween(this.overlay,{property:"opacity",duration:500}).set(0),resize:new Fx.Morph(this.center,$extend({duration:this.options.resizeDuration,onComplete:b},this.options.resizeTransition?{transition:this.options.resizeTransition}:{})),contents:new Fx.Tween(this.contents,{property:"opacity",duration:500,onComplete:b})};this.ajaxRequest=Class.empty},click:function(a){return this.open(a.href,a.title,a.rel)},open:function(b,a,c){this.href=b;this.title=a;this.rel=c;this.position();this.setup(true);this.top=Window.getScrollTop()+(Window.getHeight()/15);this.center.setStyles({top:this.top+"px",display:""});this.fx.overlay.start(0.8);return this.loadContents(b)},position:function(){this.overlay.setStyles({top:Window.getScrollTop()+"px",height:Window.getHeight()+"px"})},setup:function(a){var c=$A($$("object"));c.extend($$(window.ActiveXObject?"select":"embed"));c.each(function(d){d.style.visibility=a?"hidden":""});var b=a?"addEvent":"removeEvent";window[b]("scroll",this.eventPosition)[b]("resize",this.eventPosition);document[b]("keydown",this.eventKeyDown);this.step=0},loadContents:function(){if(this.step){return false}this.step=1;var d=this.rel.match(/[0-9]+/g);this.options.contentsWidth=(d&&(d[0]>0))?d[0]:this.options.defContentsWidth;this.options.contentsHeight=(d&&(d[1]>0))?d[1]:this.options.defContentsHeight;this.bottom.setStyles({opacity:"0",height:"0px",display:"none"});this.center.className="mb_loading";this.fx.contents.set(0);var c=this.nextEffect.bind(this);var b=this.ajaxFailure.bind(this);var a={method:"get",url:this.href,update:this.contents,evalScripts:this.options.evalScripts,evalResponse:this.options.evalResponse,onComplete:c,onFailure:b};this.ajaxRequest=new Request.HTML(a).send();return false},ajaxFailure:function(){this.contents.set("html","");this.error.clone().injectInside(this.contents);this.nextEffect();this.center.setStyle("cursor","pointer");this.bottom.setStyle("cursor","pointer");this.center.onclick=this.bottom.onclick=this.close.bind(this)},nextEffect:function(){switch(this.step++){case 1:this.center.className="";this.center.setStyle("cursor","default");this.bottom.setStyle("cursor","default");this.center.onclick=this.bottom.onclick="";this.caption.set("html",this.title);this.contents.setStyles({width:this.options.contentsWidth+"px",height:this.options.contentsHeight+"px"});if(this.center.clientHeight!=this.contents.offsetHeight){this.fx.resize.start({height:this.contents.offsetHeight});break}this.step++;case 2:if(this.center.clientWidth!=this.contents.offsetWidth){this.fx.resize.start({width:this.contents.offsetWidth,marginLeft:-this.contents.offsetWidth/2});break}this.step++;case 3:this.contents.getElementById("mb_close_link2").onclick=this.overlay.onclick=this.close.bind(this);this.bottom.setStyles({top:(this.top+this.center.clientHeight)+"px",width:this.contents.style.width,marginLeft:this.center.style.marginLeft,display:""});this.fx.contents.start(1);break;case 4:case 5:this.step=0}},keyboardListener:function(a){if((a.control&&a.key=="w")||(a.control&&a.key=="x")||(a.key=="esc")){this.close();a.stop()}},close:function(){if(this.step<0){return false}this.step=-1;for(var a in this.fx){this.fx[a].cancel()}this.center.style.display=this.bottom.style.display="none";this.center.className="mb_loading";this.fx.overlay.chain(this.setup.pass(false,this)).start(0);return false}};window.addEvent("domready",MOOdalBox.init.bind(MOOdalBox));