(function($){FadeBox=function(options){options=$.extend({},FadeBox.defaults,options);var $document=$(document);var buttonsCount=0;var boxContainer,boxBG,boxContainer,boxLayout,boxTitle,boxBody,boxControls,buttonYes,buttonNo;boxBG=$('<div id="fadeBoxBG" style="display:none"></div>').appendTo('body');boxContainer=$('<div id="fadeBoxContainer" style="display:none"></div>').insertAfter(boxBG);boxLayout=$('<div id="boxLayout"></div>').appendTo(boxContainer);boxTitle=$('<div id="boxTitle"></div>').appendTo(boxLayout).wrap('<div id="boxTitleWrap"></div>');boxBody=$('<div id="boxBody"></div>').appendTo(boxLayout);boxControls=$('<div id="boxControls"></div>').appendTo(boxLayout);boxBG.height($document.height());$(document).keydown(function(e){if(e.keyCode==27){hide()}});refreshCoords();refreshBox();function refreshCoords(){var height=($.browser.opera&&$.browser.version.indexOf('9.5')!=-1)?document.documentElement.clientHeight:$(window).height();boxContainer.css({top:$document.scrollTop()+20,left:'50%',marginLeft:'-500px'})}function addButton(options){buttonsCount++;if(typeof options!='object')options={};options=$.extend({label:'Button'+buttonsCount,style:'buttonYes'},options);var button=$('<div></div>').prependTo(boxControls).wrap('<div id="button'+buttonsCount+'" class="buttonWrap '+options.style+'"></div>');button.html(options.label);button.hover(function(){$(this).addClass('buttonHover')},function(){$(this).removeClass('buttonHover')});if(options.onClick){button.click(function(e){options.onClick(e)})}return button}function removeButtons(){buttonsCount=0;boxControls.empty()}function refreshBox(){boxTitle.html(options.title);boxContainer.width(options.width);boxContainer.height(options.height);boxContainer.removeClass();boxContainer.unbind('click');if(options.hideOnClick&&options.type=='POPUP'){boxContainer.click(function(){hide()})}switch(options.type){case'POPUP':boxContainer.addClass('popupBox');boxBG.click(function(){hide()});break;case'MESSAGE':boxContainer.addClass('messageBox');boxBG.unbind('click');break}}function show(){refreshCoords();boxBG.show();$('embed').add('object').css('visibility','hidden');boxContainer.fadeIn('fast',options.onShow)}function hide(){boxContainer.fadeOut('fast',function(){boxBG.hide();$('embed').add('object').css('visibility','visible');if(options.onHide)options.onHide()})}return{show:function(){show();return this},hide:function(){hide();return this},content:function(html){boxBody.html(html);return this},loadContent:function(url,params){$.ajaxSetup({error:function(data){boxBody.html('Request error occured.');if(options.onLoadError)options.onLoadError(data.responseText)}});boxBody.html('<div id="boxLoader"></div>');if(typeof params!='object')params={};$.get(url,params,function(data,textStatus){boxBody.html(data);refreshCoords();if(options.onLoad)options.onLoad(data,textStatus)});return this},addButton:function(options){addButton(options);return this},removeButtons:function(options){removeButtons();return this},setOptions:function(newOptions){options=$.extend({},options,newOptions);refreshBox();return this}}};FadeBox.defaults={type:"MESSAGE",hideOnClick:true,title:"Alert",width:"410px",height:"auto"}})(jQuery);