var mapasOficinas={
	mapas:[
	"../consulnor/maps_vizcaya.html",
	"../consulnor/maps_guipuzcoa.html",
	"../consulnor/maps_alava.html",
	"../consulnor/maps_logrono.html",
	"../consulnor/maps_madrid.html",		
	"../consulnor/maps_barcelona.html"	
	]
}
;
$(document).ready(function(){
	
	//acciones para los accionistas y consejos
	$(".modType09 .content:first").css("display","block");
	$(".modType09:first  h3 a").addClass("active");
	$(".modType09 h3 a").click(function(){
		$(".modType09 h3 a").removeClass("active");
		//($(this).hasClass("active"))?$(this).removeClass("active"):$(this).addClass("active");
		if ($(this).parent().parent().find(".content").css("display") != "block") {
			$(".modType09 .content").slideUp("slow");
			$(this).parent().parent().find(".content").slideToggle("slow");
			$(this).addClass("active");			
		}
		else{
			$(this).parent().parent().find(".content").slideToggle("slow");
			//$(this).parent().parent().parent().find("h3 a").addClass("active");
			$(this).removeClass("active");
		}
		return false;
	});
	
	$(".provincias li a").click(function(){
			$(".provincias li a").removeClass("active");
			$(this).addClass("active");
			$(".capaProvincia").css("display","none");
			var num = this.id.split("-");
			$(".capaProvincia[id=capa-"+num[1]+"]").css("display","block");
			
	});
	
	// acciones para informes							 
	$(".modType09 .lista").css("display","none");
	$(".modType09 .verMas").click(function(){		
		if ($(this).parent().parent().find(".lista").css("display") != "block") {
			$(".modType09 .content").slideUp("slow");
			$(this).parent().parent().find(".lista").slideToggle("slow");				
		}
		else{
			$(this).parent().parent().find(".lista").slideToggle("slow");
		}
		return false;
			
	});
	
	// acciones para las oficinas
	if ($("#oficinas").length > 0) {
		var oficina=document.location.href.split("#")[1];
		if(oficina!=""){
		  $("#"+oficina).css("display", "block");
		}
		$(".mapas").css("visibility","hidden");
		/*
$(".mapaButton").click(function(){
			var mapas=$(this).parent().find(".mapas")
			if(mapas.css("visibility")=="visible"){
				mapas.css("visibility","hidden");
				mapas.css("margin-left","-9999999px")
				$("#"+mapas.attr("id")).html("");
			}
			else{
				mapas.css("visibility","visible");
				mapas.css("margin-left","60px");
				var num=mapas.attr("id");
				var uri=mapasOficinas["mapas"][num.split("-")[1]-1];
				$("#"+num).html('<iframe src="'+uri+'" height="360" width="560"></iframe>');
			}
			return false;
		});
*/
		$("#oficinas").val("-1");
		$("#oficinas").change(function(){
			if (this.value != "-1") 
				switch (this.value) {
					case "0":
						$(".direccion").css("display", "block");
						var mapas=$(".mapas");
						mapas.css("visibility","hidden");
						mapas.css("margin-left","-9999999px");
						mapas.html("");
						break;
					default:
						var mapas=$(".mapas");
						mapas.css("visibility","hidden");
						mapas.css("margin-left","-9999999px");
						mapas.html("");

						$(".direccion").css("display", "none");
						$("#oficina-" + this.value).css("display", "block");
				}
			
		});
		
		$("#map area").click(function(){
			$(".direccion").css("display", "none");
			$($(this).attr("href")).css("display", "block");
			var mapas=$(".mapas");
			mapas.css("visibility","hidden");
			mapas.css("margin-left","-9999999px");
			mapas.html("");
			
		});
	}
	
	// acciones para el tooltip
	if ($('.tooltip').length>0) {
		$('.tooltip').tooltip({
			delay: 0,
			showURL: false
		
		});
	}
	// acciones linea de tiempo
	if($(".lineaTiempo").length>0){
		$(".lineaTiempo ul a").click(function(){
			var num=$(this).attr("id").split("-")[1];
			$(".lineaTiempo .content").attr("id","year-"+num);
			$(".lineaTiempo .lineaText").css("display","none");
			$(".lineaTiempo a").removeClass("active");
			$(this).addClass("active");
			$("#lineaText-"+num ).css("display","block");
			return false;
		})
	}
	
	$("#capaDesplegable").css("display","none");
	$("#listado01 li a").click(function(){
			$("#listado01 li a").removeClass("active");
			$(this).addClass("active");
			$("#capaDesplegable").css("display","block");
			$("#capaDesplegable div").css("display","none");
			var num = this.id.split("-");
			$("#capaDesplegable div[id=capa-"+num[1]+"]").css("display","block");
			
	});
	
	//acciones para select de operaciones
	 $("#operaciones").change(function(){
	 	switch($(this).val()){
			case "2":
				window.location.href="../corporate_finance/corporate_finance_referencias_actuales.php";
			break;
			case "1":
				window.location.href="../corporate_finance/corporate_finance_referencias_realizadas.php";
			break;
		}
	 });
	 
	 //acciones para la demo de mi cartera
	 
	 /*
	$(".captura .images a").lightBox({
	 	fixedNavigation:false,
		imageLoading:			'../images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'../images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'../images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			'../images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'../images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
		
		})*/
	$(".captura").each(function(){
		$(this).find(".controls a").each(function(i){
			$(this).click(function(){
				var aux = $(this).parent().parent().parent().find(".images li");
				$(this).parent().parent().find("a").removeClass("active");
				$(this).addClass("active");
				aux.css("display","none");
				aux.eq(i).css("display","block");
				return false;
			});
		})
		
		$("#capturas-menu li a").each(function(i){
			$(this).click(function(){
				$(this).parent().parent().find("a").removeClass("active");
				$(this).addClass("active");
				var aux =$(this).parent().parent().parent().find(".captura");
				aux.removeClass("active");
				aux.eq(i).addClass("active");
				return false;
			});
			
		})
		
	 })
	 
	 /*$('.captura>a').lightBox({fixedNavigation:true});
	 $(".captura").css("display","none")
	 $(".captura:first").css("display","block");
	 $("#capturas").find(".captura ul a").click(function(){
	 	var enlace=this;
		var title = $(this).attr("title");
		$(this).parent().parent().parent().find("img:first").fadeOut("fast", function(){
			$(this).attr("src",enlace);
			$(this).parent().attr("href",enlace);
			alert($(this).parent().attr("title"));
			$(this).parent().attr("alt",title);
		}).fadeIn("slow");
		
		
		return false;
	 });
	 $("#capturas-menu a").click(function(){
	 	$("#capturas-menu a").removeClass("active");
		$(this).addClass("active");
	 	var id=$(this).attr("id").split("-")[1];
		$(".captura").css("display","none");
		$(".captura[id=captura-"+id+"]").slideToggle("fast");
		return false;
	 })	;*/
	 
	 
	 // acciones desplegable
	  //$(".desplegableType01 .content:first").css("display","none").css("float","left")
	  //$(".desplegableType01 .modType09:first a").removeClass("active");
	 
	 //validaciones

	if (jQuery.validator) {
		jQuery.validator.setDefaults({
			onfocusout: false,
			onfocusin: false,
			onchange: false,
			onkeyup: false,
			onblur: false,
			onclik: false
		});
		var errorNormal = $('#errorNormal');
		errorNormal.append("<ul></ul>");
		
		//	 recordar password
		$("#recordarPass").validate({
			errorContainer: errorNormal,
			errorLabelContainer: $("ul", errorNormal),
			showErrors: function(errorMap, errorList){
				$("#errorNormal").addClass("errors");
				this.defaultShowErrors();
			},
			wrapper: 'li',
			meta: "validate",
			rules: {
				mail: {
					required: true,
					email: true
				}
			},
			messages: {
				mail: {
					required: "El campo correo electr&oacute;nico es obligatorio",
					email:"Introduzca un email v&aacute;lido"					
				}
			
			},
			submitHandler: function(form) {
			   $("#errorNormal").remove();
			   var success = $('<div class="success"><p>Recibir&aacute; su contrase&ntilde;a en su correo electr&oacute;nico</p></div>');
			   $("#recordarPass").before(success);
//			form.submit();
		   }
		
		});
		
		
		
		// trabaja con nosotros
		$("#trabajaConNosotros").validate({
			errorContainer: errorNormal,
			errorLabelContainer: $("ul", errorNormal),
			showErrors: function(errorMap, errorList){
				$("#errorNormal").addClass("errors");
				this.defaultShowErrors();
			},
			wrapper: 'li',
			meta: "validate",
			rules: {
				name: "required",
				surname: {
					required: true
				},
				mail: {
					required: true,
					email:true
				},
				coments: {
					required: true
				},
				condiciones: {
					required: true
				}
			},
			messages: {
				name: "El nombre es requerido",
				surname: "El Apellido es requerido",
				mail: {
					required: "El campo correo electr&oacute;nico es obligatorio",
					email:"Introduzca un email v&aacute;lido"
				},
				coments: "El campo consulta es obligatorio",
				condiciones: "Debe aceptar la pol&iacute;tica de tratamiento de datos"
			}
		});
		
		// nuevos Usuarios
		$("#nuevoUsuario").validate({
			errorContainer: errorNormal,
			errorLabelContainer: $("ul", errorNormal),
			showErrors: function(errorMap, errorList){
				$("#errorNormal").addClass("errors");
				this.defaultShowErrors();
			},
			wrapper: 'li',
			meta: "validate",
			rules: {
				password: "required",
				repassword: {
					required: true,
					equalTo:"#password"
				},
				email: {
					required: true,
					email:true
				},
				coments: {
					required: true
				},
				condiciones: {
					required: true
				}
			},
			messages: {
				password: "Debe introduccir una contrase&ntilde;a",
				repassword:{ 
					required:"El Apellido es requerido",
					equalTo:"La confirmación de la contrase&ntilde;a no coincide"
					},
				email:{
					required: "El campo correo electr&oacute;nico es obligatorio",
					email:"Introduzca un email v&aacute;lido"
				},
				condiciones: "Debe aceptar la pol&iacute;tica de tratamiento de datos"
			}
		});
	}
	
		// Use this example, or...
		$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
		// This, or...
		//$('#gallery a').lightBox(); // Select all links in object with gallery ID
		// This, or...
		//$('a.lightbox').lightBox(); // Select all links with lightbox class
		// This, or...
		//$('a').lightBox(); // Select all links in the page
		// ... The possibility are many. Use your creative or choose one in the examples above
});	
	
