var _msgbox=function(opt){
	var _o=this;
	$.each(opt,function(i,n){_o[i]=n;});
};
_msgbox.prototype={
	title:'wwwhl.ru',
	autohide:0,
	width:400,
	icon:'',
	msg:'',
	buttons:[{title:'OK'}],
	center:function(e){
		var el=e.data.el;
		if(typeof el!='undefined')el.stop().animate({left:($(window).width()-el.width())/2-20,top:($(window).height()-el.height())/2-10},'fast');
	},
	show:function(){
		var _o=this;
		this.el=$('<div class="msgbox" style="width:'+this.width+'px"></div>').appendTo('body');
		this.shadow=$('<div class="shadow"></div>').click(function(){_o.hide();}).width($(window).width()).height($(window).height()).appendTo('body');
		if(this.title!='')this.el.append('<h1>'+this.title+'</h1>');
		if(this.icon!='')this.el.append('<div class="icon '+this.icon+'"></div>');
		if(this.msg!='')this.el.append('<div class="content">'+this.msg+'</div>');
		if(this.buttons.length>0){
			var btn_container=$('<div class="buttons"></div>').appendTo(this.el);
			$.each(this.buttons,function(i,b){
				if(typeof b.category=='undefined')b.category='button';
				var btn=$('<button type="'+b.category+'">'+b.title+'</button>').appendTo(btn_container);
				if(typeof b.call!='undefined')btn.click(function(){
					var close=true;
					if(typeof b.call=='function')close=(b.call()!=-1);
					else eval(b.call);
					if(close)_o.hide();
				});
				else btn.click(function(){_o.hide();});
			});
		}
		this.el.css({left:($(window).width()-this.el.width())/2-20,top:-this.el.height()-10}).animate({top:($(window).height()-this.el.height())/2-10},'slow').find(':input:visible:first').focus();
		$(window).bind('resize',{el:this.el},this.center);
		if(this.autohide>0)window.setTimeout(function(){_o.hide();},this.autohide);
		return this;
	},
	hide:function(){
		var _o=this;
		if(typeof this.el!='undefined')this.el.fadeOut('slow',function(){
			_o.el.remove();
			_o=null;
		});
		if(typeof this.shadow!='undefined')this.shadow.remove();
		$(window).unbind('resize',this.center);
		return this;
	}
};
window.notice=function(message,params){
	if(!params)params={};
	params['msg']=message;
	if(window._msg)window._msg.hide();
	window._msg=new window._msgbox(params).show();
};
