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 _INITIAL_WIDTH=250;
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({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.error=new Element("div").setProperty("id","mb_error").set("html",_ERROR_MESSAGE);
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),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
},loadLocationData:function(){return $("locationBean")
},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.center.className="mb_loading";
this.fx.contents.set(0);
var C=this.nextEffect.bind(this);
var B=this.ajaxFailure.bind(this);
var A={async:false,method:"post",data:$("locationBean")?$("locationBean"):" no data ",url:this.href,update:this.contents,evalScripts:this.options.evalScripts,evalResponse:this.options.evalResponse,onComplete:C,onFailure:B,onSuccess:function(G,E,H,F){isResponseCorrect(H)
}};
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.center.onclick=this.close.bind(this)
},nextEffect:function(){switch(this.step++){case 1:this.center.className="";
this.center.setStyle("cursor","default");
this.center.onclick="";
this.contents.setStyles({width:this.options.contentsWidth+"px",height:"auto"});
this.center.setStyles({width:this.contents.offsetWidth,marginLeft:-this.contents.offsetWidth/2,height:"auto"});
this.fx.contents.start(1);
var A=$("mb_close");
if(A){A.onclick=this.overlay.onclick
}var B=$("mb_submit");
this.step=0;
redrawBtns();
break
}setNodeFocus()
},keyboardListener:function(A){if((A.control&&A.key=="w")||(A.key=="esc")){this.close();
A.stop()
}},loading:function(){this.center.setStyles({display:""});
this.center.className="mb_loading";
this.contents.setStyles({visibility:"hidden"});
return false
},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="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));
