/*!
* jQuery estudio crealia
*/

/* eliminar marco de enlaces */
jQuery(function($) {
	$('a').focus(function() {
		$(this).trigger('blur');
	});
	$('.display').focus(function() {
		$(this).trigger('blur');
	});
});

// Obtener calendario
jQuery(function($) {
	jQuery.fn.obtenerCalendario = function(nuevomes, nuevoanno, sig, mostrarp) {
		// declarar objeto
		var calen = this;
		//alert("A ver cómo funciona esto.");
		$.ajax({
			url: "/calendario/meses.php",
			data: "nuevo_mes="+nuevomes+"&nuevo_anno="+nuevoanno+"&sig="+sig+"&mostrarp="+mostrarp,
			async:true,
			beforeSend: function(objeto){
				//calen.fadeTo('fast', 0.1);
				calen.addClass('objload');
				$("#contcalend").remove();
				//calen.find('#contcalend').remove();
				//alert("Adiós, me voy a ejecutar");
			},
			complete: function(objeto, exito){
				//alert("Me acabo de completar")
				//if(exito=="success"){
					// alert("Y con éxito");
				//}
				//$("#calendario").append("<p>Recibido: " + objeto + "</p>");
			},
			contentType: "application/x-www-form-urlencoded",
			dataType: "html",
			error: function(objeto, quepaso, otroobj){
				//alert("Estas viendo esto por que fallé");
				//alert("Pasó lo siguiente: "+quepaso);
				//$("#calendario").append("<p>Error: " + quepaso + "</p>");
			},
			success: function(datos){
				calen.removeClass('objload');
				//alert(datos);
				//calen.fadeTo('slow', 1);
				//calen.append('<div id="contcalend">' + datos + '</div>');
				//calen.find('#contcalend').fadeTo('slow', 1);
				$('<div></div>')
				//calen.append('<div></div>')
				.attr({
					'id': 'contcalend',
					//'class': 'aviintranet'
				})
				.append(datos)
				.hide()
				.appendTo(calen)
				.fadeTo('slow', 1);
				
				// botón anterior
				var valor = calen.find('.fmesanterior').attr('alt');
				if (valor) {
					var valores = valor.split(',');
					//indexOf(',',valor);
					//calen.find('.fmesanterior').append(valor + " / " + valores[0] + " / " + valores[1]);
					calen.find('.fmesanterior').append(valores[0]);
					calen.find('.fmesanterior').click(function () {
						$("#calendario").obtenerCalendario(valores[0], valores[1], 1, mostrarp);
						return false;
					});
					calen.find('.fmesanterior').focus(function() {
						$(this).trigger('blur');
					});
				}
				
				// botón siguiente
				var valorsig = calen.find('.fmessiguiente').attr('alt');
				if (valorsig) {
					var valoressig = valorsig.split(',');
					//indexOf(',',valor);
					//calen.find('.fmesanterior').append(valor + " / " + valores[0] + " / " + valores[1]);
					calen.find('.fmessiguiente').append(valoressig[0]);
					calen.find('.fmessiguiente').click(function () {
						$("#calendario").obtenerCalendario(valoressig[0], valoressig[1], 0, mostrarp);
						return false;
					});
					calen.find('.fmessiguiente').focus(function() {
						$(this).trigger('blur');
					});
				}
			},
			type: "GET"
		});
	};
});


// efectos menu
jQuery(function($) {
	// nos aseguramos de no aplicar el efecto a versiones de ie que no soporten este código
	if ($.browser.msie && $.browser.version < 7) return;
		
	$('#nav')
		.removeClass('efecto')
		.find('a')
		.append('<span class="hover" />').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
	});
		
	$('#nav li').hover(function () {
		// on hover
		$(this).find('span.hover:first').stop().fadeTo('fast', 1);
	}, function () {
		// off hover
		$(this).find('span.hover:first').stop().fadeTo('fast', 0);
	});

	$('#nav li ul').css('left', 0)
	.not('.selec').hide();
	$('#nav li').hover(function() {
		$(this).find('ul').not('.selec').stop().fadeTo('fast', 1);
	}, function () {
		
		//$(this).find('ul').not('.selec').stop().fadeTo('slow', 0, function() {
			// oculto elemento para que no aparezca hasta pasar sobre el botón
			//$(this).hide();
		//});
		var obj = $(this).find('ul').not('.selec');
		//setTimeout(function(){
			obj.stop();
			obj.fadeTo('slow', 0, function() {
				// oculto elemento para que no aparezca hasta pasar sobre el botón
				$(this).hide();
			});
		//}, 200);
	});
	
//	var e = $('.notice'); 
//e.fadeIn(); 
//e.queue(function(){ 
  //setTimeout(function(){ 
    //e.dequeue(); 
  //}, 2000 ); 
//}); 
	
});

// tooltip
jQuery(function($) {
	/* CONFIG */		
	xOffset = 10;
	yOffset = 20;		
	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a[rel=galeriaNO]").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a[rel=galeriaNO]").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
});

//jQuery(function($) {
	//$("#galcont").fadeTo("slow", 0.3); // This sets the opacity of the thumbs to fade down to 30% when the page loads
	//$("#galcont").hover(function(){
		//$(this).find('img').fadeTo("slow", 0.3); // This should set the opacity to 100% on hover
	//},function(){
		//$(this).find('img').fadeTo("slow", 1.0); // This should set the opacity back to 30% on mouseout
	//});
//});

/* aparición imágenes con preload */
//jQuery(function($) {
	//$('img').hide().parent().addClass('objload');
	//if ($('img').attr('complete')) {
		//$('img').fadeIn('slow').parent().removeClass('objload');
	//} else {
		//$('img').load(function () {
			//$(this).fadeIn('slow').parent().removeClass('objload');
		//});
	//}
//});

/* efectos galería fotografías */
jQuery(function($) {
	$('.gal img').not('.vacio').hover(function(){
		$(this).stop().fadeTo('slow', 1);
		//$('.gal img').not(this).not('.vacio').stop().fadeTo('slow', 0.5);
		$(this).parents('.gal').find('img').not(this).not('.vacio').stop().fadeTo('slow', 0.2);
	},function(){
		//$(this).fadeTo('slow', 1);
	});
	$(".gal").hover(function(){
		//$(this).find('img').fadeTo("slow", 0.3); // This should set the opacity to 100% on hover
	},function(){
		$(this).find('.imggal img').not('.vacio').stop().fadeTo("slow", 1);
		$(this).find('.imggalnopub img').not('.vacio').stop().fadeTo("slow", 0.2); // This should set the opacity back to 30% on mouseout
	});
	
	$(".gal img.vacio").hover(function(){
		$(this).parents('.gal').find('.imggal img').not('.vacio').stop().fadeTo("slow", 1);
		$(this).parents('.gal').find('.imggalnopub  img').not('.vacio').stop().fadeTo("slow", 0.2);
	},function(){
		// nada
	});
});

/* formulario newsletter */
jQuery(function($) {
	
	var $buscador = $('#formnews li').addClass('sublabel');
	var $buscadorLabel = $buscador.find('label');
	$buscadorLabel.show();

	$('#mailnews').focus(function() {
		if ($(this).val() == $(this).attr('defaultValue')) {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$buscadorLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#mailnews').keyup(function() {
		if ($(this).val() != '') {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$buscadorLabel.fadeTo('fast', 0);
		} else {
			$buscadorLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#mailnews').blur(function() {
		if ($(this).val() == '') {
			//$(this).removeClass('imputactivo');
			//$def = $(this).attr('defaultValue');
			//$(this).val($def);
			$buscadorLabel.fadeTo('fast', 1);
		}
	});
	
	$('#formnews').submit(function () {
		//if ($('#usuario').val() == $('#usuario').attr('defaultValue') || $('#password').val() == $('#password').attr('defaultValue')) {
		//if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('#mailnews').val())) {
		if (/.+@.+\.[a-zA-Z]{2,4}$/.test($('#mailnews').val())) {
			$('#formnewsdiv').hide();
			$('#formnewsload').show();
			
			
			datosenviar = $(this).serialize();
			$.ajax({
				url: "/alta.php",
				data: datosenviar,//"mailSend=antonio@e-crealia.com",
				async:true,
				beforeSend: function(objeto){

				},
				complete: function(objeto, exito){

				},
				contentType: "application/x-www-form-urlencoded",
				dataType: "html",
				error: function(objeto, quepaso, otroobj){

				},
				success: function(datos){
					if (datos == 2) {
						var mensaje = 'No incluyó un correo electrónico válido';
					} else if (datos == 1) {
						var mensaje = 'Hemos enviado un correo de confirmación';
					} else {
						var mensaje = 'Hubo un problema al incluir su correo en nuestra lista';
					}
					$('#newsinfo').text(mensaje);
					// mostrar formulario
					$('#mailnews').val('');
					$buscadorLabel.fadeTo('fast', 1);
					$('#formnewsdiv').show();
					$('#formnewsload').hide();
					
				},
				type: "POST"
			});
		} else {
			var mensaje = "Debe incluir un correo electrónico válido";
			$('#newsinfo').text(mensaje);
		}

		return false;
	});
});

// validar formulario
jQuery(function($) {
	// validar campo al perder el foco
	$('#formcom :input').blur(function () {
		if ($(this).hasClass('requerido')) {
			var elemento = $(this).parents('li:first');
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			$(this).next('span.comentario').remove();
			if (this.value == '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if (this.id == 'mail') {
			var elemento = $(this).parents('li:first');
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			$(this).next('span.comentario').remove();
			if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.value)) {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
									
	});
	
	$('#formcom').submit(function () {
		$('#formcom :input').trigger('blur');
		var numAvisos = $('.aviso', this).length;
		$('#aviso-global').remove();
		if (numAvisos) {
			var listaCampos = [];
			$('label.aviso').each(function () {
				listaCampos.push($(this).attr('title'));
			});
			if (numAvisos == 1) {
				var mensajeAviso = 'El campo <strong>' + listaCampos + '</strong> no ha sido rellenado correctamente. Por favor, complételo.';
			} else {
				var mensajeAviso = 'Los campos <strong>' + listaCampos.join('</strong>, <strong>') + '</strong> no han sido rellenados correctamente. Por favor, complételos.';
			}
			$('<div></div>')
				.attr({
					'id': 'aviso-global',
					'class': 'aviexcl'
				})
				.append(mensajeAviso)
				.hide()
				.insertBefore('#enviar')
				.fadeIn('fast');
			return false;
		}
	});
	
});

/* formulario intranet */
jQuery(function($) {
	$('#intranet').hide();
	
	var $accesos = $('#formintranet li#usuarioli').addClass('sublabel');
	var $intraLabel = $accesos.find('label');
	
	var $accesospast = $('#formintranet li#pastli').addClass('sublabelpast');
	var $intraLabelPast = $accesospast.find('label');
	
	$('#vint').toggle(function() {
		$('#intranet').fadeIn('fast');
		return false;
	}, function () {
		//$('#intranet').fadeOut('fast');
		$('#intranet').fadeOut('fast', function() {
			// inicializar aspecto de formulario
			$(this).find('input').val('');
			$intraLabel.fadeTo('fast', 1);
			$intraLabelPast.fadeTo('fast', 1);
			$('#avisointranet').remove();
		});

		return false;
	});

	$('#usuario').focus(function() {
		if ($(this).val() == $(this).attr('defaultValue')) {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$intraLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#usuario').keyup(function() {
		if ($(this).val() != '') {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$intraLabel.fadeTo('fast', 0);
		} else {
			$intraLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#usuario').blur(function() {
		if ($(this).val() == '') {
			//$(this).removeClass('imputactivo');
			//$def = $(this).attr('defaultValue');
			//$(this).val($def);
			$intraLabel.fadeTo('fast', 1);
		}
	});
	
	$('#password').focus(function() {
		if ($(this).val() != '') {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$intraLabelPast.fadeTo('fast', 0);
		} else {
			$intraLabelPast.fadeTo('fast', 0.3);
		}
	});
	
	$('#password').keyup(function() {
		if ($(this).val() != '') {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$intraLabelPast.fadeTo('fast', 0);
		} else {
			$intraLabelPast.fadeTo('fast', 0.3);
		}
	});
	
	$('#password').blur(function() {
		if ($(this).val() == '') {
			//$(this).removeClass('imputactivo');
			//$def = $(this).attr('defaultValue');
			//$(this).val($def);
			$intraLabelPast.fadeTo('fast', 1);
		}
	});
	
	$('#formintranet').submit(function () {
		//if ($('#usuario').val() == $('#usuario').attr('defaultValue') || $('#password').val() == $('#password').attr('defaultValue')) {
		$('#avisointranet').remove();
		if ($('#usuario').val() == '' || $('#password').val() == '') {
			var mensajeAviso = 'Por favor, indique usuario y contrase&ntilde;a.';
			$('<span></span>')
				.attr({
					'id': 'avisointranet',
					'class': 'aviintranet'
				})
				.append(mensajeAviso)
				.hide()
				.insertAfter('#ienviar')
				.fadeIn('fast');
			return false;				   
		} else {
				
		}
	});
});

/* formulario intranet */
jQuery(function($) {
	$('#referenciacont').hide();
	$('#referenciacont').css('opacity', 0);
	
	var $correo = $('#referencia li#emailli').addClass('sublabel');
	var $refLabel = $correo.find('label');
	
	//var $accesospast = $('#formintranet li#pastli').addClass('sublabelpast');
	//var $intraLabelPast = $accesospast.find('label');
	
	$('#eevent').toggle(function() {
		//$('#referenciacont').fadeIn('fast');
		$('#referenciacont').animate({height: 'toggle'}, 'fast').animate({opacity: 1}, 'fast');
		return false;
	}, function () {
		//$('#intranet').fadeOut('fast');
		$('#referenciacont').animate({opacity: 0}, 'fast').animate({height: 'toggle'}, 'fast');
		$('#referenciacont').fadeOut('fast', function() {
			// inicializar aspecto de formulario
			$(this).find('input:text').val('');
			$refLabel.fadeTo('fast', 1);
			$('#avisoref').remove();
		});

		return false;
	});

	$('#email').focus(function() {
		if ($(this).val() == $(this).attr('defaultValue')) {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$refLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#email').keyup(function() {
		if ($(this).val() != '') {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$refLabel.fadeTo('fast', 0);
		} else {
			$refLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#email').blur(function() {
		if ($(this).val() == '') {
			//$(this).removeClass('imputactivo');
			//$def = $(this).attr('defaultValue');
			//$(this).val($def);
			$refLabel.fadeTo('fast', 1);
		}
	});

	$('#referencia').submit(function () {
		//if ($('#email').val() == '') {
		$('#avisoref').remove();
		contenido = $('#email').val();
		if (!/.+@.+\.[a-zA-Z]{2,4}$/.test(contenido)) {
			var mensajeAviso = 'Por favor, indique un correo electr&oacute;nico v&aacute;lido.';
			$('<span></span>')
				.attr({
					'id': 'avisoref',
					'class': 'aviref'
				})
				.append(mensajeAviso)
				.hide()
				.insertAfter('#renviar')
				.fadeIn('fast');				   
		//} else {
				
		} else {
			$('#avisoref').remove();
			$('<span></span>')
				.attr({
					'id': 'avisoref',
					'class': 'objloadpq'
				})
				.hide()
				.insertAfter('#renviar')
				.fadeIn('fast');
			
			
			datosenviar = $(this).serialize();
			$.ajax({
				url: "/gestion/referencias/enviar.php",
				data: datosenviar,//"mailSend=antonio@e-crealia.com",
				async:true,
				beforeSend: function(objeto){
					//calen.fadeTo('fast', 0.1);
					//calen.addClass('objload');
					//$("#contcalend").remove();
					//calen.find('#contcalend').remove();
					//alert("Adiós, me voy a ejecutar");
					
				},
				complete: function(objeto, exito){
					//alert("Me acabo de completar")
					//if(exito=="success"){
						// alert("Y con éxito");
					//}
					//$("#calendario").append("<p>Recibido: " + objeto + "</p>");
					
				},
				contentType: "application/x-www-form-urlencoded",
				dataType: "html",
				error: function(objeto, quepaso, otroobj){
					//alert("Estas viendo esto por que fallé");
					//alert("Pasó lo siguiente: "+quepaso);
					//$("#calendario").append("<p>Error: " + quepaso + "</p>");
					
				},
				success: function(datos){
					$('#avisoref').remove();
					var mensajeAviso = 'La referencia ha sido enviada.';
					$('<span></span>')
					.attr({
						'id': 'avisoref',
						'class': 'aviref'
					})
					.append(mensajeAviso)
					.hide()
					.insertAfter('#renviar')
					.fadeIn('fast');
				},
				type: "POST"
			});
		}
		
		return false;
	});
});

/* formulario buscador */
jQuery(function($) {
	
	var $buscador = $('#formbuscador li').addClass('sublabel');
	var $buscadorLabel = $buscador.find('label');
	$buscadorLabel.show();

	$('#buscar').focus(function() {
		if ($(this).val() == $(this).attr('defaultValue')) {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$buscadorLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#buscar').keyup(function() {
		if ($(this).val() != '') {
			//$(this).val('');
			//$(this).addClass('imputactivo');
			$buscadorLabel.fadeTo('fast', 0);
		} else {
			$buscadorLabel.fadeTo('fast', 0.3);
		}
	});
	
	$('#buscar').blur(function() {
		if ($(this).val() == '') {
			//$(this).removeClass('imputactivo');
			//$def = $(this).attr('defaultValue');
			//$(this).val($def);
			$buscadorLabel.fadeTo('fast', 1);
		}
	});
	
	$('#formbuscador').submit(function () {
		//if ($('#usuario').val() == $('#usuario').attr('defaultValue') || $('#password').val() == $('#password').attr('defaultValue')) {
		if ($('#buscar').val() == '') {
			return false;				   
		} else {
				
		}
	});
});

// validar formulario pedido
jQuery(function($) {
	// validar campo al perder el foco
	$('.formped :input').blur(function () {
		if (this.id == 'mail') {
			var elemento = $(this).parents('li:first');
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			$(this).next('span.comentario').remove();
			//if ($('#pass').val() != '') {
				if ((!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.value) || this.value == '') && ($('#pass').val() != '' || this.value != '')) {
					$(this).addClass('aviso');
					$(this).prevAll('label').addClass('aviso');
				}
			//}
		}

		if (this.id == 'pass') {
			var elemento = $(this).parents('li:first');
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			$(this).next('span.comentario').remove();
			if (this.value == '' && $('#mail').val() != '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if ($(this).hasClass('requerido')) {
			var elemento = $(this).parents('li:first');
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			$(this).next('span.comentario').remove();
			if (this.value == '' && $('#mail').val() == '' && $('#pass').val() == '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if (this.id == 'cp') {
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			if ((!/^\d{5}$/.test(this.value) || this.value == '') && $('#mail').val() == '' && $('#pass').val() == '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		//if (this.id == 'poblacion') {
			//$(this).removeClass('aviso');
			//$(this).prevAll('label').removeClass('aviso');
			//if ((!/^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s]+$/.test(this.value) || this.value == '') && $('#mail').val() == '' && $('#pass').val() == '') {
				//$(this).addClass('aviso');
				//$(this).prevAll('label').addClass('aviso');
			//}
		//}
		
		if (this.id == 'nif') {
			var letras = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E', 'T'];
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			if ((!/^\d{8}[A-Z]$/.test(this.value) || this.value == '' || this.value.charAt(8) != letras[(this.value.substring(0, 8))%23]) && $('#mail').val() == '' && $('#pass').val() == '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if (this.id == 'telefono') {
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			if ((!/^\d{9}$/.test(this.value) || this.value == '') && $('#mail').val() == '' && $('#pass').val() == '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if (this.id == 'mailn') {
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			if ((!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(this.value) || this.value == '') && $('#mail').val() == '' && $('#pass').val() == '') {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if (this.id == 'passn2') {
			var elemento = $(this).parents('li:first');
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			$(this).next('span.comentario').remove();
			if (this.value != $('#passn').val() || (this.value == '' && $('#mail').val() == '' && $('#pass').val() == '')) {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
		
		if ($(this).hasClass('requeridoent')) {
			$(this).removeClass('aviso');
			$(this).prevAll('label').removeClass('aviso');
			if (this.value == '' && ($('#nombreent').val() != '' || $('#apellidosent').val() != '' || $('#direccionent').val() != '' || $('#poblacionent').val() != '' || $('#cpent').val() != '' || $('#provinciaent').val() != '' || $('#telefonoent').val() != '')) {
				$(this).addClass('aviso');
				$(this).prevAll('label').addClass('aviso');
			}
		}
									
	});
	
	$('.formped').submit(function () {
		$('.formped :input').trigger('blur');
		var numAvisos = $('.aviso', this).length;
		$('#aviso-global').remove();
		if (numAvisos) {
			var listaCampos = [];
			$('label.aviso').each(function () {
				listaCampos.push($(this).attr('title'));
			});
			if (numAvisos == 1) {
				var mensajeAviso = 'El campo <strong>' + listaCampos + '</strong> no ha sido rellenado correctamente. Por favor, complételo.';
			} else {
				var mensajeAviso = 'Los campos <strong>' + listaCampos.join('</strong>, <strong>') + '</strong> no han sido rellenados correctamente. Por favor, complételos.';
			}
			$('<div></div>')
				.attr({
					'id': 'aviso-global',
					'class': 'aviexcl'
				})
				.append(mensajeAviso)
				.hide()
				.insertBefore('#enviar')
				.fadeIn('fast');
			return false;
		}
	});
	
});

// efectos menu logos patronato
jQuery(function($) {
	// nos aseguramos de no aplicar el efecto a versiones de ie que no soporten este código
	if ($.browser.msie && $.browser.version < 7) return;
		
	$('#logos')
		.removeClass('efecto')
		.find('a')
		.append('<span class="hover" />').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
	});
		
	$('#logos li').hover(function () {
		// on hover
		$(this).find('span.hover:first').stop().fadeTo('fast', 1);
	}, function () {
		// off hover
		$(this).find('span.hover:first').stop().fadeTo('fast', 0);
	});

	$('#logos li ul').css('left', 0)
	.not('.selec').hide();
	$('#logos li').hover(function() {
		$(this).find('ul').not('.selec').stop().fadeTo('fast', 1);
	}, function () {

		var obj = $(this).find('ul').not('.selec');
		//setTimeout(function(){
			obj.stop();
			obj.fadeTo('slow', 0, function() {
				// oculto elemento para que no aparezca hasta pasar sobre el botón
				$(this).hide();
			});
	}); 
	
});
