/* flatAlert v2.2 */
flatAlert = new Class({
	opcoes: {
		duracaoPadrao:500,
		pathImagens:'http://sislojafacil.com/arquivos/www.sislojafacil.com/js/flatAlert_v2/',
		prefixoImagens:'btn_fechar_'
	},
	initialize:function(mensagem) {
		if (!$chk($('flatAlert_fundao'))) {
			fundao = new Element('div', {
				'id':'flatAlert_fundao',
				'styles': {
					'position':'absolute',
					'left':'0px',
					'top':'0px',
					'width':'100%',
					'height':$$('body')[0].getSize().size.y + 'px',
					'background-color':'#333333',
					'opacity':'0',
					'x-index':'17'
				},
				'events': {
					'click':function() {
						this.fechar();
					}.bind(this)
				}
			}).injectInside($$('body')[0]);
			caixa = new Element('div', {
				'id':'flatAlert_caixa',
				'styles': {
					'position':'fixed',
					'border':'2px solid #333333',
					'background-color':'#ffffff',
					'padding':'8px',
					'opacity':'0',
					'z-index':'18'
				}
			}).injectAfter('flatAlert_fundao');
			texto = new Element('span', {
				'id':'flatAlert_texto',
				'styles': {
					'font-size':'14px'
				}
			}).setHTML(mensagem).injectInside('flatAlert_caixa');
			$('flatAlert_caixa').setStyles({
				'left':'50%',
				'top':'50%',
				'margin-left':'-' + ($('flatAlert_caixa').getSize().size.x / 2).toInt() + 'px',
				'margin-top':'-' + ($('flatAlert_caixa').getSize().size.y / 2).toInt() + 'px',
				'width':texto.getSize().size.x + 'px',
				'height':texto.getSize().size.y + 'px'
			});
			new Fx.Style('flatAlert_fundao', 'opacity', {
				duration:this.opcoes.duracaoPadrao
			}).start(0.85);
			new Fx.Style('flatAlert_caixa', 'opacity', {
				duration:this.opcoes.duracaoPadrao
			}).start(1);
			document.getElements('input').each(function(obj) {
				obj.addEvent('keydown', function(event) {
					if (event.keyCode == '27' && $chk($('flatAlert_fundao'))) {
						this.fechar();
					}
				}.bind(this));
			}.bind(this));
			timerFechar = setTimeout(function() {
				this.fechar();
			}.bind(this), 15000);
			defPath = this.opcoes.pathImagens + (this.opcoes.pathImagens.substr((this.opcoes.pathImagens.length - 1), 1) != '/' ? '/' : '') + this.opcoes.prefixoImagens;
			btnFechar_0 = new Image();
			btnFechar_0.src = defPath + '0.gif';
			btnFechar_1 = new Image();
			btnFechar_1.src = defPath + '1.gif';
			btnFechar = new Element('img', {
				'id':'flatAlert_btnFechar',
				'src':btnFechar_1.src,
				'title':'Fechar',
				'styles': {
					'position':'fixed',
					'opacity':'0'
				},
				'events': {
					'mouseenter':function() {
						this.setProperty('src', btnFechar_0.src);
					},
					'mouseleave':function() {
						this.setProperty('src', btnFechar_1.src);
					},
					'click':function() {
						this.fechar();
					}.bind(this)
				}
			}).injectInside($('flatAlert_caixa'));
			cx = $('flatAlert_caixa');
			setTimeout(function() {
				if ($chk($('flatAlert_btnFechar'))) {
					$('flatAlert_btnFechar').setStyles({
						'left':((cx.getSize().size.x + cx.getPosition().x) - ($('flatAlert_btnFechar').getSize().size.x / 2).toInt()) + 'px',
						'top':(cx.getPosition().y) + 'px',
						'margin-left':'-2px',
						'margin-top':'-5px',
						'opacity':'1'
					});
				}
			}, 1000);
		}
	},
	fechar:function() {
		if ($chk($('flatAlert_fundao'))) {
			clearInterval(timerFechar);
			new Fx.Style('flatAlert_fundao', 'opacity', {
				duration:this.opcoes.duracaoPadrao
			}).start(0);
			new Fx.Style('flatAlert_caixa', 'opacity', {
				duration:this.opcoes.duracaoPadrao
			}).start(0);
			this.removerElementos();
		}
	},
	removerElementos:function() {
		setTimeout(function() {
			['flatAlert_fundao', 'flatAlert_caixa', 'flatAlert_texto', 'flatAlert_btnFechar_'].each(function(el) {
				if ($chk($(el))) {
					$(el).remove();
				}
			});
		}, this.opcoes.duracaoPadrao);
	}
});