// JavaScript Document

$(document).ready(function(){
	
	// Menu Hover
	$('.menu-button').hover(function(){
		$(this).addClass('hover');
		$("#menu").slideDown();
	});
	
	$('#menu').mouseleave(function(){
		 $(this).slideUp();
	});
	
	$('.menu-button').click(function(e){
		e.preventDefault();
	});
	
	
	// Home Slide Effects
	
	$('.deploy-button').hover(
		function(){
			$(this).addClass('active');
		},
		function(){
			$(this).removeClass('active');
	});

	$('.deploy-button').toggle(
		function(){
			$(this).parent().siblings().find('.hidden').slideUp(1000);
			$(this).parent().siblings().find('span.icon').removeClass('close');
			$(this).find('span.icon').addClass('close');
			$(this).parent().find('.hidden').slideDown(1000);
			$("html, body").animate({ scrollTop: 550}, 1000 );
		},
		function(){
			$(this).parent().find('.hidden').slideUp(500);
			$(this).find('span.icon').removeClass('close');
	});
	
	
	
	// Popup
	
	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		$('html, body').css('overflow', 'hidden');
		var id = $(this).attr('href');
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});	
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
		var winH = $(window).height();
		var winW = $(window).width();
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);
		$(id).fadeIn(2000); 
	});
	
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('html, body').css('overflow', 'auto');
		$('#mask').fadeOut(800);
		$('.window').hide();
		
	});		
	
	$('#mask').click(function () {
		$('html, body').css('overflow', 'auto');					   
		$(this).fadeOut(800);
		$('.window').hide();
	});		
	
	// End Popup
	
	
	// Contact page validate
	
	$("#contact-form").submit(function() {
		
			$("#msgbox").removeClass().addClass('messagebox').text('Validando....').fadeIn(1000);
		
			$.post("scripts/validate.php",{ 
				   name:$('#name').val(),
				   company:$('#company').val(),
				   email:$('#email').val(),
				   phone:$('#phone').val(),
				   city:$('#city').val(),
				   country:$('#country').val(),
				   comments:$('#comments').val(),
				   rand:Math.random() } ,function(data){
			  
			  if(data=='yes'){
				  
					$("#msgbox").fadeTo(200,0.1,function(){ 
				
					  $(this).html('Enviando e-mail....').addClass('messageboxok').fadeTo(900,1,
					  
					  function(){ 

							$('#success').fadeIn().delay(5000).fadeOut();
						 
					  });
					  
					  $(this).fadeOut()
				  
				});
			  }
			  
			  if(data=='no'){
				  
					$("#msgbox").fadeTo(200,0.1,function(){ 
				
					  $(this).html('Validando...').addClass('messageboxok').fadeTo(900,1,
					  
					  function(){ 

							$('#error-send').fadeIn().delay(5000).fadeOut();
						 
					  });
					  
					  $(this).fadeOut()
				  
				});
			  }
			  
			  if(data=='error2'){
				  
					$("#msgbox").fadeTo(200,0.1,function(){ 
				
					  $(this).html('El formato del email no es v&aacute;lido').addClass('messageboxerror').fadeTo(900,1);
					  
					});	
			  }
			  
			  if(data=='error1'){
				  
					$("#msgbox").fadeTo(200,0.1,function(){ 
				
					  $(this).html('Por favor complete los campos obligatorios').addClass('messageboxerror').fadeTo(900,1);
					  
					});	
			  }

					
			});
			
			return false; 
				
		});
	
	// End page validate
	
	

});
