// remap jQuery to $
(function($){})(window.jQuery);


$(document).ready(function(){$("input:text, textarea, input:password").each(function(){if(this.value=='')this.value=this.title;});$("input:text, textarea, input:password").focus(function(){if(this.value==this.title)this.value='';});$("input:text, textarea, input:password").blur(function(){if(this.value=='')this.value=this.title;});$("input:image, input:button, input:submit").click(function(){$(this.form.elements).each(function(){if(this.type=='text'||this.type=='textarea'||this.type=='password'){if(this.value==this.title&&this.title!=''){this.value='';}}});});});

/* trigger when page is ready */
$(document).ready(function (){
	
	
	
	// contact form
	$('#submit-form-contact').click(function(e){
		
		e.preventDefault();
		
		var send = true;
		var nombre = $('#nombre').val();
		var email = $('#email').val();
		var domicilio = $('#domicilio').val();
		var telefono = $('#telefono').val();
		var producto = 1;//$('#producto').val();
		var mensaje = $('#mensaje').val();
		
		//ajax data
		var data = $('.form-contact').serialize();
		
		//validation
		if(nombre == "" || email == "" || mensaje == "" || domicilio == "" || telefono == "" || producto == 0)
		{
			send = false;
			alert('Verifica que los campos no se encuentren vacíos.');
		}else if( ! /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/.test(email))
		{
			alert('Ingresa el Email correctamente.');
			send = false;
		}
		
		if(send)
		{
			$.ajax({
				url : '_/includes/send_mail.php',
				data:  data,
				dataType: 'text',
				type : 'post',
				success: function(response){
					alert("Mensaje enviado correctamente.");
				},
				error: function (){
					alert('El servidor no responde... intenta de nuevo.');
				}
			});
		}
		else
		{
			if(mensaje == "")
			{
				$('#mensaje').val("Mensaje");
			}
		}
		
	});
	
	
	// Newsletter form
	$('#submit_newsletter').click(function(e){
		
		e.preventDefault();
		
		var send = true;
		var newsletter = $('#newsletter').val();
		var data = "email="+newsletter;
		
		if( ! /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/.test(newsletter))
		{
			alert('Ingresa el Email correctamente.');
			send = false;
		}
		
		
		
		if(send)
		{
			$.ajax({
				url : '_/includes/send_newsletter.php',
				data:  data,
				dataType: 'text',
				type : 'post',
				success: function(response){
					alert('Registrado correctamente.');
					if(parseInt(response) == 1)
					{
						$('#newsletter').val("Escribe tu Correo Electrónico");
					}
				},
				error: function (){
					alert('El servidor no responde... intenta de nuevo.');
				}
			});
			
		}
		else
		{
			if(newsletter == "")
			{
				$('#newsletter').val("Escribe tu Correo Electrónico");
			}
		}
	});
	
	//slider
	$('#slider').cycle({ 
		fx:    'fade', 
		pause:  1
	});
	
	//slider
	$('.micro-slider').cycle({ 
		fx:    'fade', 
		//pause:  1,
		slideResize  : 0
	});
	
	
	
	//Carousel
	jQuery('#carrousel-home').jcarousel({
        // Configuration goes here
        visible : 4,
        vertical: false,
        auto: 8,
		wrap		: 'both'
    });
	
	//Carousel
	jQuery('#carrousel-soluciones').jcarousel({
        // Configuration goes here
        visible : 4,
        vertical: false,
        auto: 8,
        wrap		: 'both'
    });
	
	//Carousel
	jQuery('#carrousel-productos').jcarousel({
        // Configuration goes here
        visible : 4,
        vertical: false,
        auto: 8,
        wrap		: 'both'
    });
    
    $('#products_services').change(function(){
		
		var value	= parseInt($(this).val());
		var page	= "";
		
		if(value > 0)
		{
			switch(value)
			{
				case 1: page = "http://gemlogistica.com"; break;
				case 2: page = "http://gemcodigobarras.com"; break;
				case 3: page = "http://gemtecnologia.com"; break;
				case 4: page = "http://gemservicio.com"; break;
				case 5: page = "http://gemetiquetas.com"; break;
				case 999: page = "http://www.gemlogistica.com/"; break;
			}
			
			window.location = page;
		}
		
	});
	
});


/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/

