/*!
* jQuery estudio crealia
*/

// 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('fast', 0, function() {
			// oculto elemento para que no aparezca hasta pasar sobre el botón
			$(this).hide();
		});
	});
	
});

// 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=galeria]").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=galeria]").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
});

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

//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('imgload');
	if ($('img').attr('complete')) {
		$('img').fadeIn('slow').parent().removeClass('imgload');
	} else {
		$('img').load(function () {
			$(this).fadeIn('slow').parent().removeClass('imgload');
		});
	}
});

/* efectos galería fotografías */
jQuery(function($) {
	$('#galcont img').not('.vacio').hover(function(){
		$(this).stop().fadeTo('slow', 1);
		$("#galcont img").not(this).not('.vacio').stop().fadeTo('slow', 0.2);
	},function(){
		//$(this).fadeTo('slow', 1);
	});
	$("#galcont").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
	});
	
	$("#galcont img.vacio").hover(function(){
		$('.imggal img').not('.vacio').stop().fadeTo("slow", 1);
		$('.imggalnopub img').not('.vacio').stop().fadeTo("slow", 0.2);
	},function(){
		// nada
	});
});

/* 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');
		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 {
				
		}
	});
});
