/**
 * Function: getLoboAlertsFeed()
 *         requires a modified version of zRSSFeed jQuery plugin
 *         I would have turned this into a plug-in also, but I didn't
 *         want to deal with scoping issues when calling itself recursively
 *         using the setTimeout() function.
 *
 * Author: Scott Horlbeck of HSC Web Team
 * 
 * Arguments:
 *
 *    useTestFeed bool
 *       This is pretty obvious.
 *
 *    refreshInterval int
 *       Number of milliseconds before the function calls itself again.
 *       60000 (60 seconds) should be good.
 *    
 *    contentFromLastUpdate string html
 *       This is not required for the first time you call the function.
 *       The function calls itself recursively, comparing the content
 *       on each call to determine if anything has changed.
 *
 * Version: 0.1
 * 
 **/
var getLoboAlertsFeed = function(useTestFeed, refreshInterval, contentFromLastUpdate) {
	if ( $('#loboalerts').length == 0 )
		$('<div id="loboalerts" class="hidden"></div>').appendTo('#dept_header');
	$('#loboalerts').rssfeed('',{
		header : false,
		limit : 3,
		showerror : true,
		titletag : 'span',
		snippet : false,
		customAPI : "http://hsc.unm.edu/_includes/loboalerts/loboalerts.cfm",
		useTestFeed : useTestFeed,
		getTodaysEntriesOnly : true,
		callback : function() {

			if (undefined === contentFromLastUpdate)
				contentFromLastUpdate = '';
			var newestData = $('#loboalerts').html().toString().replace(/[ \t\r\n]/g,'');
			var lastData   = contentFromLastUpdate.toString().replace(/[ \t\r\n]/g,'');

			if ( newestData != lastData && $(newestData).text().length > 0) {
				$('html,body').animate({scrollTop: 0}, {
					duration:500,
					complete: function() {
						if ( !$('#loboalerts').is(':visible') && $('li','#loboalerts').length > 0 ) {
							$('#loboalerts').slideDown('fast');
						} else if ( $('#loboalerts').is(':visible') && $('li','#loboalerts').length == 0 ) {
							$('#loboalerts').slideUp('fast');
						}
					}
				});
			}
			var t = setTimeout('getLoboAlertsFeed('+useTestFeed+','+refreshInterval+','+$('#loboalerts').html()+')', refreshInterval);
		}
	});
};

