var IMAGES_BASE_URL = '';
var desired_id = 0;
var new_index  = 0;

$(document).ready(function() {
	IMAGES_BASE_URL = $('div.generic-list-display .thumb').attr('src');
	
	changeListItemDisplay();  //para setear un primer elemento (new_index = 0)
	
	$('ul.generic-list li a').click(function() {
		var id_attr = $(this).attr('id');
		desired_id = id_attr.substr(id_attr.indexOf('-')+1);
		
		//los indices del array no reflejan el id del objeto, entonces hay que buscar dentro de cada uno :S
		jQuery.each(aData, function (i, obj) {
			if (obj.id == desired_id) {
				new_index = i;
			}
		});
		
		$('div.spacer').show();
		$('div.generic-list-display').fadeOut('def', changeListItemDisplay);
	});
});

function changeListItemDisplay () {
	$('div.generic-list-display .title').text(aData[new_index].titulo);
	$('div.generic-list-display .description').html(aData[new_index].descripcion);
	$('div.generic-list-display .embedded_content').html(aData[new_index].contenido_incrustado);
	if (aData[new_index].thumbnail != '') {
		$('div.generic-list-display .thumb').attr('src', IMAGES_BASE_URL + aData[new_index].thumbnail);
		$('div.generic-list-display .thumb').show();
	}
	else {
		$('div.generic-list-display .thumb').hide();
	}
	if (aData[new_index].precio != '') {
		$('div.generic-list-display .price').text('Prix Location: ' + aData[new_index].precio);
		$('div.generic-list-display .price').show();
	}
	else {
		$('div.generic-list-display .price').hide();
	}
	
	$('div.generic-list-display').oneTime(75, 'timer', function () {
		$(this).fadeIn('def', function () {
			$('div.spacer').hide();
		});
	});
}

