/* Copyright (c) 2010 Björn Wikström, Welcom Web, MIT Style License, http://www.opensource.org/licenses/mit-license.php */Wel={};Wel.Box=new Class({__type:3840,__elements:[],__titles:[],__options:{loader:"/images/bouncy.gif","background-opacity":".7","controls-opacity":".5","control-next-title":"next","control-prev-title":"prev",width:700,height:304},initialize:function(b,c,a){if(a&&typeof a=="object"){this.__mergeOptions(a)}this.__type=c;if(typeof b=="string"){this.__attachClass(b)}else{this.__attachElement(b)}},__attachClass:function(a){var b=this;$$("."+a).each(function(d,c){b.__elements.push(d.get("href"));var e="";if(d.getProperty("title")){e=d.getProperty("title")}b.__titles.push(e);d.addEvent("click",function(f){new Event(f).stop();b.__showOverlay(c)})})},__attachElement:function(b){this.__elements.push(b.get("href"));var c="";if(b.getProperty("title")){c=b.getProperty("title")}this.__titles.push(c);var a=this;b.addEvent("click",function(d){new Event(d).stop();a.__showOverlay(0)})},__createOverlay:function(){if(!Wel.Box.__overlay){Wel.Box.__overlay=new Element("div").set("id","welbox-background-layer").addClass("welbox-background-layer").setStyles({width:(window.getSize().x+50)+"px",height:window.getSize().y+"px",opacity:0});if(Browser.Engine.trident&&Browser.Engine.version<6){Wel.Box.__overlay.addClass("welbox-background-layer-ie-fix")}Wel.Box.__overlay.inject(document.body);Wel.Box.__overlay.addEvent("click",function(a){new Event(a).stop();Wel.Box.close()})}},__showOverlay:function(a){this.__createOverlay();var b=this;Wel.Box.__overlay.set("morph",{duration:500,onStart:function(){Wel.Box.__overlay.setStyle("display","block")},onComplete:function(){b.__openBox(a)}});Wel.Box.__overlay.morph({opacity:b.__options["background-opacity"]})},__openBox:function(a){var b=new Element("div").set("id","welbox-popup-layer").addClass("welbox-popup-layer").setStyles({top:(window.getSize().y/2)+"px",left:(window.getSize().x/2)+"px","text-align":"center"}).set("html",'<img src="'+this.__options.loader+'" style="border: 0; padding: 2px;" />');if(Browser.Engine.trident&&Browser.Engine.version<6){b.addClass("welbox-popup-layer-ie-fix")}b.inject(document.body);if(this.__type==Wel.Box.GALLERY){this.__showImage(a)}else{if(this.__type==Wel.Box.INLINE){this.__showInline(a)}else{this.__showAjax(a)}}},__showImage:function(b){var c=this;var a=new Image();a.onload=function(){c.__setPopupTransformation(a,b)};a.title="welbox-image";a.src=this.__elements[b]},__showInline:function(a){if(!this.__options.element){return}if(typeof this.__options.element=="string"){this.__options.element=$(this.__options.element)}$("welbox-popup-layer").empty();var b=this;$("welbox-popup-layer").set("morph",{duration:300,onComplete:function(){b.__setElementStyles(b.__options.element);b.__options.element.setStyle("display","block");b.__createInnerLayer();b.__injectElement(b.__options.element);if(b.__elements.length>1){b.__setUpControls(a)}b.__options.element.morph({opacity:1})}});this.__startTransformation()},__showAjax:function(a){var b=this;new Request({method:"post",url:b.__elements[a],data:{welboxed:"true"},evalScripts:true,onComplete:function(c){var d=new Element("div").set("html",c);b.__setPopupTransformation(d,a)}}).send()},__setPopupTransformation:function(b,a){$("welbox-popup-layer").empty();var c=this;$("welbox-popup-layer").set("morph",{duration:300,onComplete:function(){c.__setElementStyles(b);c.__createInnerLayer();c.__injectElement(b);if(c.__elements.length>1){c.__setUpControls(a)}b.morph({opacity:1})}});c.__startTransformation(b)},__startTransformation:function(b){var c,a=0;if(this.__type==Wel.Box.GALLERY){c=b.width+30;a=b.height+30}else{c=this.__options.width;a=this.__options.height}$("welbox-popup-layer").morph({width:c+"px",height:a+"px",top:((window.getSize().y/2)-(a/2))+"px",left:((window.getSize().x/2)-(c/2))+"px"})},__setElementStyles:function(a){a.setStyles({opacity:0})},__createInnerLayer:function(){new Element("div").set("id","welbox-inner-layer").inject($("welbox-popup-layer"));if(this.__type==Wel.Box.GALLERY){$("welbox-inner-layer").addClass("gallery-container")}else{if(this.__type==Wel.Box.INLINE){$("welbox-inner-layer").addClass("inline-container")}else{$("welbox-inner-layer").addClass("ajax-container")}}},__injectElement:function(a){a.inject($("welbox-inner-layer"))},__setUpControls:function(a){var b=this;if(a>0){new Element("div").set("id","welbox-prev-control").addClass("welbox-popup-control").setStyle("opacity",b.__options["controls-opacity"]).inject($("welbox-inner-layer")).addEvent("click",function(c){new Event(c).stop();b.__openSmooth(a-1)});new Element("a").set("html",b.__titles[a-1]).inject($("welbox-prev-control"))}if(a<(b.__elements.length-1)){new Element("div").set("id","welbox-next-control").addClass("welbox-popup-control").setStyle("opacity",b.__options["controls-opacity"]).inject($("welbox-inner-layer")).addEvent("click",function(c){new Event(c).stop();b.__openSmooth(a+1)});new Element("a").set("html",b.__titles[a+1]).inject($("welbox-next-control"))}},__openSmooth:function(a){var b=this;$$(".welbox-popup-control").dispose();$("welbox-popup-layer").set("morph",{onComplete:function(){$("welbox-popup-layer").dispose();b.__openBox(a)}});$("welbox-popup-layer").morph({opacity:0})},__mergeOptions:function(a){for(prop in a){this.__options[prop]=a[prop]}}});Wel.Box.AJAX=3840;Wel.Box.GALLERY=47806;Wel.Box.INLINE=2816;Wel.Box.__overlay=false;Wel.Box.close=function(){if($defined($("welbox-background-layer"))){$("welbox-background-layer").set("morph",{duration:300,onStart:function(){if($defined($("welbox-popup-layer"))){$("welbox-popup-layer").dispose()}},onComplete:function(){$("welbox-background-layer").setStyle("display","none")}});$("welbox-background-layer").morph({opacity:0})}};Wel.Box.open=function(c,d,b){var a=new Element("a").set("href",c).setStyle("display","none").addClass("welbox-temporary-opener").inject($(document.body));new Wel.Box("welbox-temporary-opener",d,b);(function(){a.fireEvent("click",a);a.dispose()}).delay(100)};Wel.Box.inline=function(b){var a=new Element("a").set("id","welbox-temporary-opener").set("href","#").setStyle("display","none").inject($(document.body));new Wel.Box($("welbox-temporary-opener"),Wel.Box.INLINE,b);(function(){a.fireEvent("click",a);a.dispose()}).delay(100)};