(function(a){a.fn.extend({boxen:function(c,b){switch(typeof c){case"object":b=c;break;case"string":b=a.extend({},{url:c,urlAttribute:null},b);break}return this.click(function(d){a.Boxen.open(this,b);return false})}});a.Boxen={defaults:{urlParams:null,showTitleBar:true,showCloseButton:true,title:null,titleAttribute:"title",closeButtonText:null,width:600,height:500,url:null,urlAttribute:"href",overlayOpacity:0.8,modal:false,postOpen:function(b){},postClose:function(){}},bigIFrame:null,overlay:null,container:null,options:null,titleBar:null,closeButton:null,contentWindow:null,contentArea:null,ie6:false,setOptions:function(b){var c=a(window);this.options=a.extend({},this.defaults,b||{});this.options.width=Math.min(this.options.width,c.width()-10);this.options.height=Math.min(this.options.height,c.height()-10);return this},getFullUrl:function(){var b=this.options.url;if(this.options.urlParams){b+=b.indexOf("?")==-1?"?":"&";b+=a.param(this.options.urlParams)}return b},init:function(){_this=this;this.isIE6=a.browser.msie&&parseInt(a.browser.version)<7;if(a.browser.opera){a.support.opacity=true}a("#boxen_overlay, #boxen_container").remove();this.overlay=a("<div>").attr("id","boxen_overlay").css({opacity:this.options.overlayOpacity,display:"none",position:"absolute",top:0,left:0,zIndex:10000});if(!this.options.modal){this.overlay.click(function(b){a.Boxen.close();return false})}this.container=a("<div>").attr("id","boxen_container").width(this.options.width).height(this.options.height).css({position:"absolute",left:"50%",top:"50%",marginLeft:Math.round(this.options.width/-2)+"px",marginTop:Math.round(this.options.height/-2)+"px",display:"none",zIndex:10001});if(this.isIE6){this.bigIFrame=a("<iframe>").attr("id","boxen_big_iframe").css({zIndex:9999,position:"absolute",top:0,left:0,opacity:0}).appendTo("body");this._sizeOverlay();this._centreContent();a(window).bind("scroll.Boxen",function(b){_this._centreContent()}).bind("resize.Boxen",function(b){_this._sizeOverlay();_this._centreContent()})}else{this.overlay.css({position:"fixed",width:"100%",height:"100%"});this.container.css("position","fixed")}this.overlay.appendTo("body");this.container.appendTo("body");this.contentWindow=a("<div>").attr("id","boxen_content").appendTo(this.container);if(this.options.showTitleBar){this.titleBar=a("<div>").attr("id","boxen_titlebar").append(a("<span>").attr("id","boxen_title").html(this.options.title)).appendTo(this.contentWindow)}else{this.titleBar=null}if(this.options.showCloseButton){this.closeButton=a("<a>").attr({href:"#",id:"boxen_close_button"}).click(function(b){a.Boxen.close();return false}).appendTo(this.contentWindow);if(this.options.closeButtonText){this.closeButton.append(a("<span>").html(this.options.closeButtonText))}}else{this.closeButton=null}this.contentArea=a("<div>").attr("id","boxen_content_area").appendTo(this.contentWindow);return this},show:function(b){this.overlay.fadeIn("fast");this.container.fadeIn("fast",function(){var d=a.Boxen;if(null!==d.options.url){var c=a("<iframe>").attr({id:"boxen_iframe_content_"+new Date().getTime(),width:d.getContentAreaWidth(),height:d.getContentAreaHeight(),frameborder:0,src:d.getFullUrl()}).appendTo(d.contentArea)}else{d.contentArea.width(d.getContentAreaWidth()).height(d.getContentAreaHeight())}d.options.postOpen(d.getContentAreaElement())});return this},close:function(){try{if(this.isIE6){a(window).unbind("scroll.Boxen").unbind("resize.Boxen");throw"IE6"}this.container.fadeOut("fast",function(){a(this).remove()});this.overlay.fadeOut("fast",function(){a(this).remove()})}catch(b){a("#boxen_big_iframe, #boxen_overlay, #boxen_container").remove()}this.options.postClose();return this},open:function(c,b){this.setOptions(b);this.options.title=this.options.titleAttribute&&a(c).attr(this.options.titleAttribute)||this.options.title;this.options.url=this.options.urlAttribute&&a(c).attr(this.options.urlAttribute)||this.options.url;this.init().show();return this},_centreContent:function(){if(this.options.height<a(window).height()){var b=Math.round(this.options.height/-2)+a(document).scrollTop();this.container.css({marginTop:b+"px"})}},_sizeOverlay:function(){var c=a(document),b={width:(c.width()-21)+"px",height:(c.height()-4)+"px"};this.bigIFrame.css(b);this.overlay.css(b)},getContentAreaElement:function(){return this.contentArea.get(0)},getContentAreaHeight:function(){return this.titleBar?this.options.height-this.titleBar.outerHeight():this.options.height},getContentAreaWidth:function(){return this.options.width}}})(jQuery);
