
var c = new Rotation("mostraBoxCases","boxCasesTodos",8000);
c.start();
var servicos = new Rotation("mostraBoxServicos","boxServicosTodos",6500);
servicos.start();

var lista = [ 		
"imgs/headerAereoporto.jpg",
"imgs/headerAssinatura.jpg", 
"imgs/headerBandeiras.jpg", 
"imgs/headerPalestra.jpg", 
"imgs/headerPraia.jpg", 
"imgs/headerTeclado.jpg",
"imgs/headerSuitcase.jpg",
"imgs/headerMundo.jpg"
];

var pause = 5000;
function imageTransition(id, time, index) {

	if (index == null) {
		index = 0;
		$("#" + id + " img:first").attr("src", lista[0]);
		$("#" + id + " img:first").css("z-index", 300);
	}
	if (index >= lista.length)
		index = 0;

	$("#" + id + " img:first").attr("src",
			$("#" + id + " img:last").attr("src"));
	$("#" + id + " img:last").attr("src", lista[index]);

	$("#" + id).attr("src", lista[index]);
	fadeEffect(id);

	setTimeout("imageTransition('" + id + "'," + time + "," + (++index) + ")",
			time);
}

function fadeEffect(id, op) {
	if (op == null)
		op = 0
	$("#" + id + " img:last").css("opacity", op / 100);
	$("#" + id + " img:first").css("opacity", 1 - (op / 100));

	if (op >= 100)
		return;
	setTimeout("fadeEffect('" + id + "'," + (op + 10) + ")", 100);
}

function initImageTransition() {
	imageTransition("fadeLogo", pause);
}
setTimeout("initImageTransition()", pause * 1.5);

function Rotation(id, idR, time) {
	if (time == null || time < 1000)
		time = 1000;
	var id = id;
	var idR = idR;
	var time = time;
	var s;
	var interval;
	this.start = function() {
		if (this.startated)
			return;

		this.s = true;

		reload(time);
	}
	var reload = function(time) {
		interval = setInterval( function() {
			animation();
		}, time);
	}
	var animation = function() {
		var w = $("#" + id).width();
		var r = $("#" + idR);
		var p = 0;
		var objInter = setInterval( function() {
			p = p - 10;
			r.css("left", p + "px");

			if (p <= -w) {
				clearInterval(objInter);
				var div = $(r).children().eq(0);
				r.append(div);
				r.css("left", "0px");
				return;
			}
		}, 10);
	}
	this.stop = function() {

		this.s = false;
		clearInterval(interval);
	}
	this.next = function() {
		var t = false;
		if (this.s) {
			this.stop();
			t = true;
		}
		animation();
		if (t)
			this.start();
	}
	this.preview = function() {
		var t = false;
		if (this.s) {
			this.stop();
			t = true;
		}
		var w = $("#" + id).width();
		var r = $("#" + idR);
		var p = -w;
		var size = $(r).children().size();
		var div = $(r).children().eq(size - 1);
		r.prepend(div);
		r.css("left", "-" + w + "px");

		var objInter = setInterval( function() {
			r.css("left", p + "px");

			if (p >= 0) {
				clearInterval(objInter);
				return;
			}
			p = p + 10;
		}, 10);
		if (t)
			this.start();
	}
}

function validationContatos(){
	
	var  errors = false;
	var emailInvalid = false;
	var form = document.getElementById("contato");
	clearErrorLabels(form);
	clearErrorMessages(form);

	if(v(form.elements['Nome']))
		errors = true;

	var field = form.elements['EmailFrom'];	
	if(	v(field))
		errors = true;
	if(validationEmail(field))
	    emailInvalid = true;	
	if(v(form.elements['TelefoneFax']))
		errors = true;
	if(	v(form.elements['Pais']))
		errors = true;
	if(	v(form.elements['Cidade']))
		errors = true;
	if(v(form.elements['Assunto']))
		errors = true;
	if(v(form.elements['Mensagem']))
		errors = true;

	if(errors)
		addErrorMessages(form,"Preencha os campos destacados abaixo.");

	if(emailInvalid)
		addErrorMessages(form,"Email inválido.");
	return !errors && !emailInvalid;
}

function validationEmail(field){
	if (field.value != null && field.value.length > 0 && field.value.match(/\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/gi)==null){
		addError(field);
		return true;
	}
	return false;
}

function clearErrorLabels(form){
	$(form).find(".campoObrigatorio").removeClass("campoObrigatorio");
}

function clearErrorMessages(form){
	var errorMessages = $(form).find("#errorMessages");	
	errorMessages.css("display","none");
	errorMessages.html("");	
}

function addErrorMessages(form,error){
	var errorMessages = $(form).find("#errorMessages");
		errorMessages.append(error+"<br />");	
		errorMessages.css("display","block");
}


function v(field){
	if (field.value != null && (field.value == "" || field.value.replace(/^\s+|\s+$/g,"").length == 0)) {
        addError(field);
        return true;
    }
    return false;
}


function addError(field){
	$(field).parent().addClass("campoObrigatorio");
}

$(document).ready(function() {
	
	   $(".aBox").click(function() {
		   var sel = this;
			$(".aBox").each(function(){
					
				if(sel == this){
					$(this).addClass("desabilitado");
					 $(this).parent().find(".escondeCurriculo").slideDown(4000);
				}
				else{
					$(this).removeClass("desabilitado");
					 $(this).parent().find(".escondeCurriculo").slideUp(4000);
				}
				
				});
	   });

	  
	 });


