// JavaScript Document

jQuery(document).ready(function() {
								
								
	jQuery('a').click(function(event) {
								  
								  
			
		if (jQuery(this).attr("title") == "pdf") {
			
		event.preventDefault();
			
		var enlace = jQuery(this).attr("href");
		
		var texto = '<iframe src="http://docs.google.com/viewer?url='+enlace+'&amp;embedded=true" width="550px" height="700px" style="border: none;"></iframe>';
		var imagen = false;
		
		popup(texto, imagen);
		
		jQuery('html, body').animate({scrollTop: 0}, 500);
		}
		
		if (jQuery(this).attr("title") == "video") {
			
		event.preventDefault();
			
		var enlace = jQuery(this).attr("href");		
		
		var texto = '<div style="margin: -20px 0 0 -20px"><iframe width="600" height="365" src="'+enlace+'" frameborder="0" allowfullscreen></iframe></div>';
		var imagen = false;	
		
		popup(texto, imagen);			
		jQuery('html, body').animate({scrollTop: 0}, 500);
		
		
		}
		
								  
	});
								
								
	jQuery(document).click(function() {
									
		var valor = jQuery('.widget_search #s').val();	
		var valor_news = jQuery('#mail_newsletter').val();	
		if (!valor) {			
			jQuery('.widget_search #s').val("Buscador");	
		}	
		if (!valor_news) {
			jQuery('#mail_newsletter').val("Introduce tu email y te mantenemos informado");				
		}
									
	});								
						   
						   
	jQuery('.widget_search #s').click(function(event) {
										
		event.stopPropagation();					
		var valor = jQuery(this).val();		
		if (valor == "Buscador") {
			jQuery(this).val("");	
		}								   
											   
	 });
	
	
	jQuery('#mail_newsletter').click(function(event) {
										
		event.stopPropagation();					
		var valor = jQuery(this).val();		
		if (valor == "Introduce tu email y te mantenemos informado") {
			jQuery(this).val("");	
		}	
		
		if (valor == "Introduce tu email...") {
			jQuery(this).val("");	
		}
											   
	 });	
	
	
	jQuery('.mod_scouts a').hover(
								  
		function(event) {
			
			jQuery('.mod_scouts a img').removeClass("activo");
			jQuery('img', this).addClass("activo");
			
			jQuery('.mod_scouts a img:not(.activo)').css("opacity", 0.4);
			jQuery('img', this).css("opacity", 1);
			event.stopPropagation();
			
		},
		
		function() {
			
			
		}
		
	);
	
	jQuery('.mod_scouts').hover(
		function() {
		
			
			
		},
		
		function() {
		jQuery('.mod_scouts a img:not(.activo)').animate({"opacity": 1}, 300);	
		});
	
	
	jQuery(".mod_newsletter button").click(function(event) {
													
event.preventDefault();
								
													});
					   
});




function popup(texto, image) {
	
	jQuery('.popup_opacity').css({"opacity": 0.4, "height" : jQuery(document).height()});
	
	
	jQuery('.popup_opacity').fadeIn("fast", function() { 
													 
				
				jQuery('.popup_box').fadeIn(500, function() {    
														  
				if (image == false) {
				
				jQuery('.popup_box .contenido').css({"width":"560px"});
				jQuery('.popup_box .contenido').html(texto);				
				}
				else {
				jQuery('.popup_box .contenido').css({"padding":0});
				jQuery('.popup_box .contenido').html("<img src="+texto+" />");	
					
				}
				
				
				
				});
	
	
	});
	
	
	jQuery('.popup_box .cerrar').click(function() {
													
		jQuery('.popup_opacity').fadeOut("fast");
		jQuery('.popup_box').fadeOut("fast");
		
	});
	
	
}


/*** Validar Email ***/


function validar_email(email_address) {
	

	email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;           
	if(!email_regex.test(email_address)){
		valid = false;     
		jQuery('.mod_newsletter .error').text("El email escrito es inválido");
	}else{
		  
	   jQuery.ajax({
	   type: "POST",
	   url: "http://"+document.domain+"/NL-process.php",
	   data: "email="+email_address,
	   success: function(msg){
			
			var imagen = false;
			popup(msg,imagen);
			
	   }
	 });
		
	
	}

}
