var strAnnounce;
var oldStrAnnounce;
var announceTimeStamp;
var first = true;


function eh(msg, exception) {
	// try again in 60 seconds
	setTimeout("refreshAnnounce()", 60000);
}

function init() {
  //alert("Made it here!");
  DWREngine.setErrorHandler(eh);
  dwr.util.useLoadingMessage();
  //Tabs.init('tabList', 'tabContents');
}

function refreshAnnounce() {
	AlertNotification.getAlertBean( {
		callback:processNotification,
		errorHandler:eh } );

}

function processNotification( notify ) {
	if ( notify != null ) {
		strAnnounce = notify.alertMessage;
		oldStrAnnounce = notify.oldAlertMessage;
		announceTimeStamp = notify.lastModifiedDate;
		if( strAnnounce != null && ( ( strAnnounce != oldStrAnnounce ) || first ) ) {
			first = false;
			//alert( first );
			//alert( "new:'" + strAnnounce + "' old:'" + oldStrAnnounce +"'");
			if ( strAnnounce != oldStrAnnounce && strAnnounce == "" ) {
				//alert("Removing the show!");
				var highlightThis = $("announcementDiv");
				new Effect.Fade( highlightThis,{duration:2});
			} else if ( strAnnounce != "" ) {
				announcement( announceTimeStamp + "\n" + strAnnounce );
				var highlightThis = $("announcementDiv");
				if( highlightThis.style.display != ""){
					new Effect.Appear( highlightThis,{duration:2});
				}
			}
		}
		setTimeout("refreshAnnounce()", 60000);
	}
}

function announcement( alertMsg ){
	var stringObj = alertMsg.replace(/\\n/g,"\n");
	alert( stringObj );
}

