var lightbox;var Lightbox=Class.create({showHtml:function(a,b){this.prepareToShow();this.content.update(a);this.lightbox.fire("lightbox:contentUpdated");if(Object.isUndefined(b)||b===true){this.doShow()}},show:function(a){this.prepareToShow();lightbox.getAndShowContentFromUrl(a)},hide:function(){if(this.historyPolling!==null){this.historyPolling.stop()}this.lightbox.hide();this.content.hide();this.overlay.hide();this.spinner.hide();this.htmlElement.setStyle({overflow:this.htmlOverflowStyle});this.contentDimensionChangedRunner.stop();Event.stopObserving(window,"resize",this.windowResizeListenerObj);this.content.stopObserving("lightbox:contentDimensionChanged",this.windowResizeListenerObj);this.lightbox.stopObserving("lightbox:contentUpdated");this.showPersistentObjects(true);this.content.update();if(window.location.hash=="#modal"){history.go(-1)}this.container.setStyle({width:this.originalContainerWidth+"px"})},initializeLightboxAnchors:function(a){var b=[];if(Object.isUndefined(a)){b=$$("a.lightbox")}else{b=a.select("a.lightbox")}b.each(function(c){c.observe("click",function(e){e.stop();var d=Event.findElement(e,"a");if(d!=document){lightbox.activeElement=d;lightbox.show(d.getAttribute("href"))}})})},isVisible:function(){return this.lightbox.visible()},initialize:function(){this.history={};this.historyPolling=null;this.htmlElement=$$("html").first();var b=$$("body").first();if(Prototype.Browser.IE){var c=document.createElement("iframe");c.setAttribute("id","lightbox-history-frame");c.src="/history-frame.php";c.style.display="block";c.style.visibility="hidden";c.style.position="absolute";c.style.top="0";c.style.left="0";c.style.width="1px";c.style.height="1px";b.appendChild(c);this.historyFrame=c}b.insert({bottom:'<div id="lightbox"></div><div id="lightbox-spinner"></div>'});var e=$("lightbox");e.setStyle({display:"none"});e.update('<div id="lightbox-overlay"></div><div id="lightbox-container"></div>');var a=$("lightbox-container");a.update('<div id="lightbox-close-container"><a href="#" id="lightbox-close"><span>Close</span></a></div>');a.insert({bottom:'<div id="lightbox-default-focus" style="display:none;"><input type="text" name="lightbox-default-focus"/></div>'});a.insert({bottom:'<div id="lightbox-start"><div class="left"></div><div class="right"></div></div><div id="lightbox-content-left"></div><div id="lightbox-content-right"></div><div id="lightbox-outer-content"><div id="lightbox-content"></div></div><div id="lightbox-end"><div class="left"></div><div class="right"></div></div>'});this.content=$("lightbox-content");this.lightbox=$("lightbox");this.container=$("lightbox-container");this.overlay=$("lightbox-overlay");this.spinner=$("lightbox-spinner");this.defaultFocusElement=$("lightbox-default-focus").down();this.spinner.setStyle({position:"absolute",zIndex:1000,display:"none"});this.containerTop=Element.getDimensionFromStyle(this.container,"top");if(Prototype.Browser.Gecko){this.overlay.setStyle({background:"url(/images/lightbox/ff-overlay-img.png)"})}else{this.overlay.setStyle({opacity:0.5})}document.observe("keydown",this.keydownListener.bindAsEventListener(this));this.lightbox.observe("click",this.lightboxClickListener.bindAsEventListener(this));$("lightbox-close").observe("click",this.clickToCloseListener.bindAsEventListener(this));this.overlay.observe("click",this.clickToCloseListener.bindAsEventListener(this));this.lightbox.observe("lightbox:contentReady",this.contentReadyListener.bindAsEventListener(this));this.lightbox.observe("lightbox:cpWriteMediaObjectRun",this.cpWriteMediaObjectRunListener.bindAsEventListener(this));if(Prototype.Browser.IE&&(typeof document.documentMode=="undefined"||document.documentMode==7)){var d=1000;this.container.select("div").each(function(f){f.style.zIndex=d--})}},getContainerHorizontalPadding:function(){if(typeof this.containerPadding=="undefined"){var d=this.content;var c=0;var a=0;while(d!==null&&d!=this.container&&a<50){c+=Element.getDimensionFromStyle(d,"padding-left");c+=Element.getDimensionFromStyle(d,"padding-right");c+=Element.getDimensionFromStyle(d,"margin-left");c+=Element.getDimensionFromStyle(d,"margin-right");var b=d;d=d.getOffsetParent();if(d==b){alert("Error: Could not resolve offsetParent - does the stylesheet contain all required styles?");break}}this.containerPadding=c}return this.containerPadding},prepareHistory:function(){if(Prototype.Browser.IE){this.historyFrame.src="/history-frame.php?modal"}else{window.location.hash="#modal"}this.historyPolling=new PeriodicalExecuter(function(a){var d=false;if(Prototype.Browser.IE){var b=this.historyFrame.contentWindow.document.title;if(b.indexOf("?modal")<0){d=true}}else{var c=window.location.hash;if(window.location.hash!="#modal"){d=true}}if(d){a.stop();if(this.isVisible()){this.hide()}}}.bind(this),0.5)},showPersistentObjects:function(a){$$("select","embed","object").each(function(b){if(a){b.style.visibility="visible"}else{b.style.visibility="hidden"}})},prepareToShow:function(){if(!this.prepared){if(this.isVisible()){this.hide()}this.prepareHistory();this.content.hide();this.showPersistentObjects(false);this.overlay.show();this.container.hide();this.lightbox.show();this.scolloffset=document.viewport.getScrollOffsets();this.htmlOverflowStyle=this.htmlElement.getStyle("overflow");this.htmlElement.setStyle({overflow:"hidden"});this.repositionLightboxAndOverlay();this.repositionSpinner();this.spinner.show();this.prepared=true}},repositionLightboxAndOverlay:function(){var c=document.viewport.getScrollOffsets();var a=document.viewport.getDimensions();var d=this.container.getDimensions();var e=[d.height+this.containerTop,a.height].max();var b=[d.width,a.width].max();this.lightbox.setStyle({top:c.top+"px",left:c.left+"px",width:a.width+"px",height:a.height+"px"});this.overlay.setStyle({left:"0px",top:"0px",height:e+"px",width:b+"px"})},doShow:function(){if(!this.prepared){this.prepareToShow()}this.prepared=false;this.content.show();this.container.setStyle({visibility:"hidden"});this.container.show();if(Object.isUndefined(this.originalContainerWidth)||this.originalContainerWidth===null){this.originalContainerWidth=this.container.getWidth()}this.windowResizeListenerObj=this.windowResizeListener.bindAsEventListener(this);Event.observe(window,"resize",this.windowResizeListenerObj);this.content.observe("lightbox:contentDimensionChanged",this.windowResizeListenerObj);this.lastContentDimensions=this.content.getDimensions();this.contentDimensionChangedRunner=new PeriodicalExecuter(function(g){var h=this.content.getDimensions();if(h.height!=this.lastContentDimensions.height||h.width!=this.lastContentDimensions.width){this.content.fire("lightbox:contentDimensionChanged")}this.lastContentDimensions=this.content.getDimensions()}.bind(this),0.5);var b=-1;var a=false;var f=this.content.down("div");if(typeof f!="undefined"&&f.identify()!="lightbox_flash_container"&&f.getWidth()>0){this.setContentWidth(f.getWidth());a=true}else{var d=this.content.down();var c;if(d!==null&&typeof d!="undefined"){if(d.tagName=="IMG"){c=d.getWidth();if(c>0){this.setContentWidth(c);a=true}else{d.observe("load",this.resizeContentToImageSizeListener.bindAsEventListener(this))}}else{if(d.identify()=="lightbox_flash_container"&&d.down()!==null){if(d.down()!==null){var e=d.down().getDimensionFromStyle("width");if(e>0){this.setContentWidth(e);a=true}}else{}}else{a=true}}}else{a=true}}if(a){this.lightbox.fire("lightbox:contentReady")}this.lightbox.fire("lightbox:doShowFinished")},getAndShowContentFromUrl:function(f){if(f===null){alert("No URL provided");return}if(f.match(/\.(jpg|jpeg|png|gif)$/)){var g=new Image();Event.observe(g,"load",function(m){this.showHtml('<img src="'+f+'" alt=""/>')}.bindAsEventListener(this));g.src=f}else{if(f.match(/\.(swf|flv)/)){var h='<div id="lightbox_flash_container"></div>';var d;var k;var l=500;var a=300;if(typeof this.activeElement!="undefined"){var b=this.activeElement.readAttribute("name");if(b!==null&&b.match(/width\d+height\d/)){d=b.match(/width(\d+)/).last();k=b.match(/height(\d+)/).last()}}var j=f.match(/\.(swf|flv)$/).last();var c="";switch(j){case"swf":c="application/x-shockwave-flash";var e={};break;case"flv":c="video/flv";var i={floatingcontrols:"true"};break}this.lightbox.observe("lightbox:contentUpdated",function(m){if(typeof d!="undefined"&&typeof k!="undefined"){this.insertMediaObject(f,d,k,c,i)}else{var n={service:"mmarchive.fileinfo",fileUrl:f};new Ajax.Request("/xmlhttprequest.php",{parameters:n,onSuccess:function(o){var p=o.responseText.evalJSON();this.insertMediaObject(f,p.width,p.height,c,i)}.bind(this),onFailure:function(){this.insertMediaObject(f,l,a,c,i)}.bind(this)})}}.bindAsEventListener(this));this.showHtml(h,false)}else{new Ajax.Request(f,{method:"get",onSuccess:function(r){var p=r.responseText;if(p.match(/<body\b/)){var n=p.match(/<div id="placeholder-content">([\s\S]*?)<div id="placeholder-/);if(n===null){n=p.match(/<div id="placeholder-content-no-right">([\s\S]*?)<div id="placeholder-/)}if(n!==null){var m=n.first();n=m.match(/([\s\S]*)<\/div>/);p=n.first();p=p.replace(/placeholder-content(-no-right)?/,"lightbox-placeholder-content")}}this.content.update(p);var o=this.content.select("div[id=lightbox-placeholder-content]").first();var q=o.select("div.tile-common");q.each(function(s){s.classNames().each(function(t){if(t=="tile-common"){return}o.addClassName(t+"-lightbox")})});this.lightbox.fire("lightbox:contentUpdated");this.doShow()}.bind(this),onFailure:function(m){this.hide();alert("Could not connect to URL")}.bind(this)})}}},insertMediaObject:function(b,c,a,e,d){cpWriteMediaObject(b,"null",c,a,e,0,1,"null","lightbox_flash_container",d,true);this.lightbox.fire("lightbox:cpWriteMediaObjectRun")},repositionSpinner:function(){var b=document.viewport.getScrollOffsets();var a=document.viewport.getDimensions();this.spinner.setStyle({top:b.top+"px",left:b.left+"px",width:a.width+"px",height:a.height+"px"})},setContentWidth:function(a){this.container.setStyle({width:a+this.getContainerHorizontalPadding()+"px"})},setDefaultFocus:function(){try{this.defaultFocusElement.focus()}catch(a){}},contentReadyListener:function(a){lightbox.initializeLightboxAnchors(this.content);this.container.setStyle({visibility:"visible"});this.spinner.hide();this.repositionLightboxAndOverlay();this.setDefaultFocus()},windowResizeListener:function(a){this.repositionLightboxAndOverlay()},resizeContentToImageSizeListener:function(a){this.setContentWidth(a.element().getHiddenElementDimensions().width);this.lightbox.fire("lightbox:contentReady")},cpWriteMediaObjectRunListener:function(b){var a=$("lightbox_flash_container").down();if(a!==null){this.setContentWidth(a.getDimensionFromStyle("width"));this.lightbox.fire("lightbox:contentReady")}this.doShow()},keydownListener:function(a){if(lightbox.isVisible()){if(a.keyCode==Event.KEY_ESC){this.clickToCloseListener(a)}if([32,Event.KEY_RETURN,Event.KEY_TAB,Event.KEY_UP,Event.KEY_DOWN].indexOf(a.keyCode)>-1){if(!a.element().descendantOf(this.lightbox)){a.stop()}}}},lightboxClickListener:function(c){var b=c.element();var a=c.findElement("a");if(["INPUT","BUTTON","A"].indexOf(b.nodeName)==-1&&Object.isUndefined(a)){c.stop()}},clickToCloseListener:function(a){a.stop();this.hide()}});document.observe("dom:loaded",function(a){lightbox=new Lightbox();lightbox.initializeLightboxAnchors()});
