$(document).ready(function(){
	//toggle submenu del sidebar derecho:
	$("#snail-links li a").click(function(){
		$($($(this).parent()).children("ul")[0]).toggle("slow");
		$(this).toggleClass("menos");
	})
	
	//toggle menu de blog:
	$("#menuBlog ul a.cerrado").click(function(){
		$($($(this).parent()).children("ul")[0]).toggle("fast");
		$(this).toggleClass("abierto");
		return false;
	})
	
	
	
	//areas de scrollers
	$(".panel").each(function(){
		anchoT = 0;
		altoT = 0;
		$($($(this).children("ul"))).children("li").each(function(){
			// cojo el ancho de cada elemento teniendo en centa margenes y rellenos
			var anchoImg = $(this).width();
			var margenLi = $(this).css("margin-right");
			var paddingLir = $(this).css("padding-right");
			var paddingLil = $(this).css("padding-left");
			anchoT = anchoT+(anchoImg+parseInt(margenLi)+parseInt(paddingLir)+parseInt(paddingLil));
			// cojo la altura del elemento teniendo en cuenta margenes y rellenos:
			var altoLi = $(this).height();
			var HmargenLi = $(this).css("margin-bottom");
			var paddingLit = $(this).css("padding-top");
			var paddingLib = $(this).css("padding-bottom");
			sumaH = altoLi+parseInt(HmargenLi)+parseInt(paddingLit)+parseInt(paddingLib);
			if (altoT < sumaH) {
				altoT = sumaH
			}
		});
		if ($(this).attr("rel")== "dosLineas") {
			$($(this).children("ul")).css("width", anchoT/2);
			$(this).css("height", altoT*2+20);
		}
		else if ($(this).attr("rel")== "3Lineas") {
			$($(this).children("ul")).css("width", anchoT/3);
			$(this).css("height", altoT*3+10);
		}
		else if ($(this).attr("rel")== "4Lineas") {
			$($(this).children("ul")).css("width", anchoT/4);
			$(this).css("height", altoT*4+10);
		}
		else {
			$($(this).children("ul")).css("width", anchoT);
			$(this).css("height", altoT+15);
		}
		$(this).css("position", "relative");
	});
	
	// persiana scrolling  imagen:
	$(function() {
		$('.genteLooc ul.persianas li').hover(function(){
			var alto = $($(this).children("img")[0]).height();
			$(this).find('img').animate({top: alto+'px'},{queue:false,duration:900});
		}, function(){
			$(this).find('img').animate({top:'0px'},{queue:false,duration:900});
		});
	});
	
	$(".showThat").click(function(){
		var altoVentana = $("body").height();
		$("body").prepend("<div id='overlay'> </div>");
		$("#overlay").css("height", altoVentana);
		var a = $(this).attr("rev");
		$("#"+a).show("fast");
		//detecta explorer para meter un hack:
		var vIE=/*@cc_on function(){
		      switch(@_jscript_version){
		           case 5.5:return 5.5;
		           case 5.6:return 6;
		           case 5.7:return 7;
		        }
		     }()||@*/0;
		if (vIE==6) {
		  	$("#screen").css("display", "none"); //hack para que el video flash no se superponga al modal en Explorer
		}
		else if (vIE==7) {
			var altoV = $("#screen").height();
			$($("#screen").children("object")).css("display", "none");
			$("#screen").height(altoV);
			$("#screen").css("display", "none");
		}
		else {
			var altoV = $("#screen").height();
			$($("#screen").children("object")).css("display", "none");
			$("#screen").height(altoV);
			$("#screen").css("display", "block");
		}
		return false;
	});

	$(".closeThis").click(function(){
		var a = $(this).attr("rev");
		$("#"+a).hide("fast");
		$("#overlay").hide();
		$("#screen").css("display", "block"); //hack para que el video flash no se superponga al modal en Explorer
		$($("#screen").children("object")).css("display", "block");
		return false;
	});
	
	//colaboradores scroll:
	$("#colaboradores .panel ul li a").mouseover(function(){
		var a = $($(this).children("img")).attr("alt");
		$("#colaboradores h4.quien").html(a);
	});
	
});
