$(document).ready(function() {
function addAnnouncements () {
	var data = "";
	var alertType = 0;
	
		//uses jquery url parser plugin
		//to account for whether script is fired from www or not
		//http://projects.allmarkedup.com/jquery_url_parser/
		
	$.post("http://"+ jQuery.url.attr("host") +"/include/php/get-announcements.php", function(theXML){		
			
			$("announcement",theXML).each(function(i){
			
				//var announcement = $(this).find("firstname").attr("title");
				var announcement = $(this).find("description").text();
				var title = $(this).find("title").text();
				var id = $(this).find("id").text();
				var order = $(this).find("order").text();
				var type = $(this).find("type").text();

				data = data + "<h3>" + title + "</h3> <p>" + announcement + "</p>";
				
				if (type == 1) {//Security) 
					alertType = 1;
				}
				if (id > 1) {
				$("#announcement-alert").css("display","block");	
				}
			});
				

			if (alertType == 1) {//Security) 
				$("#announcement-alert").html("<h2>Campus Alert</h2>");
				data = data + "<p id=\"announcement-tag\">Please stay informed of the situation by checking any of the Gardner-Webb Alert systems</p>";
				$("#announcement-block").css({"background" : "url(http://www.gardner-webb.edu/include/images/announcements/emergency.jpg)"});
			}
			else {   //Weather
				$("#announcement-alert").html("<h2>Weather Announcement</h2>");
				data = data + "<div id=\"announcement-tag\"><p>Please, continue monitoring this site for changes or call the Gardner-Webb Snow Line 877-498-7669 (877-GWU-SNOW). <br><br>Always remember to check road conditions before traveling.</p></div>";
				$("#announcement-block").css({"background" : "url(http://www.gardner-webb.edu/include/images/announcements/weather-snow.jpg)"});
			}

			$("#announcement-block-copy").html(data);
			

			$(this).delay(60000,function(){
				addAnnouncements();
			});
	});
}

	
	$("#announcement-alert").mouseup(function(){
		$("#announcement-block").fadeIn();
		//$("#content").fadeTo("slow", 0.33);
	});
	
	
	$("#announcement-block-xclose").mouseup(function(){
		$("#announcement-block").hide();
		$("#content").fadeTo("fast", 1);	
	});


	addAnnouncements();   
	
});