/*
  Funciones Generales seccion Latinoamerica
*/
var $j = jQuery.noConflict();

/*
   Function Anonima
   Inicia los eventos asociados a los selectores cuando se carga el archivo
*/
$j(function($) {
	$('#mexico a').click(function(){
		$('#mexico_menu').fadeToggle('slow');
		return false;
	}); // end click mexico_menu
	$('#distribucion a').click(function(){
		$('#dist_menu').fadeToggle('slow');
		return false;
	}); // end click dist_menu
}); // end function

/*
    Function fadeToggle
    Permite que el efecto fade se comporte como toggle

    Parameters:
	speed - Duracion del efecto
	easing
	callback - Funcion a ejecutar cuando se termine el efecto

    Return:
	Void
*/
jQuery.fn.fadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle'}, speed, easing, callback);
}

jQuery(document).ready(function(){
	 
	
	jQuery('.plantasLight').click(function(){
		var link = jQuery(this);
		var divLight = jQuery('#lightPlantas');
		jQuery.ajax({
			url : link.attr('href'),
			success : function(html){
				divLight.html(html);
				jQuery('#backLightNuest').fadeIn();
				divLight.fadeIn();
				jQuery('#plantasButtons').fadeIn();
				jQuery('#backPlantas').fadeOut();
				jQuery('#cvDiv').fadeOut();
			}
		});
		return false;
	});
	
	jQuery('.plantasLightExternas').click(function(){
		var link = jQuery(this);
		var divLight = jQuery('#lightExternas');
		jQuery.ajax({
			url : link.attr('href'),
			success : function(html){
				
				divLight.html(html);
				jQuery('#lightNuest1').fadeIn();
				jQuery('#backLightNuest').fadeIn();
				divLight.fadeIn();
				 jQuery('#carrusel').jcarousel();
				jQuery('#externasButtons').fadeIn();
				jQuery('#backExternas').fadeOut();
			}
		});
		return false;
	});
	jQuery('#closeLight2').click(function(e){
		e.preventDefault();
		closeLightExternas();
		return false;
	});
	jQuery('#backExternas').click(function(e){
		e.preventDefault();
		back(); 
		return false;
	});
	jQuery('#nextExternas').click(function(e){
		e.preventDefault();
		next();
		return false;
	});
	jQuery('#closeLightLinght').click(function(e){
		e.preventDefault();
		closeLightExternas();
		return false;
	});
	jQuery('#backLightNuest').click(function(e){
		e.preventDefault();
		closeLightExternas();
		return false;
	});
	jQuery('#cerrarInfoExternas').click(function(e){
		e.preventDefault();
		closeLightExternas();
	});
	
	jQuery('#boton-mexico').click(function(){
		jQuery('#mexico-menu').fadeIn();
		jQuery('#boton-mexico').addClass('activo');
	});
	
	jQuery('#boton-centros').click(function(){
		jQuery('#dist_menu').fadeIn();
		jQuery('#boton-centros').addClass('activo');
	});
	
	jQuery('#boton-centros.activo').click(function(){
		jQuery('#dist_menu').fadeOut();
		jQuery('#boton-centros').removeClass('activo');
	});
	
	function closeLightExternas(){
		var divLight = jQuery('#lightExternas');
		jQuery('#mexico-menu').fadeOut();
		jQuery('#dist_menu').fadeOut();
		jQuery('#lightNuest1').fadeOut();
		jQuery('#backLightNuest').fadeOut();
		divLight.fadeOut().empty();
		jQuery('#externasButtons').fadeOut();
		jQuery('#backExternas').fadeOut();	
	}
});

