function Messi(n,t){var i=this,r,u;if(i.options=jQuery.extend({},Messi.prototype.options,t||{}),i.messi=jQuery(i.template),i.setContent(n),i.options.title==null?jQuery(".messi-titlebox",i.messi).remove():(jQuery(".messi-title",i.messi).append(i.options.title),i.options.buttons.length!==0||i.options.autoclose||i.options.closeButton&&(u=jQuery('<span class="messi-closebtn"><\/span>'),u.bind("click",function(){i.hide()}),jQuery(".messi-titlebox",this.messi).prepend(u)),i.options.titleClass!=null&&jQuery(".messi-titlebox",this.messi).addClass(i.options.titleClass)),i.options.width!=null&&jQuery(".messi-box",i.messi).css("width",i.options.width),i.options.buttons.length>0)for(r=0;r<i.options.buttons.length;r++){var e=i.options.buttons[r].btnClass?i.options.buttons[r].btnClass:"",o=i.options.buttons[r].val?i.options.buttons[r].val:"",f=jQuery('<div class="btnbox"><button class="btn '+e+'" href="#">'+i.options.buttons[r].label+"<\/button><\/div>").data("value",o);f.bind("click",function(){var n=jQuery.data(this,"value"),t=i.options.callback!=null?function(){i.options.callback(n)}:null;i.hide(t)});jQuery(".messi-actions",this.messi).append(f)}else jQuery(".messi-footbox",this.messi).remove();return i.options.buttons.length!==0||i.options.title!=null||i.options.autoclose||i.options.closeButton&&(u=jQuery('<span class="messi-closebtn"><\/span>'),u.bind("click",function(){i.hide()}),jQuery(".messi-content",this.messi).prepend(u)),i.modal=i.options.modal?jQuery('<div class="messi-modal"><\/div>').css({opacity:i.options.modalOpacity,width:jQuery(document).width(),height:jQuery(document).height(),"z-index":i.options.zIndex+jQuery(".messi").length}).appendTo(document.body):null,i.options.show&&i.show(),jQuery(window).bind("resize",function(){i.resize()}),i.options.autoclose!=null&&setTimeout(function(n){n.hide()},i.options.autoclose,this),i}Messi.prototype={options:{autoclose:null,buttons:[],callback:null,center:!0,closeButton:!0,height:"auto",title:null,titleClass:null,modal:!1,modalOpacity:.2,padding:"10px",show:!0,unload:!0,viewport:{top:"0px",left:"0px"},width:"500px",zIndex:99999},template:'<div class="messi"><div class="messi-box"><div class="messi-wrapper"><div class="messi-titlebox"><span class="messi-title"><\/span><\/div><div class="messi-content"><\/div><div class="messi-footbox"><div class="messi-actions"><\/div><\/div><\/div><\/div><\/div>',content:"<div><\/div>",visible:!1,setContent:function(n){jQuery(".messi-content",this.messi).css({padding:this.options.padding,height:this.options.height}).empty().append(n)},viewport:function(){return{top:(jQuery(window).height()-this.messi.height())/2+jQuery(window).scrollTop()+"px",left:(jQuery(window).width()-this.messi.width())/2+jQuery(window).scrollLeft()+"px"}},show:function(){this.visible||(this.options.modal&&this.modal!=null&&this.modal.show(),this.messi.appendTo(document.body),this.options.center&&(this.options.viewport=this.viewport(jQuery(".messi-box",this.messi))),this.messi.css({top:this.options.viewport.top,left:this.options.viewport.left,"z-index":this.options.zIndex+jQuery(".messi").length}).show().animate({opacity:1},300),this.visible=!0)},hide:function(n){if(this.visible){var t=this;return this.messi.animate({opacity:0},300,function(){t.options.modal&&t.modal!=null&&t.modal.remove();t.messi.css({display:"none"}).remove();t.visible=!1;n&&n.call();t.options.unload&&t.unload()}),this}},resize:function(){this.options.modal&&jQuery(".messi-modal").css({width:jQuery(document).width(),height:jQuery(document).height()});this.options.center&&(this.options.viewport=this.viewport(jQuery(".messi-box",this.messi)),this.messi.css({top:this.options.viewport.top,left:this.options.viewport.left}))},toggle:function(){return this[this.visible?"hide":"show"](),this},unload:function(){this.visible&&this.hide();jQuery(window).unbind("resize",this.resize());this.messi.remove()}};jQuery.extend(Messi,{alert:function(n,t,i){var r=i.btnText?i.btnText:"OK",u=[{id:"ok",label:r}];return i=jQuery.extend({closeButton:!1,modal:!0,buttons:u,callback:function(){}},i||{},{show:!0,unload:!0,callback:t}),new Messi(n,i)},ask:function(n,t,i){var r=i.btnYesText?i.btnYesText:"Yes",u=i.btnNoText?i.btnNoText:"No",f=[{id:"yes",label:r,val:"Y",btnClass:"btn-success"},{id:"no",label:u,val:"N",btnClass:"btn-danger"}];return i=jQuery.extend({closeButton:!1,modal:!0,buttons:f,callback:function(){}},i||{},{show:!0,unload:!0,callback:t}),new Messi(n,i)},img:function(n,t){var i=new Image;jQuery(i).load(function(){var n={width:jQuery(window).width()-50,height:jQuery(window).height()-50},r=this.width>n.width||this.height>n.height?Math.min(n.width/this.width,n.height/this.height):1;jQuery(i).css({width:this.width*r,height:this.height*r});t=jQuery.extend(t||{},{show:!0,unload:!0,closeButton:!0,width:this.width*r,height:this.height*r,padding:0});new Messi(i,t)}).error(function(){console.log("Error loading "+n)}).attr("src",n)},load:function(n,t){t=jQuery.extend(t||{},{show:!0,unload:!0});var i={url:n,dataType:"html",cache:!1,error:function(n){console.log(n.responseText)},success:function(n){new Messi(n,t)}};jQuery.ajax(i)}})