/* RTI Home.js */

var rti;
if(!rti) rti = {};

window.addEvent('domready', function() {
	rti.homeWidgets = new RTIHomeButtons({
		el: $('subnav'),
		field: $('services_content'),
		loaderEl: $('loading')
	});
});

var RTIHomeButtons = new Class({
	initialize: function(options) {
		this.el = options.el;
		this.field = options.field;
		this.loadingDiv = options.loaderEl;
		this.progress = new Element('div').setProperty('id', 'progress');
		this.fade = new Fx.Style(this.field, 'opacity', {duration: 300});
		this.el.addEvent('click', function(evt) {
			(new Event(evt)).stop();
			this.ajax(evt);
		}.bindWithEvent(this));
	},
	ajax: function(evt) {
		
		this.progress.injectInside(this.loadingDiv);
		
		this.fade.chain(function() {
			var myAjax = new Ajax(
				'/home_info.php?p=' + evt.target.id, {
				method: 'get',
				update: this.field,
				onComplete: this.finish.bind(this)
			}).request();
		}.bind(this)).start(1,0);
		
	},
	finish: function() {
		this.fade.start(0,1);
		this.progress.remove();
	}
});