// calcula las dimensiones máximas que puede tener el escriotrio
$(document).ready(function(){	   
				
	$("body").css({"overflow-y":"scroll"});
	
	/* combertir un listado de fotos en un slide vertical ---------------------------------- */
	$(".listaFotos").mousemove(function( e ){
		var $listaFotos = $(this);
		var $lista = $(this).find("ul");
		if( $listaFotos.height() < $lista.height() ){
			var margenTop = 50;
			var margenBottom = 100;
			var mouseTop = 	Math.round(( e.clientY + $("#colDer").scrollTop() ) - $listaFotos.offset().top) - margenTop ;	
			var espacioRest = ($lista.outerHeight() - $listaFotos.height()) + margenBottom;
			var posTop = Math.round((mouseTop*( espacioRest * -1 ))/$listaFotos.height());
			if( posTop > 0 ){
				posTop = 0;
			}
			if( posTop < ((espacioRest - margenBottom)*-1) ){
				posTop = ((espacioRest - margenBottom)*-1)  ;
			}
			$lista.css({top: posTop });
		}
	});
	
	/* añade target="_black" a enlaces con class="targetBlanck" --------------------------- */
	$("a.js_targetBlank").each(function(){
		var js_targetBlank = $(this);
		var HREF = js_targetBlank.attr("href");
		js_targetBlank.bind("click", function(e){
			window.open(HREF);
			return false;
		});
		js_targetBlank.bind("keypress", function(e){
			if( e.which == 13 ){
				window.open(HREF);
			}
			return false;
		});
	});
	
	/* quita el borde que crea firefox en el onFocus ---------------- */
	$("a").css({ "outline":"none"});
	
	/* crea la barra de scroll ---------------------------------------*/
	$(window).bind("resize", rersizeContendores);
	rersizeContendores();
	
	var timeOutIdHref;
	/*Moviendo scroll al módulo clickado -----------------------------*/
	$("#subMenuWeb li a").bind("click", function(){
		$this = $(this);
		var destino = $this.attr("href");
		$("#colDer").each(function(){
			this.scrollTo(destino);
		});
		clearTimeout(timeOutIdHref);
		timeOutIdHref = setTimeout(function(){
			location.href=(destino);
		},700);
		return false;
	});
	
	$("a.moverInicio, a#logoWeb, a.moverAModulo").each(function(){
		var moverInicio = $(this);
		moverInicio.bind("click", function(){
			var destino = moverInicio.attr("href");
			$("#colDer").each(function(){
				this.scrollTo(destino);
			});
			clearTimeout(timeOutIdHref);
			timeOutIdHref = setTimeout(function(){
				location.href=(destino);
			},700);
			return false;
		});
	});
	
	
});


var intervalIdPossTop;

function rersizeContendores(){
return false;
	var $colder = $('#colDer');
	$colder.jScrollPaneRemove();
	
	var cuerpo = $("body");
	var contenedor = $("#contenedor");
	var colIzq = $("#colIzq");
	var colDer = $("#colDer");
	colIzq.height( contenedor.height() - colIzq.offset().top );
	colDer.height( contenedor.height() - colDer.offset().top );
	
	
	var modulosPossTop_ar = new Array();
	
	$(".modulo").each(function(){
		$this = $(this);
		if( $this.height() <= colDer.height() ){
			$this.height( colDer.height() );
		}
	});
	
	
	$('#colDer').jScrollPane({
		showArrows:true,
		arrowSize:15,
		scrollbarWidth:10,
		animateTo:true, 
		animateInterval:10, 
		animateStep:7
	});
	
	
	var modulosPossTop_ar = new Array();
	$(".modulo").each(function(){
		$this = $(this);
		modulosPossTop_ar.push( new Array( $this.attr("id") , $this.position().top ) );
	});
	
	clearInterval( intervalIdPossTop );
	intervalIdPossTop = setInterval(function(){
		
		var postionTop = Math.round( $colder.position().top * -1 );
		var debugStr = "";
		for(var i=0; i< modulosPossTop_ar.length; i++ ){
			
			var id = modulosPossTop_ar[i][0];
			var top = modulosPossTop_ar[i][1];
			var ctrl = $("a[href='#"+id+"']");
			var modulo = $("#"+id);
			if( postionTop > (top-50) && postionTop < (top+(modulo.height()-50)) ){
				ctrl.addClass("itemActivo");
			}else{
				ctrl.removeClass("itemActivo");
			}
		}
	}, 500);

	
	
}

$(window).load(function(){	
	$('#colDer').each(function(){
		this.scrollTo( "#" + location.href.split("#").pop() );
	});
});



function focalizaEnlaceModuloDesdeFlash( id_modulo ){
	$('#subMenuWeb li a[href="#modulo_'+id_modulo+'"]').addClass("itemFlashHover");
}
function desfocalizaEnlaceModuloDesdeFlash( id_modulo ){
	$('#subMenuWeb li a[href="#modulo_'+id_modulo+'"]').removeClass("itemFlashHover");
}
var setTimerModulodesdeFlash;
function muestraModuloDesdeFlash( id_modulo ){
	setTimeout( function(){
		$('#subMenuWeb li a[href="#modulo_'+id_modulo+'"]').trigger("click");
	},100);
}











