$(document).ready(function(){	   
	
	//$("#PICS img:last-child").load(function(){centrargaleria();});
	centrargaleria();
	
	$("#bloquelogotipo #tempo").show("slow");
	$("#bloquelogotipo #lema").show("slow");
	$("#bloquelogotipo #data").show("slow");
	
	$("#redessociaistop li, #redessociais a, #menu_idiomas .activo").corner("5px");
	$(".itemGaleria").corner("7px");
	
	$(".mais").corner("tl 10px");
	
	
	$(".pestanasresumo h3").corner("5px");
	$("#panelportada_formacion .pestana").corner("tl 5px").corner("tr 5px");
	$("#panelportada_novas .pestana").corner("tl 5px").corner("tr 5px");
	
	

	
	$("iframe").load(function() {$(this).attr("allowtransparency","true");});
	
	
	
	
	/* para que la barra de scroll siempre sume ancho ------------------------------------- */
	$("html").css({"overflow-y":"scroll","overflow-x":"auto" });
	
	/* 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"});
	
	
	/* para colorear las filas de las tablas --------------------------------------------- */
	$("table.js_tblComun").each(function(){
		$(this).find("tbody tr:even").each(function(){
			$(this).addClass("js_colorAlterno");
		});
		$(this).find("tbody tr").hover(function(){
			$(this).addClass("js_colorHover");				   
		},
		function(){
			$(this).removeClass("js_colorHover");	
		});
	 });
	
	/* para iniciar colorBox ------------------------------------------------------------ */
	$("a[rel='colorbox_1'] , a[rel='colorbox_2'] , a[rel='colorbox_3']").colorbox({
		transition:"true",
		maxWidth:900,
		maxHeight:( $("body").height() - 20 ),
		opacity:0.50,
		current: "foto: {current} / {total}"
	});
	
	/* para iniciar jrMiniGaleria ---------------------------------------------------------*/
	$("#minigaleria_1 , #minigaleria_2 , #minigaleria_3").jrMiniGaleria({
		autoMovimiento : false,
        retardoEntreFotos : 8000
	});

	/* para iniciar jrMiniGaleria ---------------------------------------------------------*/
	/*$("#videoBar-bar").jrMiniGaleria({
		autoMovimiento : false,
        retardoEntreFotos : 8000
	});*/
	
	/* para o menu principal desplegable */
	$("ul.open").each(function(){
		$(this).show();
	});
								
	$("a.sn0").click(function(){
		$("a").removeClass('verm');
		if ($(this).next("ul").css("display")=="none"){
			$(this).removeClass('despregado');
		}else{
			$(this).addClass('despregado');
		}
	});
	
	$("a.sn1").click(function(){
		$("a").removeClass('verm');
		$(this).addClass('verm');
	});	
	
	$("a.sn2").click(function(){
		$("a.sn2").removeClass('verm');
		$(this).addClass('verm');
	});
	
	$("a.sn3").click(function(){
		$("a.sn3").removeClass('verm');
		$(this).addClass('verm');
	});	
	
	
	
	
	/* pestanas de resumo da columna dereita */		
	$(".pestanasresumo h3").click(function(){
		pestanexarm(this);
	});	
	selecc=$(".pestanasresumo h3:last");
	$(selecc).addClass("activo");
	$(".pestanasresumo h3:not(.activo)").next(".resumo").css("display","none");
	pestanexarm(selecc);
	/*
	maxH=0;
	$(".pestanasresumo .resumo").each(function(){
			if ($(this).outerHeight() >maxH){
				maxH=$(this).outerHeight();
			}
	});
	maxH=maxH+20+20+20;
	$(".pestanasresumo").css("height",maxH+"px");//.css("border","2px solid red");
	
	pestana=0;
	$(".pestanasresumo h3.pestana").each(function(){
		$(this).css("top",22*pestana+"px");
		pestana++;
	});
	
	$(".subpestana").next(".vermais").css("margin-top","-19px").css("float","right");
	*/
	
	
	
	
	
	/* pestanas de resumo en portada */		
	$("#panelportada_formacion h2").click(function(){	pestanexar2(this);});	
	selecc=$("#panelportada_formacion h2:first");
	pestanexar2(selecc);
	maxH=0;
	$("#panelportada_formacion .resumo").each(function(){
			if ($(this).outerHeight() >maxH){maxH=$(this).outerHeight();	}
	});
	maxH=maxH+20+20+20;
	//$("#panelportada_formacion").css("height",maxH+"px");
	pestana2=0;
	$("#panelportada_formacion h2.pestana").each(function(){
		//$(this).css("top",22*pestana2+"px");
		pestana2++;
	});
	$(".subpestana").next(".vermais").css("margin-top","-19px").css("float","right");
	
	
	
	/* pestanas de resumo en portada */		
	$("#panelportada_novas h2").click(function(){	pestanexar3(this);});	
	selecc=$("#panelportada_novas h2:first");
	pestanexar3(selecc);
	maxH=0;
	$("#panelportada_novas .resumo").each(function(){
			if ($(this).outerHeight() >maxH){maxH=$(this).outerHeight();	}
	});
	maxH=maxH+20+20+20;
	pestana2=0;
	$("#panelportada_novas h2.pestana").each(function(){
		//$(this).css("top",22*pestana2+"px");
		pestana2++;
	});
	$(".subpestana").next(".vermais").css("margin-top","-19px").css("float","right");
	
	
	
/*	
  maxH=0;
 $("#panelportada_novas .resumo, #panelportada_formacion .resumo").each(function(){			
			maxH=$("#panelportada_novas .resumo").height();
			if ($("#panelportada_formacion .resumo").height() >maxH){
				maxH=$("#panelportada_formacion .resumo").height();
			}			
			//para compensar as alturas das pestanas de portada          		
            $("#panelportada_novas, #panelportada_formacion").css("height",maxH+"px");
	});
	maxH=maxH+20+5;
	$("#panelportada_novas, #panelportada_formacion").css("height",maxH+"px");
	 maxH=370;
	 $("#panelportada_novas, #panelportada_formacion").css("height",maxH+"px");
*/	 
	//alert(maxH);
	//maxH=maxH+20;
	//$("#panelportada_novas, #panelportada_formacion").css("height",maxH+"px");
	

		
	$('#PICS').cycle({ 
		fx: 'fade', 
		speed: 3000 ,
		timeout:1000,
		random: 1 
	 });			

	
});

$(window).load(function(){      
    //$("#panelportada_formacion").load(function(){
       compensarAlturasPortada();
    //});
});

$(window).resize(function() {
	centrargaleria();
});

function compensarAlturasPortada(){
    maxH=0;
    
    maxH=$("#pp1").height();

    if ($("#pp2").height()>maxH){
        maxH=$("#pp2").height();
    }
    
    if ($("#pp3").height()>maxH){
        maxH=$("#pp3").height();
    }  
    
    if ($("#pp4").height()>maxH){
        maxH=$("#pp4").height();
    } 
    
    if ($("#pp5").height()>maxH){
        maxH=$("#pp5").height();
    }       
    
    if ($("#pp6").height()>maxH){
        maxH=$("#pp6").height();
    }         
    
    maxH=maxH+20;    
    //maxH=350;

    $("#pp1, #pp2, #pp3, #pp4, #pp5, #pp6").css("height",maxH+"px");
}

function centrargaleria(){
	if($('#PICS').css('display')=="none"){
		$('#PICS').css("display","block");
	}
	distancia=($(window).width()/2)-500-5;
	//alert(distantia);
	distancia=distancia+"px";
  	$('#PICS').css('left', distancia);
}


function pestanexar2(secc){
	$("#panelportada_formacion h2").removeClass("activo");
	$(secc).addClass("activo");
	$("#panelportada_formacion h2.activo").next(".resumo").css("display","block");
	$("#panelportada_formacion h2:not(.activo)").next(".resumo").css("display","none");
}


function pestanexar3(secc){
	$("#panelportada_novas h2").removeClass("activo");
	$(secc).addClass("activo");
	$("#panelportada_novas h2.activo").next(".resumo").css("display","block");
	$("#panelportada_novas h2:not(.activo)").next(".resumo").css("display","none");
}

function pestanexarm(secc){
	$(".pestanasresumo h3.activo").next(".resumo").slideUp('slow', function() {
		$(".pestanasresumo h3").removeClass("activo");
		$(secc).addClass("activo");
		//$(".pestanasresumo h3.activo").next(".resumo").css("display","block");
		$(".pestanasresumo h3.activo").next(".resumo").slideDown('slow');
		//$(".pestanasresumo h3:not(.activo)").next(".resumo").css("display","none");
	});
}

function pestanexar(secc){
/*
	selectedOption = $(secc);
	nextOption = $(".pestanasresumo h3:last"); 
	selectedOption2 = $(secc).next(".remumo");
	nextOption2 = $(".pestanasresumo .resumo:last");  
	if ($(nextOption).text() != "") {             
		 $(selectedOption).remove();
		 $(nextOption).after($(selectedOption));
	}           
	if ($(nextOption2).text() != "") {             
		 $(selectedOption2).remove();
		 $(nextOption).after($(selectedOption2));
	}  
	*/
	$(".pestanasresumo h3").removeClass("activo");
	$(secc).addClass("activo");
	$(".pestanasresumo h3.activo").next(".resumo").css("display","block");
	$(".pestanasresumo h3:not(.activo)").next(".resumo").css("display","none");
	//alert($(".pestanasresumo h3.activo").next().css());
	
}



/* para o menu principal desplegable */
$(function(){
	(function($){
		
		$.fn.accordion = function(custom) {
			var defaults = {
				keepOpen: false,
				startingOpen: false
			} 
			var settings = $.extend({}, defaults, custom);
			if(settings.startingOpen){
				$(settings.startingOpen).show();
			}
		
			return this.each(function(){
				var obj = $(this);
				$('li a', obj).click(function(event){
						var elem = $(this).next();
						if(elem.is('ul')){
							event.preventDefault();
							if(!settings.keepOpen){
								obj.find('ul:visible').not(elem).not(elem.parents('ul:visible')).slideUp('fast', function(){

																																	$("a.sn0").addClass('despregado');

																														  });
							}
							
							elem.slideToggle('fast');
														
						}
				});

			});
		};
		
		$('#menu').accordion({keepOpen:false, startingOpen: '#open'});
		
	})(jQuery);
	
});

//, function(){alert("mmmmm");}


