/*
example:
ShowBox({
    title: 'Заголовок',
    data: 'текст',
    buttons: [
        {caption: 'закрыть',
        action: 'close'},
        {caption: 'лол',
        action: function(){alert(1);}}
    ]
})
*/
var zBox, zArea, zArr;
$(function(){	$('body').prepend($('<div z="Box"/>'));

	zBox=$('div[z=Box]');
	if($.browser.msie)zBox.attr('style','top: expression(parseInt(document.body.scrollTop, 10)+200 + \'px\');');
	zBox.css({
			'position':($.browser.msie?'absolute':'fixed'),
			'width':'100%',
			'display':'none'
		});

	zBox.append('<center/>');
	zBox.find('center').append(
		$('<div/>')
	);

	$('body').prepend($('<div z="Area" id="backArea"/>'));
	zArea=$('div[z=Area]');
	if($.browser.msie)zArea.attr('style','top: expression(parseInt(document.body.scrollTop, 10) + \'px\');');
	zArea.css({
			'position':($.browser.msie?'absolute':'fixed'),
			'width':'100%',
			'height':'100%',
			'display':'none'
		}).click(HideBox);

});
function ShowBox(settings){	var config = {
		data  		: '',
	 	title   	: '',
		buttons		: undefined
   	};
	var configBtn = {
		caption  	: 'Close',
	 	action   	: 'close'
   	};
   	if (settings) $.extend(config, settings);

	zBox.find('div').html('');
	zBox.find('div').append($('.Tpls .msgTpl').clone());
	zBox.find('.msgLabel').append(config.data);
	zBox.find('.msgTitle').html(config.title);
	zBox.find('.msgX').click(function(){		HideBox();
		return false;
	});
	var button = zBox.find('.msgBtn').clone();
	zBox.find('.msgBtn').remove();
	if(config.buttons !== undefined){
		for (var key in config.buttons) {
		    var val = config.buttons[key];
		    var conf = configBtn;
		    if (val) $.extend(conf, val);

		    var btn = button.clone();
		    if(!$.isFunction(conf.action)){		    	if(conf.action=='close')conf.action = function(){HideBox();};		    }
//            btn.css('float','left');
		    btn.attr('value',val.caption).click(conf.action);

			zBox.find('.msgBtnList').append(btn);
		}
	}
//        zBox.find('.msgBtnList').append($('<div/>').css('clear','both'));	}

	zArr=$('ins, iframe, embed');
		zBox.css({
			'opacity':0,
			'display':'block'
		});
		if(!$.browser.msie){			zBox.css({
				'top':'-'+zBox.height()+'px'
			});		}

		zArea.css({
			'opacity':0,
			'display':'block'
		});


		zBox.animate({
			'opacity':1
		},'slow');
		if(!$.browser.msie){
			zBox.animate({
				'top':'200px'
			},'slow');
		}



		zArea.animate({'opacity':0.6});
	zArr.animate({'opacity':0},function(){		zArr.css({visibility:'hidden'});
	});}
function HideBox(data){
	zBox.fadeOut();
	zArea.fadeOut(function(){
			zArr.css({visibility:'visible'});
		zArr.animate({'opacity':1});
	});
}

