MOSAICO = {
	inicio : function (evento) {
		MOSAICO.todosiluminados(null);
		$("ul#fotos, #secciones ul a, ul#fotos .foto").hover(MOSAICO.ilumina, MOSAICO.apaga);
		$("#fotos li:nth-child(4n)").css("width","117px");
	},
	todosiluminados : function (evento) {
		$("ul#fotos .foto").removeClass("inactivo");
		$("#secciones ul a").addClass("inactivo");
	},
	ilumina : function (evento) {
		id = evento ? evento.target.id.substring(1) : '';

		$("ul#fotos .foto").addClass("inactivo");
		$("#secciones ul a").addClass("inactivo");
		$("#f"+id).removeClass("inactivo");;
		$("#t"+id).removeClass("inactivo");
	},
	apaga : function (evento) {
		id = evento ? evento.target.id.substring(1) : '';
		bEsFoto = $(evento.target).hasClass("foto");

		if (bEsFoto) {
			$("ul#fotos .foto").addClass("inactivo");
			$("#secciones ul a").addClass("inactivo");
		}
		else {
			$("ul#fotos .foto").removeClass("inactivo");
			$("#secciones ul a").addClass("inactivo");
		}
	}
}

VISORVIDEO = {
	inicio : function (evento) {
		$("#videos a").bind("click", VISORVIDEO.playEnVisor);
	},
	playEnVisor : function (evento) {
		/* Explorer, Opera y Safari utilizan el método no estandar */
		oPlayer = ($.browser.mozilla) ? document['playerVideoW3C'] : window['playerVideoNoW3C'];
		if (oPlayer) {
			oPlayer.SetURL(this.href);
			evento.preventDefault();
		}
	}
}

LISTAVIDEOS = {
	aImg : null,
	inicio : function (evento) {
		if (document.getElementById("ficha")) {
			//Cargamos la lista de imagenes

			// Primero conseguimos la sección de la que queremos extraer las imágenes
			var idSec = $("#secciones").attr("class").replace(/seccion/, "");

			$.getJSON("/listavideos.php?idSec="+idSec,
				function(data){
					LISTAVIDEOS.original = $("#fotograma img").get(0);
					LISTAVIDEOS.aImg = new Array();

					$.each(data.items, function(i,item){
					var oImg = new Image;
					oImg.src = item.media
					LISTAVIDEOS.aImg.push(oImg);
					});
				}
			);

			/* Asignamos la imagen que se tiene que mostrar a cada elemento de la lista */
			$("#secciones li a").each(
				function(i) {
					$(this).hover(
						function(evento) {
							$("#fotograma").html(LISTAVIDEOS.aImg[this.getAttribute("posicion")]);
							//$("#detalle").hide();
							//$.log(LISTAVIDEOS.aImg[0]);
						},
						function(evento) {
							$("#fotograma").html(LISTAVIDEOS.original);
							//$("#detalle").show();
							//$.log(LISTAVIDEOS.original);
						}
					)
					.attr("posicion", i);
				}
			);

		} /* if (ficha) */
	}
}

$(document).ready(function(e) {
	MOSAICO.inicio(e);
	VISORVIDEO.inicio(e);
	LISTAVIDEOS.inicio(e);
	$('.scroll').jScrollPane().css("padding-right","0");

});

