(function($){

	$(document).ready(function(){
//		$(document.body).append('<div id="BMmessages" class="top-right"></div>');
		$(document.body).append('<div id="BMloading" style="display:none"></div><div id="BMmessages" class="top-left"></div>');
	
		if ( $.BMMessagesAlert ) { bmAlert($.BMMessagesAlert, 'info', true); }
		if ( $.BMMessagesError ) { bmAlert($.BMMessagesError, 'error', true); }
		
	//	$("#BMloading") .ajaxStart(function(){ ajaxStart(); }) .ajaxComplete(function(){ ajaxEnd(); });
	});
	
	$.jGrowlTheme = '';

})(jQuery);


function bmAlert( message, type, sticky ) {
	if ( type == 'error' )  {
		var image = 'icon_warning.gif';
		var color = '#dbc4b0';
	}
	else {
		var image = 'icon_info.gif';
		var color = 'white';
	}

	text = '<table style="border-spacing:6px;" cellspacing="6"><tr><td style="vertical-align:top;"><img src="/misc/images/'+image+'" width="24"></td> <td style="vertical-align:top;color:'+color+'">'+message+'</td></tr></table>'
	$('#BMmessages').jGrowl(text, {
		sticky: sticky,
		glue: 'before',
		theme:  $.jGrowlTheme,
		speed: 600,
		positon: 'bottom-left',
		easing: 'easeInOutExpo',
		animateOpen: { 
			height: "show",
			width: "show"
		},
		animateClose: { 
			height: "hide",
			width: "show"
		}
	});
}

function ajaxStart() {
	$.blockUI({ message: '<img src="/misc/images/loadingAnimation.gif">',
		css: {
			top:  ($(window).height() - 13) /2 + 'px', 
            left: ($(window).width() - 209) /2 + 'px', 
			width: '209px',
			height: '13px',
			border: 'none',
			background: 'none'
		}
	});
}

function ajaxEnd() { $.unblockUI(); }
