var joobibox={presets:{size:{x:600,y:450},sizeLoading:{x:200,y:150},marginInner:{x:20,y:20},marginImage:{x:150,y:200},handler:false,adopt:null,closeWithOverlay:true,zIndex:65555,overlayOpacity:0.7,classWindow:"",classOverlay:"",disableFx:false,onOpen:Class.empty,onClose:Class.empty,onUpdate:Class.empty,onResize:Class.empty,onMove:Class.empty,onShow:Class.empty,onHide:Class.empty,fxOverlayDuration:250,fxResizeDuration:750,fxContentDuration:250,ajaxOptions:{}},initialize:function(A){if(this.options){return this}this.presets=$merge(this.presets,A);this.setOptions(this.presets);this.build();this.listeners={window:this.reposition.bind(this,[null]),close:this.close.bind(this),key:this.onkeypress.bind(this)};this.isOpen=this.isLoading=false;this.window.close=this.listeners.close;return this},build:function(){this.overlay=new Element("div",{id:"sbox-overlay",styles:{display:"none",zIndex:this.options.zIndex}});this.content=new Element("div",{id:"sbox-content"});this.btnClose=new Element("a",{id:"sbox-btn-close",href:"#"});this.window=new Element("div",{id:"sbox-window",styles:{display:"none",zIndex:this.options.zIndex+2}}).adopt(this.btnClose,this.content);if(!window.ie6){this.overlay.setStyles({position:"fixed",top:0,left:0});this.window.setStyles({position:"fixed",top:"50%",left:"50%"})}else{this.overlay.style.setExpression("marginTop",'document.documentElement.scrollTop + "px"');this.window.style.setExpression("marginTop",'0 - parseInt(this.offsetHeight / 2) + document.documentElement.scrollTop + "px"');this.overlay.setStyles({position:"absolute",top:"0%",left:"0%"});this.window.setStyles({position:"absolute",top:"0%",left:"0%"})}$(document.body).adopt(this.overlay,this.window);this.fx={overlay:this.overlay.effect("opacity",{duration:this.options.fxOverlayDuration,wait:false}).set(0),window:this.window.effects({duration:this.options.fxResizeDuration,wait:false}),content:this.content.effect("opacity",{duration:this.options.fxContentDuration,wait:false}).set(0)}},addClick:function(A){return A.addEvent("click",function(){if(this.fromElement(A)){return false}}.bind(this))},fromElement:function(E,A){this.initialize();this.element=$(E);if(this.element&&this.element.rel){A=$merge(A||{},Json.evaluate(this.element.rel))}this.setOptions(this.presets,A);this.assignOptions();this.url=(this.element?(this.options.url||this.element.href):E)||"";if(this.options.handler){var D=this.options.handler;return this.setContent(D,this.parsers[D].call(this,true))}var C=false;for(var B in this.parsers){if((C=this.parsers[B].call(this))){return this.setContent(B,C)}}return this},assignOptions:function(){this.overlay.setProperty("class",this.options.classOverlay);this.window.setProperty("class",this.options.classWindow)},close:function(A){if(A){new Event(A).stop()}if(!this.isOpen){return this}this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));this.window.setStyle("display","none");this.trashImage();this.toggleListeners();this.isOpen=null;this.fireEvent("onClose",[this.content]).removeEvents();this.options={};this.setOptions(this.presets).callChain();return this},onError:function(){if(this.image){this.trashImage()}this.setContent("Error during loading")},trashImage:function(){if(this.image){this.image=this.image.onload=this.image.onerror=this.image.onabort=null}},setContent:function(A,B){this.content.setProperty("class","sbox-content-"+A);this.applyTimer=this.applyContent.delay(this.fx.overlay.options.duration,this,[this.handlers[A].call(this,B)]);if(this.overlay.opacity){return this}this.toggleOverlay(true);this.fx.overlay.start(this.options.overlayOpacity);this.reposition();return this},applyContent:function(B,A){this.applyTimer=$clear(this.applyTimer);this.hideContent();if(!B){this.toggleLoading(true)}else{if(this.isLoading){this.toggleLoading(false)}this.fireEvent("onUpdate",[this.content],20)}this.content.empty()[["string","array",false].contains($type(B))?"setHTML":"adopt"](B||"");this.callChain();if(!this.isOpen){this.toggleListeners(true);this.resize(A,true);this.isOpen=true;this.fireEvent("onOpen",[this.content])}else{this.resize(A)}},resize:function(B,A){var C=window.getSize();this.size=$merge(this.isLoading?this.options.sizeLoading:this.options.size,B);var D={width:this.size.x,height:this.size.y,marginLeft:-this.size.x/2,marginTop:-this.size.y/2};$clear(this.showTimer||null);this.hideContent();if(!A){this.fx.window.start(D).chain(this.showContent.bind(this))}else{this.window.setStyles(D).setStyle("display","");this.showTimer=this.showContent.delay(50,this)}this.reposition(C)},toggleListeners:function(B){var A=B?"addEvent":"removeEvent";this.btnClose[A]("click",this.listeners.close);if(this.options.closeWithOverlay){this.overlay[A]("click",this.listeners.close)}document[A]("keydown",this.listeners.key);window[A]("resize",this.listeners.window);window[A]("scroll",this.listeners.window)},toggleLoading:function(A){this.isLoading=A;this.window[A?"addClass":"removeClass"]("sbox-loading");if(A){this.fireEvent("onLoading",[this.window])}},toggleOverlay:function(A){this.overlay.setStyle("display",A?"":"none");$(document.body)[A?"addClass":"removeClass"]("body-overlayed")},showContent:function(){if(this.content.opacity){this.fireEvent("onShow",[this.window])}this.fx.content.start(1)},hideContent:function(){if(!this.content.opacity){this.fireEvent("onHide",[this.window])}this.fx.content.stop().set(0)},onkeypress:function(A){switch(A.key){case"esc":case"x":this.close();break}},reposition:function(A){A=A||window.getSize();this.overlay.setStyles({width:A.size.x,height:A.size.y});this.fireEvent("onMove",[this.overlay,this.window,A])},removeEvents:function(A){if(!this.$events){return this}if(!A){this.$events=null}else{if(this.$events[A]){this.$events[A]=null}}return this},parsers:{image:function(A){return(A||this.url.test(/\.(jpg|jpeg|png|gif|bmp)$/i))?this.url:false},adopt:function(A){if($(this.options.adopt)){return $(this.options.adopt)}if(A||($(this.element)&&!this.element.parentNode)){return $(this.element)}var B=this.url.match(/#([\w-]+)$/);return B?$(B[1]):false},url:function(A){return(A||(this.url&&!this.url.test(/^javascript:/i)))?this.url:false},iframe:function(A){return(A||this.url)?this.url:false},string:function(A){return true}},handlers:{image:function(A){this.image=new Image();var B={loaded:function(){var E={x:window.getWidth()-this.options.marginImage.x,y:window.getHeight()-this.options.marginImage.y};var D={x:this.image.width,y:this.image.height};for(var C=0;C<2;C++){if(D.x>E.x){D.y*=E.x/D.x;D.x=E.x}else{if(D.y>E.y){D.x*=E.y/D.y;D.y=E.y}}}D={x:parseInt(D.x),y:parseInt(D.y)};if(window.webkit419){this.image=new Element("img",{src:this.image.src})}else{$(this.image)}this.image.setProperties({width:D.x,height:D.y});this.applyContent(this.image,D)}.bind(this),failed:this.onError.bind(this)};(function(){this.src=A}).delay(10,this.image);this.image.onload=B.loaded;this.image.onerror=this.image.onabort=B.failed},adopt:function(A){return A.clone()},url:function(A){this.ajax=new Ajax(A,this.options.ajaxOptions);this.ajax.addEvent("onSuccess",function(B){this.applyContent(B);this.ajax=null}.bind(this));this.ajax.addEvent("onFailure",this.onError.bind(this));this.ajax.request.delay(10,this.ajax)},iframe:function(A){return new Element("iframe",{src:A,frameBorder:0,width:this.options.size.x,height:this.options.size.y})},string:function(A){return A}},extend:$extend};joobibox.extend(Events.prototype);joobibox.extend(Options.prototype);joobibox.extend(Chain.prototype);joobi.onDOMready(function(){joobibox.initialize({});$$("a[rev=joobibox]").each(function(A){A.addEvent("click",function(B){new Event(B).stop();joobibox.fromElement(A)})})});