$(document).ready(function(){

	$(".promo").colorbox({
		iframe:true,
		innerWidth:674,
		innerHeight: 395
	});
	
	$('.error').hide();
	
	$('#slider').easySlider({
		auto: true,
		continuous: true
	});
	
	/*
	 * Formulario
	 */
	
	$('.enviarReserva').click(function(){
		$('.error').hide();
		
		var valido = true;
		var nombre = $('#nombre').val();
		var apellido = $('#apellido').val();
		var mail = $('#mail').val();
		var telefono = $('#telefono').val();
		var diaIn = $('#diaIn').val();
		var mesIn = $('#mesIn').val();
		var anioIn = $('#anioIn').val();
		var fechaIn = diaIn + '/' + mesIn + '/' + anioIn;
		var diaOut = $('#diaOut').val();
		var mesOut = $('#mesOut').val();
		var anioOut = $('#anioOut').val();
		var fechaOut = diaOut + '/' + mesOut + '/' + anioOut;
		var comentarios = $('#comentarios').val();
		var _comment = $('#_comment').val();
		var _fields = $('#_fields').val();
		
		if (nombre == ""){
			$('#errorNombre').show();
			$('#nombre').css('backgroundColor', '#FFE6D9');
			$('#nombre').focus();
			
			valido = false;
			
			return false;
		}
		
		if (mail == ""){
			$('#errorMail').show();
			$('#mail').css('backgroundColor', '#FFE6D9');
			$('#mail').focus();
			
			valido = false;
			
			return false;
		}
		
		if (telefono == ""){
			$('#errorTelefono').show();
			$('#telefono').css('backgroundColor', '#FFE6D9');
			$('#telefono').focus();
		}
		
		var dataString = 'nombre=' + nombre + '&apellido=' + apellido + '&mail=' + mail + '&telefono=' + telefono + '&fechaIn=' + fechaIn + '&fechaOut=' + fechaOut + '&comentarios=' + comentarios + '&_comment=' + _comment + '&_fields=' + _fields;
		
		$.ajax({
			type: 'GET',
			url: 'proxy.php',
			data: dataString,
			dataType: 'json',
			success: function(msg) {
				if (msg){
					window.location = 'procesa.php?' + dataString;
				} else {
					window.location = 'index.php?envio=0';
				}
			}
		});
		
		return false
	});
});

/*
 * Easy Slider
 */
 
function slideSwitch() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	// use this to pull the images in the order they appear in the markup
	var $next =  $active.next().length ? $active.next()
		: $('#slideshow IMG:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 10000 );
});
