

var lists = {
							
	inicialize: function(options){
		
		
		this.options = Object.extend({
			resizeDuration: 400,
			resizeTransition: Fx.Transitions.sineInOut,
			initialWidth: 450,
			initialHeight: 450,
			container: document.body,
			descriptions: true,
			opacity: 0.7,
			url: ''
		}, options || {});

		
		$A($$('.spreadable')).each(function(el) {
			
			el.onclick = this.click.pass(el, this);
			
		}, this);

		
		$A($$('.li')).each(function(el) {
			//alert(el.innerHTML);
			this.element = el;
			el.onclick = this.click2.pass(el, this);
			/*el.addEvent('click', function(e){
				new Event(e).stop();
				
				this.click2(el);
			}.bind(this));*/
			
		}, this);
		
		$$('a.delete').each(function(el) {
			
			//	### Codi del lightbox
			el.onclick = this.startDeleting.pass(el, this);	
			
		}, this);

	},
	
	click: function (element) {	
		//alert(
		element.toggleClass('closed');
		
		$A($$('.' + element.id)).each(function(el) {
			
			el.toggleClass('hidden');
			
		}, this);
	},
	
	click2: function (element) {	
	
		//alert(element.innerHTML);
		
		element.toggleClass('current');
			
	},
	
	startDeleting: function (element) {
						
		this.params = element.getProperty('alt').split(" ");
		this.package = this.params[0];
		this.table = this.params[1];
		this.id = this.params[2];
		this.url = element.href;
		
		if ( confirm("¿Estás seguro que deseas eliminar el registro?") ) {
			return this.deleteRecord();
		}
		
		return false;
		
	},
	
	
	deleteRecord: function () {
		
		//this.url = '/equipo_singular/intranet/' + this.package.toLowerCase() + '/delete_process/' + this.id;

		var rowFadeout = this.rowFadeout.bind(this);
		var ajaxOptions = {
			url: this.url,
			method: 'post',
			onComplete: rowFadeout
		};
			
		this.ajaxRequest = new Request(ajaxOptions).send();
			
		return false;
	},
	
	rowFadeout: function() {
		row = this.table + '-' + this.id;
		var myFx = new Fx.Elements($(row), {
			onComplete: function(){
				this.toggleRows();
				$(row).dispose();
			}.bind(this)
		}).start({
			'0': {
				'opacity': [1,0]
			}
		});

	},
	
	toggleRows: function() {
		row_deleted = $( this.table + '-' + this.id);
		
		rows = $$('.ordinary_list tr').length;

		current_row = row_deleted;
		
		for (i=1;i<=rows;i++) {
			if ( current_row.getNext() != null ) {
				nextRow = current_row.getNext();
				if ( nextRow.hasClass('lighter') ) {
					nextRow.addClass('darker');
					nextRow.removeClass('lighter');
				}
				else if ( nextRow.hasClass('darker') ) {
					nextRow.addClass('lighter');
					nextRow.removeClass('darker');
				}
				current_row = current_row.getNext();
			}
		}
		
	}

}