/* faq.js */

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


window.addEvent('domready', function() {
	rti.links = new AjaxLinks({
		el: $('links'),
		ajaxURL: 'index.html?p=2'
	});
});

var AjaxLinks = new Class({
	initialize: function(options) {
		this.el = options.el;
		this.ajaxURL = options.ajaxURL;
	
		this.el.addEvent('click', function(evt) {
			if(evt.target.className === 'infolink') {
			// Fixed from original script to allow links in output
				(new Event(evt)).stop();
				
				this.targetId = evt.target.getProperty('id').substring(5);
				
				var ajaxDiv = 'ajax-' + this.targetId;
				
				if($(ajaxDiv)) {
					$(ajaxDiv).dispose();
				} else {
					this.content = new Element('div', {
						'class':'ajax-loader-sm',
						'id': 'ajax-' + this.targetId
					}).inject(evt.target, 'after');
					this.ajax(evt);
				}
			}
		}.bindWithEvent(this));
		
		$$('.infolink').addEvent('mouseover', function() {
			this.effect = new Fx.Morph(this, {link: 'cancel', duration: 200, transition: Fx.Transitions.Quad.easeInOut});
			this.effect.start({
				'padding-left': ['0px', '10px']
			});
		})
		.addEvent('mouseout', function() {
			this.effect.start({
				'padding-left': ['0px']
			});
		});
	},
	ajax: function(evt) {

		this.link = evt.target;
		
		this.id =  this.link.id.substring(5);

		
		var myAjax = new Request({
			 url: this.ajaxURL + '&ajax=1&id=' + this.id,
			onSuccess: this.finish.bind(this)
		}).get();
		
		
	},
	finish: function(txt,xml) {
		//console.log(xml);
		
	var fade = new Fx.Tween(this.content);
	
	fade.set('opacity', 0);
		
		this.content.set({
			'styles': {
				'background-color':'#93bf28',
				'background-image': 'none',
				'border': '3px solid #ffe',
				'color': '#fff',
				'width': 'auto',
				'height':'auto',
				'padding': '8px',
				'margin-bottom': '12px'
			},
			'html': 'Answer: ' + txt
		});
	fade.start('opacity', 0,1);
	}
});