
LastReviewsClass = Class.extend( BaseApplicationModuleClass,
{
	container : null,
	isNextAvailable : null,
	isPreviousAvailable : null,
	
	initialize : function(obj)
	{
		that = this; //jq "this" hack
		this.container = obj;
		
		
		$('ul li', this.container).not(':first').hide();
		
		this.refreshNavigation();
		this.bindNavigation();
	},
	
	refreshNavigation : function ()
	{
		$('.next, .prev', this.container).removeClass('inactive');
		this.isPreviousAvailable = true;
		this.isNextAvailable = true;

		if($('li:visible', this.container).get(0) == $('li:first', this.container).get(0))
		{
			$('.prev', this.container).addClass('inactive');
			this.isPreviousAvailable = false;
		}
		
		if($('li:visible', this.container).get(0) == $('li:last', this.container).get(0))
		{
			$('.next', this.container).addClass('inactive');
			this.isNextAvailable = false;
		}
	},
	
	bindNavigation : function ()
	{
		//$('.next, .prev', this.container).select(function () { return false; });
		
		$('.prev', this.container).click(this.navigatePrevious);
		$('.next', this.container).click(this.navigateNext);
	},
	
	
	navigatePrevious : function ()
	{
		if(!that.isPreviousAvailable)
		{
			return;
		}
		
		hideThat = $('li:visible', that.container);
		hideThat.prev().show();
		hideThat.hide();
		
		that.refreshNavigation();
	},
	
	
	navigateNext : function ()
	{
		if(!that.isNextAvailable)
		{
			return;
		}
		
		hideThat = $('li:visible', that.container);
		hideThat.next().show();
		hideThat.hide();

		that.refreshNavigation();
	}

});

$(document).ready(function ()
{
	var lastReviews = new LastReviewsClass($('.opinions'));
});

