$(document).ready(function () {
	if ($('.alert.alertMsgErro').length > 0 || 
			$('.alert.alertMsgSucesso').length > 0 ||
			$('.alert.alertMsgAlert').length > 0 ||
			$('.alert.alertMsgConfirm').length > 0) {
		
		// adicionar botão fechar
		$('.alert.alertMsgErro div.contenedor > div, .alert.alertMsgSucesso div.contenedor > div, .alert.alertMsgAlert div.contenedor > div').
			append('<a href="#" class="btFechar">fechar</a>');
		
		// adicionar acão aos botões fechar e não (ambos com as mesmas ações)
		$('.alert div.contenedor > div .btFechar, .alert div.contenedor > div .btNao').click(function() {
			$(this).parents('.alert').fadeOut(function() {
				$(this).remove();
				if ($('.alert').length == 0) {
					$("#BoxOverlay").slideUp(function() {
						$('#BoxOverlay').remove();
					});
				}
			});
			return false;
		});

		if ($("#BoxOverlay").length == 0) {
			$('body').append('<div id="BoxOverlay"></div>');
			$('#BoxOverlay').css( {
				position : 'absolute',
				top : 0,
				left : 0,
				opacity : '0.7',
				backgroundColor : '#0C4DA2',
				'z-index' : 90,
				height : $(document).height(),
				width : $(document).width(),
				display : 'none'
			});
		}
		$("#BoxOverlay").slideDown(function() {
			$('.alert').each(function() {
				$(this).css({
					'top' : ($(document).scrollTop() + 
								(($(window).height() - $(this).outerHeight()) / 2)) + 'px'
				}).fadeIn();
			});
		});
	}
});
