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=100;var _CONTENT_HEIGHT=0.9;var _CONTENT_WIDTH=0.9;var _ANIMATE_CAPTION=true;var _EVAL_SCRIPTS=false;var _EVAL_RESPONSE=false;var MOOdalBox={init:function(a){this.options=Object.extend({resizeDuration:_RESIZE_DURATION,animateCaption:_ANIMATE_CAPTION,contentHeight:_CONTENT_HEIGHT,contentWidth:_CONTENT_WIDTH,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.resizeWindow.bind(this);this.options.contentsHeight=(this.options.contentHeight*Window.getHeight());this.options.contentsWidth=this.options.contentWidth*Window.getWidth();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.contentsWidth+"px",height:this.options.contentsHeight+"px",marginLeft:"-"+(this.options.contentsWidth/2)+"px",display:"none"}).injectInside(document.body);this.contents=new Element("div").setProperty("id","mb_contents").injectInside(this.center);this.close=new Element("div").setProperty("id","mb_close").setStyle("display","none").injectInside(document.body);this.closelink=new Element("a").setProperties({id:"mb_close_link",href:"#"}).injectInside(this.close);this.closelink.onclick=this.overlay.onclick=this.closeMe.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}),close:new Fx.Morph(this.close,$extend({duration:400,onComplete:b},this.options.resizeTransition?{transition:this.options.resizeTransition}:{}))};this.initOpen()},click:function(a){return this.open(a.href,a.title,a.rel)},initOpen:function(){if(typeof SWFAddress!="undefined"){var c=SWFAddress.getValue();if(c.search(/\/projectId\//)!=-1){var a=c.match(/\/projectId\/(\d+)/);if(txReferencesPi1DetaiUrl.indexOf("?")==-1){var b=txReferencesPi1DetaiUrl+"?tx_references_pi1[showUid]="+a[1]}else{var b=txReferencesPi1DetaiUrl+"&tx_references_pi1[showUid]="+a[1]}this.open(b)}else{if(c.search(/\/project\//)!=-1){var a=c.match(/\/project\/[a-z0-9\-]+\//i);var b=txReferencesPi1DetaiUrl+a[0];b=b.replace(/\/\//,"/");this.open(b)}}}},open:function(b){if(typeof SWFAddress!="undefined"){var a=this.getUrlValue(b);SWFAddress.setValue(a)}this.href=b;this.position();this.setup(true);this.options.contentsHeight=(this.options.contentHeight*Window.getHeight());this.options.contentsWidth=this.options.contentWidth*Window.getWidth();this.center.setStyles({width:this.options.contentsWidth+"px",height:this.options.contentsHeight+"px",marginLeft:"-"+(this.options.contentsWidth/2)+"px"});this.top=Window.getScrollTop()+((Window.getHeight()-this.options.contentsHeight-10)/2);this.center.setStyles({top:this.top+"px",display:""});this.positionClose();this.fx.overlay.start(0.8);return this.loadContents(b)},getUrlValue:function(b){var c="";if(b.search(/tx_references_pi1\[showUid\]=/)!=-1){var a=b.match(/tx_references_pi1\[showUid\]=(\d+)/);c="/projectId/"+a[1]}else{if(b.search(/\/project\//)!=-1){var a=b.match(/\/project\/[a-z0-9\-]+\//i);c=a[0]}}return c},position:function(){this.overlay.setStyles({top:Window.getScrollTop()+"px",height:Window.getHeight()+"px"})},resizeWindow:function(){this.position();this.options.contentsHeight=(this.options.contentHeight*Window.getHeight());this.options.contentsWidth=this.options.contentWidth*Window.getWidth();this.top=Window.getScrollTop()+((Window.getHeight()-this.options.contentsHeight-10)/2);this.fx.resize.start({top:this.top+"px",width:this.options.contentsWidth,marginLeft:-this.options.contentsWidth/2,height:this.options.contentsHeight});this.fx.resize.chain(this.positionClose.bind(this))},positionClose:function(){this.close.setStyles({top:this.top+"px",left:(Window.getWidth()-this.options.contentsWidth)/2+this.options.contentsWidth})},setup:function(a){var c=$A($$("object"));c.extend($$(window.ActiveXObject?"select":"embed"));c.each(function(d){d.style.visibility=a?"hidden":"visible"});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;this.close.setStyles({opacity:"0",width:"0px",display:"none"});this.center.className="mb_loading";this.fx.contents.set(0);this.contentsIframe=new Element("iframe").setProperties({id:"mb_contens_iframe",frameborder:"0",marginwidth:"0",marginheight:"0",scrolling:"no"}).setStyles({width:"100%",height:"100%",display:"none"}).injectInside(this.contents);this.contentsIframe.src=this.href;var a=this.nextEffect.bind(this);this.contentsIframe.addEvent("domready",a);return false},nextEffect:function(){switch(this.step++){case 1:this.center.className="";this.center.setStyle("cursor","default");this.close.setStyle("cursor","default");this.center.onclick=this.close.onclick="";if(this.center.clientHeight!=this.contents.offsetHeight){this.fx.resize.start({height:this.contents.offsetHeight});break}this.step++;case 2:this.close.setStyles({top:this.top+"px",display:""});this.fx.contents.start(1);break;case 3:if(this.options.animateCaption){this.fx.close.start({opacity:1,width:this.closeWidth});break}this.close.setStyles({opacity:"1",width:this.closeWidth+"px"});case 4:this.contentsIframe.setStyle("display","inline");this.step=0}},keyboardListener:function(a){if((a.control&&a.key=="w")||(a.control&&a.key=="x")||(a.key=="esc")){this.close();a.stop()}},closeMe: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.close.style.display="none";this.center.className="mb_loading";this.fx.overlay.chain(this.setup.pass(false,this)).start(0);this.contentsIframe.dispose();$("flashContent").setStyles({position:"relative",left:"0"});if(typeof SWFAddress!="undefined"){window.location.hash=""}return false}};window.addEvent("domready",MOOdalBox.init.bind(MOOdalBox));
