jQuery(document).ready(function($) {
	//Variables globales
	window.animando=false;
	//ACCIONES DE BOTON
	$("#botPrev").click(
		function(){
			if(window.animando == false)
				{
					goPrev()
				}	
			return false;		
			} 
	);
	$("#botNext").click(
		function(){
			//over
				if(window.animando == false)
				{
					goNext()
				}
				return false;	
			}
	);
	//sort

	$(".mascara a").click(evNuestrosClientesClic);
	
	// -----------------
	$("#clientes_botPrev").click (evClientesPrevClic);
	$("#clientes_botNext").click (evClientesNextClic);
	evDocumentReady();
	
	
})

// FUNCIONES NAV HORIZONTAL-----------------------
function goPrev(){
	
	if($('#slide').css("left")!="0px")
	{
		window.animando = true;
		$('#slide').animate({ left : "+=320" }, 1100 , function() { //1500 
			window.animando = false;
		});
	}
	return false;
	
}

function goNext(){
	
	var ancho = $('#slide').css("width");
	var posX = $('#slide').css("left");
	ancho = ancho.toString();
	posX = posX.toString();
	var anchoNu = ancho.replace("px","");
	var posXNu = posX.replace("px","");
	
	// if( (Number(anchoNu)+Number(posXNu))+320 > 0 )
	if( (Number(posXNu)) > -1920 )
	{
	window.animando = true;
	$('#slide').animate({ left : "-=320" }, 1100 , function() { //1500 
		window.animando = false;
	});
	}
	return false;
}

function evNuestrosClientesClic () {
	$("#clientes_imagen").attr ("src", this.href);
	$("#clientes_descripcion").html (this.rel);
	return false;
}


// Slide nuestros clientes.
function evClientesPrevClic () {
	goPrevClientes ();
	return false;
}

function evClientesNextClic () {
	goNextClientes ();
	return false;
}

function goPrevClientes(){
	
	if($('.contanidoMask').css("left")!="0px" && !window.animando)
	{
		window.animando = true;
		$('.contanidoMask').animate({ left : "+=167" }, 1100 , function() { //1500 
			window.animando = false;
		});
	}
	return false;
	
}

function goNextClientes(){
	
	var ancho = $('.contanidoMask').css("width");
	var posX = $('.contanidoMask').css("left");
	ancho = ancho.toString();
	posX = posX.toString();
	var anchoNu = ancho.replace("px","");
	var posXNu = posX.replace("px","");
	
	// if( (Number(anchoNu)+Number(posXNu))+320 > 0 )
	if( (Number(posXNu)) > -167 && !window.animando)
	{
	window.animando = true;
	$('.contanidoMask').animate({ left : "-=167" }, 1100 , function() { //1500 
		window.animando = false;
	});
	}
	return false;
}

/*FORMULARIO ENCUESTA*/

function evDocumentReady () {
 $("#recommend_submit").click ( evLetsTalkSubmitClick );
}

function evLetsTalkSubmitClick () {		
	// name, date_birth, email
	if ( $("#referido_nombre").val () == "" || $("#usuario_nombre").val () == "" ) {
		//
		$("#form_status").html ("<span class='errorform'>Por favor, complete todos los datos.</span>");
		return false;
	} else if ( !isEmail( $("#referido_email").val () ) || !isEmail( $("#usuario_email").val () ) ) {
		//
		$("#form_status").html ("<span class='errorform'>Por favor, complete todos los datos.</span>");
		return false;
	}
	//
	$.post($("#recommend_form").attr ("action"), $("#recommend_form").serialize(), evLetsTalkFormResponse);
	$("#form_status").html ("<span class='okform'>Enviando mensaje...</span>");
	return false;
}

function evLetsTalkFormResponse (_data) {
	if ( _data == "true" ) {
		$("#recommend_form")[0].reset();
		$("#form_status").html ("<span class='okform'>Gracias por recomendarnos. En la brevedad un representante se contactar&aacute; con usted.</span>");
	} else {
		$("#form_status").html ("<span class='errorform'>El mensaje no fue enviado!</span>");
	}
}

function isEmail( _value ) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(_value); 
}


/*----------*/

