RTW = window.RTW || {};

RTW.EMERGENCY = {
	
	init: function(data) {
		this.retrieveInformation(data);
	},

	retrieveInformation: function(data) {
		var aggregatedContent = { title: "", active: false, content: "" };
		var self = this;
		$.each(data.feed.entry, function(i,content) {
			var tagName = content.title['$t'];
			var tagContent = content.content['$t'].replace(/^(.*): /,'');
			if(tagName.toLowerCase() == 'short title') {
				aggregatedContent.title = tagContent;
			} else if(tagName.toLowerCase() == 'active') {
				aggregatedContent.active = (tagContent.toLowerCase() == 'y') ? true : false;
			} else {
				aggregatedContent.content += "<"+tagName+">"+tagContent+"</"+tagName+">";
			}
		});
		self.setupMessages(aggregatedContent);
	},

	setupMessages: function(googleContent) {
		if(googleContent.active) {
			$('#sidebar-right .boxWhiteWide:first').after('<div class="boxWhiteWide" rel="prettyPhoto" href="#emergencyMsg"> \
				<div class="boxOuterWhite"> \
					<div class="boxInnerWhite"> \
							<h2><span class="rightColumnBoxHeading">Travel Alert</span></h2> \
							<div class="rightColumnBox travelAlert"></div> \
							<div class="rightColumnBoxText redArrow">'+googleContent.title+'</a></div> \
					</div> \
				</div> \
			</div> \
			<div id="emergencyMsg" class="hide">'+googleContent.content+'</div>');
			$('.travelAlert').parents('.boxWhiteWide').prettyPhoto({
				show_title: true,
				social_tools: '<br/>',
				modal: true,
				default_width: 600
			});
		}
	}

};
