/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

// Speed of the automatic slideshow
var slideshowSpeed = 6000;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
		"title" : "Produção de Vídeo",
		"image" : "1.jpg",
		"url" : "?p=portfolio&e=1",
		"firstline" : "Você está pronto para inovar?",
		"secondline" : "Consulte o Grupo RS em seu próximo projeto!<br>Produção de filmes publicitários, vídeos institucionais e treinamentos,<br>documentários, gravação de shows, programas de TV  e campanhas políticas.<br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "Sites e Sistemas",
		"image" : "2.jpg",
		"url" : "?p=portfolio&e=2",
		"firstline" : "Parceria em projetos On-Line",
		"secondline" : "Além de produzir sites inteligentes e lojas virtuais, a RS Site quer <br>entender o seu projeto para aprimorar o desempenho e conseqüentemente <br>atingir os resultados almejados. <br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "Som e Equipamento",
		"image" : "3.jpg",
		"url" : "?p=portfolio&e=3",
		"firstline" : "Aluguel de equipamento de som <br>e iluminação profissional",
		"secondline" : "Equipamentos de pequeno, médio e grande porte que atende empresas, prefeituras e músicos <br>em eventos que exigem alta qualidade de sonorização e iluminação.  <br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "A escrita da luz ",
		"image" : "4.jpg",
		"url" : "?p=portfolio&e=4",
		"firstline" : "A escrita da luz",
		"secondline" : "Registre com arte seu evento. A fotografia é a arte do milésimo de segundo com <br>que é capturada a imagem. De maneira funcional nos apresentamos em eventos<br> corporativos e sociais.<br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "Análise e pesquisa	",
		"image" : "5.jpg",
		"url" : "?p=portfolio&e=5",
		"firstline" : "Acerte no alvo!",
		"secondline" : "Os publicitários sabem que toda a campanha de comunicação começa<br> pela pesquisa de mercado. A pesquisa não acha e não é subjetiva  e sim  uma ciência <br>que acerta as perguntas que a empresa sempre quis saber,<br> reorganiza e age de acordo com as tendências reveladas por ela.<br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "OutDoor",
		"image" : "6.jpg",
		"url" : "?p=portfolio&e=6",
		"firstline" : "OUTDOOR",
		"secondline" : "O Grupo RS possui placas de outdoor na região de Franca-SP,<BR> consulte um de nossos representantes para orientar a<BR> escolha dos pontos mediante ao público-alvo e tráfego desejado. <br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "Produção de Áudio",
		"image" : "7.jpg",
		"url" : "?p=portfolio&e=7",
		"firstline" : "Gravação jingles, spots e músicas",
		"secondline" : "Para a empresa não há forma melhor de se posicionar uma marca na mente dos <br>consumidores do que o jingle. Para o músico não há maneira melhor <br>de ver sua obra concretizada em arquivos de áudio.<br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>"
	}, {
		"title" : "TV Corporativa",
		"image" : "9.jpg",
		"url" : "?p=portfolio&e=8",
		"firstline" : "TV Corporativa",
		"secondline" : "Com a TV Corporativa, sua empresa pode ter uma rede de TV Privada Exclusiva,<BR> um novo canal de comunicação para estreitar o relacionamento entre empresa,<BR> funcionários, fornecedores e clientes.<br>&nbsp;<br><b Style='color:#ffcc00'>[ + Veja Portfólio ]</b>	"
	}
];



$(document).ready(function() {
	
	// Backwards navigation
	$("#back").click(function() {
		stopAnimation();
		navigate("back");
	});
	
	// Forward navigation
	$("#next").click(function() {
		stopAnimation();
		navigate("next");
	});
	

	// Backwards navigation
	$("#1").mouseover(function() {
	    stopAnimation();
		navigate("1");
	});

    // Backwards navigation
	$("#2").mouseover(function() {
	    stopAnimation();
		navigate("2");
	});

	// Backwards navigation
	$("#3").mouseover(function() {
	    stopAnimation();
		navigate("3");
	});

	// Backwards navigation
	$("#4").mouseover(function() {
	    stopAnimation();
		navigate("4");
	});

	// Backwards navigation
	$("#5").mouseover(function() {
	    stopAnimation();
		navigate("5");
	});

	// Backwards navigation
	$("#6").mouseover(function() {
	    stopAnimation();
		navigate("6");
	});

	// Backwards navigation
	$("#7").mouseover(function() {
	    stopAnimation();
		navigate("7");
	});
	
	// Backwards navigation
	$("#8").mouseover(function() {
	    stopAnimation();
		navigate("8");
	});

	
	var interval;
	$("#control").toggle(function(){
		stopAnimation();
	}, function() {
		// Change the background image to "pause"
		$(this).css({ "background-image" : "url(images/btn_pause.png)" });
		
		// Show the next image
		navigate("next");
		
		// Start playing the animation
		interval = setInterval(function() {
			navigate("next");
		}, slideshowSpeed);
	});
	
	
	var activeContainer = 1;	
	var currentImg = 0;
	var animating = false;
	var navigate = function(direction) {
		// Check if no animation is running. If it is, prevent the action
		if(animating) {
			return;
		}
		
		

		// Check which current image we need to show
		if(direction == "next") {
			currentImg++;
			if(currentImg == photos.length + 1) {
				currentImg = 1;
			
			}
		} else if (direction == "back")
		{ currentImg--;
			if(currentImg == 0) {
				currentImg = photos.length;
		}} else {
			//currentImg--;
			currentImg = direction;
			
		}
        
		for (ct = 1; ct<9; ct++)
		{ if (ct == currentImg)
		{$("#"+ct).css({ "background-image" : "url(images/menus/"+ct+"on.png)" }); }
		  else{$("#"+ct).css({ "background-image" : "url(images/menus/"+ct+"off.png)" });}
		}
		
				//alert("url(images/menus/"+currentImg+"on.png)");
		
		// Check which container we need to use
		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;
		
		// Make sure the new container is always on the background
		currentZindex--;
		
		// Set the background image of the new active container
		$("#headerimg" + activeContainer).css({
			"background-image" : "url(images/" + photoObject.image + ")",
			"display" : "block",
			"z-index" : currentZindex
		});
		
		// Hide the header text
		$("#headertxt").css({"display" : "none"});
		
		// Set the new header text
		$("#firstline").html(photoObject.firstline);
		$("#secondline")
			.attr("href", photoObject.url)
			.html(photoObject.secondline);
		$("#pictureduri")
			.attr("href", photoObject.url)
			.html(photoObject.title);
		
		
		// Fade out the current container
		// and display the header text when animation is complete
		$("#headerimg" + currentContainer).fadeOut(function() {
			setTimeout(function() {
				$("#headertxt").css({"display" : "block"});
				animating = false;
			}, 500);
		});
	};
	
	var stopAnimation = function() {
		// Change the background image to "play"
		$("#control").css({ "background-image" : "url(images/btn_play.png)" });
		
		// Clear the interval
		clearInterval(interval);
	};
	
	// We should statically set the first image
	navigate("next");
	
	// Start playing the animation
	interval = setInterval(function() {
		navigate("next");
	}, slideshowSpeed);
	
});
