var HomePage = function() {
	var activeElement = null;
	var init = false;
	
	function registerAnnouncements() {		
		// start all hidden
		$$('#announcements li').each(function(li) { 
			li.hide(); 
			li.setStyle({ marginBottom: "0px" });
		});				
		$$("#announcements ul")[0].setStyle({ height: "1em" });
		$$("#announcements .announcements_label")[0].setStyle({ 
			borderRight: "solid 1px #777", paddingRight: "7px", marginRight: "7px"
		});		
						
		if ($$("#announcements li").length > 0) {
			showNextAnnouncement();		
		}
	};
	
	function announcementAppearFinished() {		 
		activeElement.fade({ 
			delay: 5.0,
			afterFinish: showNextAnnouncement
		});						
	};
	
	function showNextAnnouncement() {		
		if (activeElement != null) {
			activeElement = activeElement.next();											
		}		
		
		if (activeElement === null) {			
			activeElement = $$('#announcements li')[0];			
		}								
				
		activeElement.appear({ 
			afterFinish: announcementAppearFinished
		});
	};
			
	return {
		init: function() {
			if (!init) {
				init = true;
				registerAnnouncements();
			}
		}
	};
}();

document.observe("dom:loaded", function() {	
	HomePage.init();
});