// Se ejecuta al terminar la ejecución del script PHP
function changeImg(img, ind){
	var loadImg = new Image();
	loadImg.onload=function(){
		// Mostrar nueva imagen y activar link correcto
		$("#welcome a:eq("+ind+")").attr('class','selected');
		$('#welcomePhoto img').attr('src',img).fadeIn(600);
	}
	loadImg.src = img;
}

// funcion AJAX
function loadImg(ind){
	// Ocultar imagen y hacer llamada al script PHP
	$("#welcome a").attr('class','');
	$('#welcomePhoto img').fadeOut(600,function(){
		$.ajax({type: 'GET', url:server+'ajax_img.php', data: 'img='+ind, success: function(html){changeImg(html,ind-1)}});
	});
}

// añadir evento a cada uno de los links de las imagenes
$(document).ready(function(){
	$("#welcome a").bind("click", function(){loadImg( $(this).attr('href').replace(server+'index.php?img=','')); return false;});
});