var reviews = {
	all_reviews: null,
	review_options: null,
	init: function() {
		// Set up attributes
		this.all_reviews = $$('#review_display .review_box');
		this.review_options = $$('#review_options li');
		// Housekeeping : clean up after CSS default (no script) view
		$$('#review_display .review_box.hide').invoke('removeClassName','hide').invoke('hide');
		// Setup event handlers
		this.review_options.invoke('observe','mouseover',this.mouse_over.bindAsEventListener(this));
		this.review_options.invoke('observe','mouseout',this.mouse_out.bindAsEventListener(this));
		this.review_options.invoke('observe','click',this.clicky.bindAsEventListener(this));
	},
	// the event handler methods
	clicky: function(e) {
		var el = e.element(); // the clicked element
		this.deselect_all();
		this.hide_all_reviews();
		this.select_new_review(el);
		Event.stop(e);
	},
	mouse_over: function(e) {
		var el = e.element(); // the mouseover element
		//this.hide_all_reviews();
		//this.show_hovered_review(el);
		window.clearInterval(this.timer);
		Event.stop(e);
	},
	mouse_out: function(e) {
		this.show_only_selected_review();
		this.timer = window.setInterval('reviews.show_only_selected_review()', 10);
		Event.stop(e);
	},
	
	// utility methods
	show_only_selected_review: function() {
		this.hide_all_reviews();
		this.selected_review().show();		
		window.clearInterval(this.timer);
	},
	hide_all_reviews: function() {
		this.all_reviews.invoke('hide');
	},
	selected_review: function() {
		return $$('#review_display .selected').first();
	},
	show_hovered_review: function(el) {
		var hover_review_id = el.up('li').id;
		var hover_review = $('display_' + hover_review_id);
		new Effect.SlideDown(hover_review,{
			duration: .25
		});
	},
	deselect_all: function() {
		this.review_options.invoke('removeClassName','selected');
		this.all_reviews.invoke('removeClassName','selected');
	},
	select_new_review: function(el) {
		var selected_review_id = el.up('li').addClassName('selected').id;
		var new_review = $('display_' + selected_review_id);
		new_review.addClassName('selected');
		new Effect.SlideDown(new_review,{
			duration: .5
		});
		new Effect.Highlight(new_review.up(index=1),{
			duration: .7,
			startcolor: '#C8CA80',
			endcolor: '#E8EB95'
		});
	}
};
document.observe('dom:loaded', function() {
	reviews.init();
});


