var slideshowSpeed = 10000;

var photos = [ {
		"title" : "",
		"image" : "banner.jpg",
		"url" : "",
		"firstline" : "Inova&ccedil;&atilde;o e tecnologia",
		"secondline" : "Esse &eacute; o nosso neg&oacute;cio."
	}, {
		"title" : "",
		"image" : "banner2.jpg",
		"url" : "",
		"firstline" : "Projetos personalizados",
		"secondline" : "Uni&atilde;o de conhecimentos e compet&ecirc;ncias entre sua empresa e a nossa."
	}, {
		"title" : "",
		"image" : "banner3.jpg",
		"url" : "",
		"firstline" : "Aloca&ccedil;&atilde;o de Profissionais",
		"secondline" : "O Conhecimento Necessário pelo tempo certo e com o m&iacute;nimo esfor&ccedil;o."
	}, {
		"title" : "",
		"image" : "banner4.jpg",
		"url" : "",
		"firstline" : "F&aacute;brica de Codifica&ccedil;&atilde;o e Testes",
		"secondline" : "Tecnologia da informa&ccedil;&atilde;o com base nos conceitos e m&eacute;todos."
	}, {
		"title" : "",
		"image" : "banner5.jpg",
		"url" : "",
		"firstline" : "Licenciamento e Representa&ccedil;&atilde;o",
		"secondline" : "Representante exclusiva no Brasil da empresa Adacel Inc."
	}
];



$(document).ready(function() {
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {

		if(animating) {
			return;
		}

		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			}
		} else {
			currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
			}
		}

		var currentContainer = activeContainer;
		if(activeContainer == 1) {
			activeContainer = 2;
		} else {
			activeContainer = 1;
		}
		
		showImage(photos[currentImg - 1], currentContainer, activeContainer);
		
	};
	
	var currentZindex = -1;
	var showImage = function(photoObject, currentContainer, activeContainer) {
		animating = true;
		

		currentZindex--;

		$("#headerimg" + activeContainer).css({
			"background-image" : "url(images/" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		

		$("#headertxt").css({"display" : "none"});
		

		$("#firstline").html(photoObject.firstline);
		$("#secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
		

		$("#headerimg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				$("#headertxt").css({"display" : "block"});
				animating = false;
			}, 500);
		});
	};
	
	var stopAnimation = function() {

		$("#control").css({ "background-image" : "url(images/btn_play.png)" });
		
		clearInterval(interval);
	};
	

	navigate("next");
	

	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
	
});
