
/**
 * @author T Mower
 */

Event.observe(window, 'load', function() {
//Event.observe(document, "dom:loaded", function(){
	if ($('comments')) {
		var rating_a = new Comments({container: 'commentsList'});
	}
});

Comments = Class.create({
	
	mainContainer: null,

	initialize: function(opt){
		if (opt.container == null) throw ('Comments(): a comments container needs to be specified.');
		if (opt.container == null) console.log(opt.container);
		this.mainContainer = $(opt.container);
		// If the links don't exist, exit without doing anything
		if (!this.mainContainer.down('#showAllTop')) return;
		if (!this.mainContainer.down('#showLatestTop')) return;
		this.applyBehaviour();
	},
	
	applyBehaviour:function(){
		Event.observe(this.mainContainer.down('#showAllTop'), 'click', this.showAllComments);
		Event.observe(this.mainContainer.down('#showAllBottom'), 'click', this.showAllComments);
		Event.observe(this.mainContainer.down('#showLatestTop'), 'click', this.showLatestComments);
		Event.observe(this.mainContainer.down('#showLatestBottom'), 'click', this.showLatestComments);
	},

	showAllComments:function(event, item){
		Event.stop(event);
		$('otherComments').show();
		$('showLatestTop').show();
		$('showAllTop').hide();
		$('showLatestBottom').show();
		$('showAllBottom').hide(); 

	},

	showLatestComments:function(event, item){
		Event.stop(event);
		$('otherComments').hide();
		$('showLatestTop').hide();
		$('showAllTop').show();
		$('showLatestBottom').hide();
		$('showAllBottom').show();
		$('commentsList').scrollTo();

	}

});
