$(document).ready(function () {
	$('#espacio-interactivo a').each(function(i) {
		var direccion = this.href;
		var enlace = $(this);
		// ej. http://www.publifestival.es/productos/fotografias-jurados
		if (direccion.indexOf('/productos/') != -1) {
			$.ajax({
					type: "GET",
					url: direccion + '?ajax=true', // '/paginas/' + id,
					data: null,
					dataType: 'html',
					success: function(msg){
						var d = new Date();
						var t = d.getTime();
						var id = 'fotos-cargadas-' + t;
						$('#espacio-interactivo').append('<div id="' + id + '" style="display:none">' + msg + '</div>');
						$('#' + id + ' a').attr('rel', 'shadowbox['+id+']');
						enlace.addClass('shadow');
						enlace.attr('href', $('#' + id + ' a:first').attr('href'));
						enlace.attr('rel', 'shadowbox['+id+']');
						$('#' + id + ' a:first').remove();
						tmp = msg.split('h2>');
						titulo = tmp[1].replace('</','');
						if (titulo) {
//							$('#fotos-cargadas a').attr('title', titulo);
							enlace.attr('title', titulo);
						}

						Shadowbox.setup("a.shadow", {
						     /*   gallery:            "Fotos" + id, */
						        autoplayMovies:     true
						    });
					},
					complete: function (XMLHttpRequest, textStatus) { }
				});
				
		} else if (direccion.indexOf ('youtube.com') != -1)
		{
			// ej: http://www.youtube.com/watch?v=pzOYDmHvzrE&feature=player_embedded
			// convertir en http://www.youtube.com/v/pzOYDmHvzrE
			var partes = enlace.attr('href');
			partes = partes.split('?');
			partes = partes[1].split('&');
			partes = partes[0].split('=');
			id = partes[1];
			if (id)
				enlace.attr('href', 'http://www.youtube.com/v/' + id);
			enlace.addClass('shadowvideo');
			Shadowbox.setup("a.shadowvideo", {
			        gallery:            "Vídeo",
			        autoplayMovies:     true,
			        width:	640,
			        height: 480
			    });
		}
		else {
			Shadowbox.setup("a.shadowbox");
		}
		
		
		
	});
});
