jQuery.fn.boxy=function(d){d=d||{};return this.each(function(){var c=this.nodeName.toLowerCase(),self=this;if(c=='a'){jQuery(this).click(function(){var a=Boxy.linkedTo(this),href=this.getAttribute('href'),localOptions=jQuery.extend({actuator:this,title:this.title},d);if(a){a.show()}else if(href.indexOf('#')>=0){var b=jQuery(href.substr(href.indexOf('#'))),newContent=b.clone(true);b.remove();localOptions.unloadOnHide=false;new Boxy(newContent,localOptions)}else{if(!localOptions.cache)localOptions.unloadOnHide=true;Boxy.load(this.href,localOptions)}return false})}else if(c=='form'){jQuery(this).bind('submit.boxy',function(){Boxy.confirm(d.message||'Please confirm:',function(){jQuery(self).unbind('submit.boxy').submit()});return false})}})};function Boxy(a,b){this.boxy=jQuery(Boxy.WRAPPER);jQuery.data(this.boxy[0],'boxy',this);this.visible=false;this.options=jQuery.extend({},Boxy.DEFAULTS,b||{});if(this.options.modal){this.options=jQuery.extend(this.options,{center:true,draggable:false})}if(this.options.actuator){jQuery.data(this.options.actuator,'active.boxy',this)}this.setContent(a||"<div></div>");this._setupTitleBar();this.boxy.css('display','none').appendTo(document.body);this.toTop();if(this.options.fixed){if(jQuery.browser.msie&&jQuery.browser.version<7){this.options.fixed=false}else{this.boxy.addClass('fixed')}}if(this.options.center&&Boxy._u(this.options.x,this.options.y)){this.center()}else{this.moveTo(Boxy._u(this.options.x)?this.options.x:Boxy.DEFAULT_X,Boxy._u(this.options.y)?this.options.y:Boxy.DEFAULT_Y)}if(this.options.show)this.show()};Boxy.EF=function(){};jQuery.extend(Boxy,{WRAPPER:"<table cellspacing='0' cellpadding='0' border='0' class='boxy-wrapper'>"+"<tr><td class='top-left'></td><td class='top'></td><td class='top-right'></td></tr>"+"<tr><td class='left'></td><td class='boxy-inner'></td><td class='right'></td></tr>"+"<tr><td class='bottom-left'></td><td class='bottom'></td><td class='bottom-right'></td></tr>"+"</table>",DEFAULTS:{title:null,closeable:true,draggable:true,clone:false,actuator:null,center:true,show:true,modal:false,fixed:true,closeText:'[close]',unloadOnHide:false,clickToFront:false,behaviours:Boxy.EF,afterDrop:Boxy.EF,afterShow:Boxy.EF,afterHide:Boxy.EF,beforeUnload:Boxy.EF},DEFAULT_X:50,DEFAULT_Y:50,zIndex:1337,dragConfigured:false,resizeConfigured:false,dragging:null,load:function(b,c){c=c||{};var d={url:b,type:'GET',dataType:'html',cache:false,success:function(a){a=jQuery(a);if(c.filter)a=jQuery(c.filter,a);new Boxy(a,c)}};jQuery.each(['type','cache'],function(){if(this in c){d[this]=c[this];delete c[this]}});jQuery.ajax(d)},get:function(a){var p=jQuery(a).parents('.boxy-wrapper');return p.length?jQuery.data(p[0],'boxy'):null},linkedTo:function(a){return jQuery.data(a,'active.boxy')},alert:function(a,b,c){return Boxy.ask(a,['OK'],b,c)},confirm:function(b,c,d){return Boxy.ask(b,['OK','Cancel'],function(a){if(a=='OK')c()},d)},ask:function(b,c,d,e){e=jQuery.extend({modal:true,closeable:false},e||{},{show:true,unloadOnHide:true});var f=jQuery('<div></div>').append(jQuery('<div class="question"></div>').html(b));var g={},answerStrings=[];if(c instanceof Array){for(var i=0;i<c.length;i++){g[c[i]]=c[i];answerStrings.push(c[i])}}else{for(var k in c){g[c[k]]=k;answerStrings.push(c[k])}}var h=jQuery('<form class="answers"></form>');h.html(jQuery.map(answerStrings,function(v){return"<input type='button' value='"+v+"' />"}).join(' '));jQuery('input[type=button]',h).click(function(){var a=this;Boxy.get(this).hide(function(){if(d)d(g[a.value])})});f.append(h);new Boxy(f,e)},isModalVisible:function(){return jQuery('.boxy-modal-blackout').length>0},_u:function(){for(var i=0;i<arguments.length;i++)if(typeof arguments[i]!='undefined')return false;return true},_handleResize:function(a){var d=jQuery(document);jQuery('.boxy-modal-blackout').css('display','none').css({width:d.width(),height:d.height()}).css('display','block')},_handleDrag:function(a){var d;if(d=Boxy.dragging){d[0].boxy.css({left:a.pageX-d[1],top:a.pageY-d[2]})}},_nextZ:function(){return Boxy.zIndex++},_viewport:function(){var d=document.documentElement,b=document.body,w=window;return jQuery.extend(jQuery.browser.msie?{left:b.scrollLeft||d.scrollLeft,top:b.scrollTop||d.scrollTop}:{left:w.pageXOffset,top:w.pageYOffset},!Boxy._u(w.innerWidth)?{width:w.innerWidth,height:w.innerHeight}:(!Boxy._u(d)&&!Boxy._u(d.clientWidth)&&d.clientWidth!=0?{width:d.clientWidth,height:d.clientHeight}:{width:b.clientWidth,height:b.clientHeight}))}});Boxy.prototype={estimateSize:function(){this.boxy.css({visibility:'hidden',display:'block'});var a=this.getSize();this.boxy.css('display','none').css('visibility','visible');return a},getSize:function(){return[this.boxy.width(),this.boxy.height()]},getContentSize:function(){var c=this.getContent();return[c.width(),c.height()]},getPosition:function(){var b=this.boxy[0];return[b.offsetLeft,b.offsetTop]},getCenter:function(){var p=this.getPosition();var s=this.getSize();return[Math.floor(p[0]+s[0]/2),Math.floor(p[1]+s[1]/2)]},getInner:function(){return jQuery('.boxy-inner',this.boxy)},getContent:function(){return jQuery('.boxy-content',this.boxy)},setContent:function(a){a=jQuery(a).css({display:'block'}).addClass('boxy-content');if(this.options.clone)a=a.clone(true);this.getContent().remove();this.getInner().append(a);this._setupDefaultBehaviours(a);this.options.behaviours.call(this,a);return this},moveTo:function(x,y){this.moveToX(x).moveToY(y);return this},moveToX:function(x){if(typeof x=='number')this.boxy.css({left:x});else this.centerX();return this},moveToY:function(y){if(typeof y=='number')this.boxy.css({top:y});else this.centerY();return this},centerAt:function(x,y){var s=this[this.visible?'getSize':'estimateSize']();if(typeof x=='number')this.moveToX(x-s[0]/2);if(typeof y=='number')this.moveToY(y-s[1]/2);return this},centerAtX:function(x){return this.centerAt(x,null)},centerAtY:function(y){return this.centerAt(null,y)},center:function(a){var v=Boxy._viewport();var o=this.options.fixed?[0,0]:[v.left,v.top];if(!a||a=='x')this.centerAt(o[0]+v.width/2,null);if(!a||a=='y')this.centerAt(null,o[1]+v.height/2);return this},centerX:function(){return this.center('x')},centerY:function(){return this.center('y')},resize:function(a,b,c){if(!this.visible)return;var d=this._getBoundsForResize(a,b);this.boxy.css({left:d[0],top:d[1]});this.getContent().css({width:d[2],height:d[3]});if(c)c(this);return this},tween:function(a,b,c){if(!this.visible)return;var d=this._getBoundsForResize(a,b);var e=this;this.boxy.stop().animate({left:d[0],top:d[1]});this.getContent().stop().animate({width:d[2],height:d[3]},function(){if(c)c(e)});return this},isVisible:function(){return this.visible},show:function(){if(this.visible)return;if(this.options.modal){var c=this;if(!Boxy.resizeConfigured){Boxy.resizeConfigured=true;jQuery(window).resize(function(){Boxy._handleResize()})}this.modalBlackout=jQuery('<div class="boxy-modal-blackout"></div>').css({zIndex:Boxy._nextZ(),opacity:0.7,width:jQuery(document).width(),height:jQuery(document).height()}).appendTo(document.body);this.toTop();if(this.options.closeable){jQuery(document.body).bind('keypress.boxy',function(a){var b=a.which||a.keyCode;if(b==27){c.hide();jQuery(document.body).unbind('keypress.boxy')}})}}this.boxy.stop().css({opacity:1}).show();this.visible=true;this._fire('afterShow');return this},hide:function(a){if(!this.visible)return;var b=this;if(this.options.modal){jQuery(document.body).unbind('keypress.boxy');this.modalBlackout.animate({opacity:0},function(){jQuery(this).remove()})}this.boxy.stop().animate({opacity:0},300,function(){b.boxy.css({display:'none'});b.visible=false;b._fire('afterHide');if(a)a(b);if(b.options.unloadOnHide)b.unload()});return this},toggle:function(){this[this.visible?'hide':'show']();return this},hideAndUnload:function(a){this.options.unloadOnHide=true;this.hide(a);return this},unload:function(){this._fire('beforeUnload');this.boxy.remove();if(this.options.actuator){jQuery.data(this.options.actuator,'active.boxy',false)}},toTop:function(){this.boxy.css({zIndex:Boxy._nextZ()});return this},getTitle:function(){return jQuery('> .title-bar h2',this.getInner()).html()},setTitle:function(t){jQuery('> .title-bar h2',this.getInner()).html(t);return this},_getBoundsForResize:function(a,b){var c=this.getContentSize();var d=[a-c[0],b-c[1]];var p=this.getPosition();return[Math.max(p[0]-d[0]/2,0),Math.max(p[1]-d[1]/2,0),a,b]},_setupTitleBar:function(){if(this.options.title){var b=this;var c=jQuery("<div class='title-bar'></div>").html("<h2>"+this.options.title+"</h2>");if(this.options.closeable){c.append(jQuery("<a href='#' class='close'></a>").html(this.options.closeText))}if(this.options.draggable){c[0].onselectstart=function(){return false};c[0].unselectable='on';c[0].style.MozUserSelect='none';if(!Boxy.dragConfigured){jQuery(document).mousemove(Boxy._handleDrag);Boxy.dragConfigured=true}c.mousedown(function(a){b.toTop();Boxy.dragging=[b,a.pageX-b.boxy[0].offsetLeft,a.pageY-b.boxy[0].offsetTop];jQuery(this).addClass('dragging')}).mouseup(function(){jQuery(this).removeClass('dragging');Boxy.dragging=null;b._fire('afterDrop')})}this.getInner().prepend(c);this._setupDefaultBehaviours(c)}},_setupDefaultBehaviours:function(b){var c=this;if(this.options.clickToFront){b.click(function(){c.toTop()})}jQuery('.close',b).click(function(){c.hide();return false}).mousedown(function(a){a.stopPropagation()})},_fire:function(a){this.options[a].call(this)}};function WinBox(a,b,c){a=$.extend({title:b},a||{});var d=new Boxy("<div> "+c+" </div>",a);allDialogs.push(d);return false}
