var SqueezeBox={presets:{size:{x:600,y:450},sizeLoading:{x:200,y:150},marginInner:{x:20,y:20},marginImage:{x:50,y:75},handler:false,target:null,closable:true,closeBtn:true,zIndex:65555,overlayOpacity:0.7,classWindow:'',classOverlay:'',overlayFx:{},resizeFx:{},contentFx:{},parse:false,parseSecure:false,ajaxOptions:{},onOpen:$empty,onClose:$empty,onUpdate:$empty,onResize:$empty,onMove:$empty,onShow:$empty,onHide:$empty},initialize:function(a){if(this.options)return this;this.presets=$merge(this.presets,a);this.options={};this.setOptions(this.presets).build();this.bound={window:this.reposition.bind(this,[null]),scroll:this.checkTarget.bind(this),close:this.close.bind(this),key:this.onKey.bind(this)};this.isOpen=this.isLoading=false;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.closeBtn=new Element('a',{id:'sbox-btn-close',href:'#'});this.win=new Element('div',{id:'sbox-window',styles:{display:'none',zIndex:this.options.zIndex+2}}).adopt(this.closeBtn,this.content);this.fx={overlay:new Fx.Tween(this.overlay,$merge({property:'opacity',onStart:Events.prototype.clearChain,duration:250,link:'cancel'},this.options.overlayFx)).set(0),win:new Fx.Morph(this.win,$merge({onStart:Events.prototype.clearChain,unit:'px',duration:750,transition:Fx.Transitions.Quint.easeOut,link:'cancel',unit:'px'},this.options.resizeFx)),content:new Fx.Tween(this.content,$merge({property:'opacity',duration:250,link:'cancel'},this.options.contentFx)).set(0)};$(document.body).adopt(this.overlay,this.win)},assign:function(a,b){return a.addEvent('click',function(){return!SqueezeBox.fromElement(this,b)})},fromElement:function(d,e){this.initialize();if(this.element)this.trash();this.element=$(d);this.setOptions($merge(this.presets,e||{}));if(this.element&&this.options.parse){var f=this.element.getProperty(this.options.parse);if(f&&(f=JSON.decode(f,this.options.parseSecure)))this.setOptions(f)}this.assignOptions();this.url=((this.element)?(this.options.url||this.element.get('href')):d)||'';var g=this.options.handler;if(g)return this.setContent(g,this.parsers[g].call(this,true));var h=false;this.parsers.some(function(a,b){var c=a.call(this);if(c){h=this.setContent(b,c);return true}return false},this);return h},assignOptions:function(){this.overlay.set('class',this.options.classOverlay);this.win.set('class',this.options.classWindow);if(Browser.Engine.trident4)this.win.addClass('sbox-window-ie6')},close:function(e){var a=($type(e)=='event');if(a)e.stop();if(!this.isOpen||(a&&!$lambda(this.options.closable).call(this,e)))return this;this.fx.overlay.start(0).chain(this.toggleOverlay.bind(this));this.win.setStyle('display','none');this.trash();this.toggleListeners();this.isOpen=false;this.fireEvent('onClose',[this.content]);return this},trash:function(){this.element=this.asset=null;this.options={};this.removeEvents().setOptions(this.presets).callChain()},onError:function(){this.asset=null;this.setContent('string','Error during loading')},setContent:function(a,b){if(!this.handlers[a])return false;this.content.className='sbox-content-'+a;this.applyTimer=this.applyContent.delay(this.fx.overlay.options.duration,this,this.handlers[a].call(this,b));if(this.overlay.retrieve('opacity'))return this;this.toggleOverlay(true);this.fx.overlay.start(this.options.overlayOpacity);return this.reposition()},applyContent:function(a,b){this.applyTimer=$clear(this.applyTimer);this.hideContent();if(!a){this.toggleLoading(true)}else{if(this.isLoading)this.toggleLoading(false);this.fireEvent('onUpdate',[this.content],20)}this.content.empty();if(['string','array',false].contains($type(a)))this.content.set('html',a||'');else this.content.adopt(a);this.callChain();if(!this.isOpen){this.toggleListeners(true);this.resize(b,true);this.isOpen=true;this.fireEvent('onOpen',[this.content])}else{this.resize(b)}},resize:function(a,b){var c=document.getSize(),scroll=document.getScroll();this.size=$merge((this.isLoading)?this.options.sizeLoading:this.options.size,a);var d={width:this.size.x,height:this.size.y,left:(scroll.x+(c.x-this.size.x-this.options.marginInner.x)/2).toInt(),top:(scroll.y+(c.y-this.size.y-this.options.marginInner.y)/2).toInt()};$clear(this.showTimer||null);this.hideContent();if(!b){this.fx.win.start(d).chain(this.showContent.bind(this))}else{this.win.setStyles(d).setStyle('display','');this.showTimer=this.showContent.delay(50,this)}return this.reposition()},toggleListeners:function(a){var b=(a)?'addEvent':'removeEvent';this.closeBtn[b]('click',this.bound.close);this.overlay[b]('click',this.bound.close);document[b]('keydown',this.bound.key)[b]('mousewheel',this.bound.scroll);window[b]('resize',this.bound.window)[b]('scroll',this.bound.window)},toggleLoading:function(a){this.isLoading=a;this.win[(a)?'addClass':'removeClass']('sbox-loading');if(a)this.fireEvent('onLoading',[this.win])},toggleOverlay:function(a){this.overlay.setStyle('display',(a)?'':'none');$(document.body)[(a)?'addClass':'removeClass']('body-overlayed')},showContent:function(){if(this.content.get('opacity'))this.fireEvent('onShow',[this.win]);this.fx.content.start(1)},hideContent:function(){if(!this.content.get('opacity'))this.fireEvent('onHide',[this.win]);this.fx.content.set(0)},onKey:function(e){switch(e.key){case'esc':this.close(e);case'up':case'down':return false}},checkTarget:function(e){return this.content.hasChild(e.target)},reposition:function(){var a=document.getSize(),scroll=document.getScroll();this.overlay.setStyles({left:scroll.x+'px',top:scroll.y+'px',width:a.x+'px',height:a.y+'px'});this.win.setStyles({left:(scroll.x+(a.x-this.win.offsetWidth)/2).toInt()+'px',top:(scroll.y+(a.y-this.win.offsetHeight)/2).toInt()+'px'});return this.fireEvent('onMove',[this.overlay,this.win])},removeEvents:function(a){if(!this.$events)return this;if(!a)this.$events=null;else if(this.$events[a])this.$events[a]=null;return this},extend:function(a){return $extend(this,a)},handlers:new Hash(),parsers:new Hash()};SqueezeBox.extend(new Events($empty)).extend(new Options($empty)).extend(new Chain($empty));SqueezeBox.parsers.extend({image:function(a){return(a||(/\.(?:jpg|png|gif)$/i).test(this.url))?this.url:false},clone:function(a){if($(this.options.target))return $(this.options.target);if(this.element&&!this.element.parentNode)return this.element;var b=this.url.match(/#([\w-]+)$/);return(b)?$(b[1]):(a?this.element:false)},ajax:function(a){return(a||(this.url&&!(/^(?:javascript|#)/i).test(this.url)))?this.url:false},iframe:function(a){return(a||this.url)?this.url:false},string:function(a){return true}});SqueezeBox.handlers.extend({image:function(b){var c,tmp=new Image();this.asset=null;tmp.onload=tmp.onabort=tmp.onerror=(function(){tmp.onload=tmp.onabort=tmp.onerror=null;if(!tmp.width){this.onError.delay(10,this);return}var a=document.getSize();a.x-=this.options.marginImage.x;a.y-=this.options.marginImage.y;c={x:tmp.width,y:tmp.height};for(var i=2;i--;){if(c.x>a.x){c.y*=a.x/c.x;c.x=a.x}else if(c.y>a.y){c.x*=a.y/c.y;c.y=a.y}}c.x=c.x.toInt();c.y=c.y.toInt();this.asset=$(tmp);tmp=null;this.asset.setProperties({width:c.x,height:c.y});if(this.isOpen)this.applyContent(this.asset,c)}).bind(this);tmp.src=b;if(tmp&&tmp.onload&&tmp.complete)tmp.onload();return(this.asset)?[this.asset,c]:null},clone:function(a){return a.clone()},adopt:$arguments(0),ajax:function(b){this.asset=new Request.HTML($merge({method:'get'},this.options.ajaxOptions)).addEvents({onSuccess:function(a){this.applyContent(a);this.asset=null}.bind(this),onFailure:this.onError.bind(this)});this.asset.send.delay(10,this.asset,[{url:b}])},iframe:function(a){return new Element('iframe',$merge({src:a,frameBorder:0,width:this.options.size.x,height:this.options.size.y},this.options.iframeOptions))},string:function(a){return a}});SqueezeBox.handlers.url=SqueezeBox.handlers.ajax;SqueezeBox.parsers.url=SqueezeBox.parsers.ajax;SqueezeBox.parsers.adopt=SqueezeBox.parsers.clone;