try{
	jQuery.jGrowl.defaults.position = 'top-left';
	jQuery.jGrowl.defaults.closerTemplate = '<div>[ close all alerts ]</div>';
}catch(e){}

var ignoreAlerts = [];

function removePopupAlert(alert_id)
{
	if(alert_id)
	{
		jQuery.getJSON('/includes/functions/specialalert.php?json=true&remove='+alert_id, function(data) {
			if(data.result){
				//console.log('deleted '+alert_id);
			}else{
				//console.log('problem with '+alert_id);
			}
		});
	}
}
function registerPopupAlert(alert_id, msg)
{
	if(!ignoreAlerts.in_array(alert_id))
	{
		jQuery.jGrowl("<p>"+msg+"</p>", {
			sticky: true,
			close: function(e,m,o) {
				removePopupAlert(alert_id);
			}
		});
		ignoreAlerts.push(alert_id);
	}
}
function getPopupAlerts()
{
	jQuery.getJSON('/includes/functions/specialalert.php?jsonalert=true', function(data) {
		if(data.hasAlerts)
		{
			for(var i = 0; i < data.alerts.length; i++)
			{
				registerPopupAlert(data.alerts[i][0], data.alerts[i][1]);
			}
		}
		setPopupAlertTimer();
	});
}

var popupAlertTimeout = null;
var popupAlertSeconds = 30;

function setPopupAlertTimer()
{
	popupAlertTimeout = window.setTimeout("getPopupAlerts()", popupAlertSeconds * 1000);
}

jQuery(document).ready(function(){
	setPopupAlertTimer();
});

