if (!window.ehavior) window.ehavior = {};
if (!window.ehavior.ui) window.ehavior.ui = {};
ehavior.ui.alerts = {};

ehavior.ui.alerts.timer = null;

ehavior.ui.alerts.show = function(headline, message, callback)
{
	var that = this;
	var overlay = $('#fullPageOverlay');
	var infoBox = $('#alertBox');
	overlay.css('width', $(document).width()+'px');
	overlay.css('height', $(document).height()+'px');
	overlay.show();
	infoBox.find('h2').html(headline);
	infoBox.find('p').html(message);
	if (callback && Object.prototype.toString.call(callback) === "[object Function]") {
		infoBox.find('#alertConfirmButton').bind('click',
			function()
			{
				infoBox.hide();
				overlay.hide();
				callback.apply();
			}
		).show();
	} else {
		infoBox.find('#alertConfirmButton').hide();
		this.timer = setTimeout(function(){that.hide();}, 10000);
	}
	
	// Bind close action
	$('#alertBox span.close').add('#fullPageOverlay').bind('click', ehavior.ui.alerts.hide);
	
	infoBox.show();
};

ehavior.ui.alerts.hide = function()
{
	if (this.timer !== null) {
		// Stop the timer.
		clearTimeout(this.timer);
		this.timer = null;
	}
	$('#alertBox').add('#fullPageOverlay').hide();
	$('#alertBox span.close').add('#alertBox #alertConfirmButton').add('#fullPageOverlay').unbind();
};
