var provinceRotation;

function showAlerts() {
	$.getJSON("static/alerts/getalerts.php", {lang: lang}, function(data) {
		var c = 0;
		if (data !== null) {
			$("#provinces").empty();
			$.each(data, function(i, product) {
				c++;
				var provincedata = product.split(":");
				$("#provinces").append("<div class=\"province\"><a onclick=\"trackCustomLink('Alerts in effect')\" href=\"index.php?product=alerts&pagecontent=prov&provcode=" + provincedata[1] + "\">" + provincedata[0] + "</a></div>");
			});
		}

		if (c > 0) {
			var n = $(".province").length;
			if (n > 0) {
				$("#warning_list").fadeIn();
				setupRotator();
			} else {
				$("#warning_list").html("");
			}
		} else {
			$("#warning_list").fadeOut();
		}
	});
}

function setupRotator() {
	if ($('.province').length >= 1) {
		clearTimeout(provinceRotation);
		$('.province:first').addClass('current').fadeIn(1000);
		provinceRotation = setInterval('textRotate()', 3000);
	}
}

function textRotate() {
	var current = $('#provinces > .current');
	if (current.next().length == 0) {
		current.removeClass('current').fadeOut(1000);
		$('.province:first').addClass('current').fadeIn(1000);
	} else {
		current.removeClass('current').fadeOut(1000);
		current.next().addClass('current').fadeIn(1000);
	}
}

