var pagina;
var submenuActual;
var intervaloSubmenu;
var altoColCentral;

$(document).ready( function (){

	// MENU Y SUBMENU
	$("#mainMenu a").mouseover(dentroMM).mouseout(fueraMM).click( function (){ return false });
	$("#submenu a").mouseover(dentroSM).mouseout(fueraSM);
	$("#accesoDirecto a").hover(dentroAD, fueraAD)
	$("#submenu ul").hide();
	
	pagina = String(location).substr(String(location).lastIndexOf("/")+1, 10);
	indiceMenu = Number(pagina.charAt(3))-1;
	submenuActual = "#sm"+Number(indiceMenu+1);
	indiceSubmenu = Number(pagina.charAt(5))-1;
	
	$("#mainMenu a:eq("+indiceMenu+")").css({ color: "#95c338" }).unbind('mouseout', fueraMM);
	$("#submenu #sm"+(indiceMenu+1)+" a:eq("+indiceSubmenu+")").css({ color: "#95c338" }).unbind('mouseout', fueraSM);
	$("#submenu #sm"+(indiceMenu+1)).show();

	// CORRIGE SUBMENU
	//$(document).mousemove(function (){ clearInterval(intervaloSubmenu); intervaloSubmenu = setInterval(muestraSubmenu, 4000); })
	
	
	// SCROLL
	altoColCentral = $("#col_centro").height();
	if($("#mascara").height()>$("#col_centro").height()){ activaScroll(); };
	
	// LIGHTBOX GALERIA
	$("#listaMini a").prettyPhoto({ theme: 'light_square', showTitle: false });
	
	// LIGHTBOX MODAL
	$(".modal").prettyPhoto({ theme: 'light_square', showTitle: false });
	
	// GALERIA
	$("#listaMini").carrusel();
	
	// PÁGINAS ESPECIALES
	paginasEspeciales();

})




////////////////////////////////////////////////////////////////////////////////////////////////
//
//  MENU PRINCIPAL, SUBMENU Y ACCESOS DIRECTOS
//
////////////////////////////////////////////////////////////////////////////////////////////////
function dentroMM(){
	$(this).css({ color: "#95c338" });
	$("#submenu ul").hide();
	$(String($(this).attr("href"))).fadeIn();
}
function fueraMM(){
	$(this).css({ color: "#FFF" });
}
function cargaPortada(){
	url = $(this).attr("href");
	$("#submenu ul").hide();
	$("#contenidos").animate({ opacity:0 }, 500, function(){ location = url; });
	return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////
function dentroSM(){
	$(this).css({ color: "#95c338" });
}
function fueraSM(){
	$(this).css({ color: "#ccc" });
	clearInterval(intervaloSubmenu);
	intervaloSubmenu = setInterval(muestraSubmenu, 5000);
}
////////////////////////////////////////////////////////////////////////////////////////////////
function dentroAD(){
	$(this).css({ color: "#95c338" });
}
function fueraAD(){
	$(this).css({ color: "#FFF" });
}

function muestraSubmenu(){
	//alert("muestra SM ->  "+submenuActual);
	clearInterval(intervaloSubmenu);
	$("#submenu ul").hide();
	$(submenuActual).fadeIn();
}





////////////////////////////////////////////////////////////////////////////////////////////////
//
//  SCROLL TEXTO
//
////////////////////////////////////////////////////////////////////////////////////////////////
function activaScroll(){
	$("#col_centro").css({ overflow:"hidden" }).append("<div id='subeScroll'></div><div id='scroll'><div id='arrastraScroll'></div></div><div id='bajaScroll'></div>");
	$("#scroll").css({ width:"10px", height:(altoColCentral-20)+"px", background:"#dedede", position:"absolute", right:"4px", top:"10px"});
	$("#subeScroll").css({ width:"10px", height:"10px", background:"url(_img/bg_btn_scroll.gif) top", position:"absolute", right:"4px", top:"0px"}).click(subeScroll);
	$("#bajaScroll").css({ width:"10px", height:"10px", background:"url(_img/bg_btn_scroll.gif) bottom", position:"absolute", right:"4px", bottom:"0px"}).click(bajaScroll);
	$("#arrastraScroll").css({ width:"10px", height:"50px", background:"#424242"}).draggable({ containment: "parent", drag:scrollContenido });
}
function subeScroll(){
	var nuevaPos = Number($("#arrastraScroll").position().top-100)
	$("#arrastraScroll").css({ top: nuevaPos+"px" });
	if ( nuevaPos <0 ){ $("#arrastraScroll").css({ top: "0px" }); }
	scrollContenido();
}
function bajaScroll(){
	var nuevaPos = Number($("#arrastraScroll").position().top+100)
	$("#arrastraScroll").css({ top: nuevaPos+"px" });
	if ( nuevaPos >(altoColCentral-70) ){ $("#arrastraScroll").css({ top: (altoColCentral-70)+"px" }); }
	scrollContenido();
}
function scrollContenido(){
	alturaContenido = $("#mascara").height();
	alturaScroll= $("#scroll").height();
	desplazamiento = alturaContenido-alturaScroll;
	cadena = $("#arrastraScroll").css("top")
	sinPX = Number(cadena.substr(0, cadena.indexOf("p")))
	porcentaje = (sinPX*100)/(alturaScroll-$("#arrastra").height());
	posYcontenido = (porcentaje*desplazamiento)/100
	$("#mascara").css("marginTop",-posYcontenido );
}



////////////////////////////////////////////////////////////////////////////////////////////////
//
//  PÁGINAS ESPECIALES
//
////////////////////////////////////////////////////////////////////////////////////////////////
function paginasEspeciales(){
	switch(pagina){
		////////////////////////////////////////////////////
		// EQUIPO
		////////////////////////////////////////////////////
		case "sec2_5.php":
			$("#staff div").hide();
			//$("#staff h4:eq(0)").css({ background:"#95c338"}).next().css({ background:"#e8e8e8"}).show();
			$("#staff h4:eq(0)").next().show();
			
			$("#staff h4").click(function (){
										   		//$("#staff h4").css({ background:"none"});
										   		$("#staff div").css({ background:"none"}).stop().slideUp(400);	
										   		//$(this).css({ background:"#95c338"}).next().css({ background:"#e8e8e8"}).stop().slideDown(400);
										   		$(this).next().stop().slideDown(400);
												// CARGA AUTOMÁTICA DE LA PRIMERA FOTO
												$("#fotosEquipo").css({ background: "#EEE url(_img/precarga.gif) no-repeat center"});
												$("#fotosEquipo img").attr("src", $(this).next().find(".foto:eq(0)").attr("href")).hide().load(function(){ $("#fotosEquipo").css({ background: "#EEE"}); $(this).show();})
												$("#nombreFotoEquipo p").text( $(this).next().find(".foto:eq(0)").text() );
											});	
			$(".foto").click(function (){
									   			$("#nombreFotoEquipo p").text($(this).text());
									   			$("#fotosEquipo").css({ background: "#EEE url(_img/precarga.gif) no-repeat center"});
												$("#fotosEquipo img").attr("src", $(this).attr("href")).hide().load(function(){ $("#fotosEquipo").css({ background: "#EEE"}); $(this).show();})
												return false;
										   	});	
			
		break;
		////////////////////////////////////////////////////
		// LISTADO TORNEOS
		////////////////////////////////////////////////////
		case "sec5_1.php":
			$(".itemTorneo:even").css({ background: "#DDD" });			
		break;
	}
}







