(function($){

	$.livefeed = {
		
		options: {
			slideSpeed: 150,
			rotationSpeed: 10000,
		},
		
		data: {},
		
		init: function() {
			if ( $("#ahLiveFeed").length == 0 ) return false;
			$("#ahLiveFeed").html( '<div class="msg-wrapper"><p class="loading">Loading</p></div>' );
			$.ajax({
				url: 'http://www.askhugo.com.au/js/livefeed.js',
				type: 'get',
				dataType: 'json',
				success: function( data, textStatus ) {
					$.livefeed.data = data.livefeed;
					$("#ahLiveFeed").bind( 'showMsg', function() {
						$.livefeed.textMsg = $.livefeed.data[Math.round((Math.random()/1)*($.livefeed.data.length-1))];
						if ( !$.livefeed.textMsg ) {
							$("#ahLiveFeed").html( '<div class="msg-wrapper"><p class="error type2">Could not initialise the live feed!</p></div>' );
							clearInterval( $.livefeed.timer );
							return false;
						}
						$("#ahLiveFeed").append( '<div class="msg-wrapper" style="display: none"><p>'+$.livefeed.textMsg+'</p></div>' );
						$("#ahLiveFeed .msg-wrapper:visible").slideUp( $.livefeed.options.slideSpeed, function() { $(this).remove() } );
						$("#ahLiveFeed .msg-wrapper:hidden").slideDown( $.livefeed.options.slideSpeed );
					});
					$("#ahLiveFeed").html('').trigger('showMsg');
					$.livefeed.timer = setInterval( '$("#ahLiveFeed").trigger(\'showMsg\')', $.livefeed.options.rotationSpeed );
				},
				error: function( xml, textStatus, err ) {
					$("#ahLiveFeed").html( '<div class="msg-wrapper"><p class="error type1">Could not initialise the live feed!</p></div>' );
				},
			});
		},
		
	}
	
	$.livefeed.init();

})(jQuery);
