// JavaScript Document
var listaFotos = ["../img/fondoD_002.jpg","../img/fondoD_001.jpg","../img/fondoD_003.jpg","../img/fondoD_004.jpg"];

var imgAct = 0;
var tiempoEntreTrans = 5000;

function pasoCarrusel() {
	// set up the node / element
	_im =$("<img>");
	
	// hide and bind to the load event
	_im.hide();
	_im.bind("load",function(){ 
		$(this).fadeIn(1000).queue(function() {
			$(this).prev().remove();
			setTimeout(pasoCarrusel,tiempoEntreTrans);
			$(this).dequeue();
		});
		
	});
	_im.bind("error",function(){
		$(this).remove();
		pasoCarrusel(); 
	});
	
	
	// append to target node / element
	$('.fondoAnimado').append(_im);
	
	// set the src attribute now, after insertion to the DOM
	imgAct++;
	if (imgAct >= listaFotos.length) imgAct = 0;
	_im.attr('src',listaFotos[imgAct]);
}

function iniciaMarcadorMenu() {
	$("#menu a.activo").mouseleave();
}

function inicializacionGeneral() {
	$("#menu a").mouseenter(function() {
		$(this).addClass("encima");
		$("#marcaMenu").stop(true, false).animate({
				left: $(this).position().left,
				width: $(this).outerWidth()
				});
	}).mouseleave(function() {
		$(this).removeClass("encima");
		$("#marcaMenu").stop(true, false).animate({
				left: $("#menu a.activo").position().left,
				width: $("#menu a.activo").outerWidth()
				});
	});
	
	$("#idioma a").hover(function() {
		$(this).addClass("encima");
	},function() {
		$(this).removeClass("encima");
	}).click(function() {
		if (location.protocol == "file:") return true;
		var auxStr = location.pathname;
		if (auxStr.indexOf("/" + this.id + "/") == 0) return false;
		if (auxStr.indexOf("/index") != -1) return true;
		if (auxStr.length <= 1) return true;
		else {
			var ind = auxStr.indexOf("/",1);
			location.pathname = "/" + this.id + "/" + auxStr.substr(ind + 1);
			return false;
		}
	});
	
	setTimeout(iniciaMarcadorMenu,500);
	
	setTimeout(pasoCarrusel,tiempoEntreTrans);
};
