


/*REPRESENTATIVES_PT*/



/* * *
	REPRESENTANTIVES
* * */
var representatives = new Object();
Object.extend(representatives, {	
	/* GET */
	get: function(url, state){
		this.wait(true);
		new Ajax.Request( 
			url, {
				method: 'get',
				onComplete: this.getReturn.bind(this),
				onFailure: this.onFailure.bind(this)
			}
		);
	},
	getReturn: function(ret){
		$('representatives_ajax').innerHTML = email.decode(ret.responseText);
		this.addBox(false);
		this.wait(false);
	},
	
	/* ADD BOX */
	addBox: function(){
		$A($('representatives_ajax').getElementsByTagName('a')).each(function(element){
			Event.observe(element, 'click', function(event){
				box.activate(event);
				var rep = Event.element(event).parentNode;
				$('lightbox_id').value = document.getElementsByClassName('id', rep)[0].innerHTML;
			}.bindAsEventListener(box), false);
		});
	},


	/* WAIT */
	wait: function(status){
		if(status){
			Element.hide('representatives_ajax');
			Element.show('representatives_loading');
		}else{
			Element.hide('representatives_loading');
			Element.show('representatives_ajax');
		}
	},
	
	/* ON FAILURE */
	onFailure: function(transport){
		alert('Problemas com a aplicação.\n\nFalha na requisiçao AJAX.\n\nOcorrência: '+transport.status);
	}
});


/*-----------------------------------------------------------------------------------------------*/

ContentLoaded(window, function(){
	$('representatives_ajax').innerHTML = email.decode($('representatives_ajax').innerHTML);
	representatives.addBox();
});