/**
 * @author Kristofer Forsell
 */
function Class(){
	this.me = "news";
	
}

Class.prototype = {
	
	// INIT
	init:function(){
		this.initialized = false;
		this.bindEvents();
	},
	
	loadNews: function(newsUrl){
		
		if(blom.news.initialized == false){
			
			// Show the loader
			$("#loader").fadeIn(100);
			
			$.ajax({
				type: "GET",
				url: newsUrl,
				success: function(data) {
					
					// Hide the loader
					$("#loader").fadeOut(100);
					// Clear the diary
					$("#content").append( $(data).find('#content').html() );
					blom.news.openView();
				}
			});
		
			blom.news.initialized = true;
		
		}else {
			blom.news.openView();
		}
		
	},
	loadMorePosts: function( url ){
	
			$.ajax({
				type: "GET",
				url: url,
				success: function(data) {
					
					// Hide the loader
					$("#loader").fadeOut(100);
					// Clear the diary
					var markup = $(data).find('.post-feed').html();
					$('#nav-below', '#news').remove();
				 	$(markup).css('display','none').appendTo('#news').fadeIn();
				}
			});

	},
	
	bindEvents: function(){
		
		$('#news').find('.nav-previous').live('click', function(){ 
			blom.news.loadMorePosts( $(this).find('a').attr('href') ); 
			return false;
		});
		
	},
	
	openView: function(){
		$("#news").fadeIn(400);
		$('#loader').fadeOut(100);
		blom.changeIndexTitle( 'Index' );
	},
	
	closeView: function(){
		$("#news").hide();
		
	},
	
	// GENERIC
	toString: function() {
  		return this.me;
	},
	
}

blom.news = new Class();

$(document).ready(function(){
	blom.initClass("news");
});
