
if( window.MooTools ) {

var TestimonialPopup = {


	setContainer: function(el) {
		this.container = $(el);

		this.container.getElement('.titlebar a.close')
			.addEvent('click', function(e) {
				new Event(e).stop();
				this.blur();
				TestimonialPopup.close();
			});

		this.container.getElement('.view-another')
			.addEvent('click', function(e) {
				new Event(e).stop();
				this.blur();
				TestimonialPopup.update();
			});
	},


	show: function() {
		scrolls = window.getScroll();

		t = scrolls.y;

		// Park the Container off the page to get offset dimensions
		this.container.getParent().setStyles({'left':'-3000px'});
		this.container.getParent().setStyle('display','block');

		var h = this.container.getStyle('height').toInt();
		var wsize = window.getSize();
		wh = wsize.y;

		_h = (wh-h)/2;
		t += _h;

		this.container.getParent().setStyles({'top':t+'px','left':'0px'});

	},

	close: function() {
		this.container.getParent().setStyle('display','none');
	},

	update: function() {

		sidebar_target = $('sidebar_testimonial').getElement('p .comment');
		popup_target = this.container.getElement('p .comment');

		new Request({
			'url':'/applications/TestimonialsRotator/api/random-review.php',
			'method':'get',
			'noCache':true,
			'onSuccess':function(txt) {
				sidebar_target.set('html',txt);
				popup_target.set('html',txt);
			}
		}).send();

	}

};

window.addEvent( 'domready', function() {

	TestimonialPopup.setContainer('testimonial_popup');
	

	hdl_readmore = $("sidebar_testimonial").getElement('a.readmore');
	hdl_readmore.addEvent('click', function(e) {
				new Event(e).stop();
				this.blur();
				TestimonialPopup.show();				
    });

	
});

} /* END Mootools Accessible Check Wrapper */