// JavaScript Document
$(document).ready(function()
{
	$("img").preload();
	
	$("#categoria img").preload();
	$("#categoria2 img").preload();
	$("#categoria3 img").preload();
	$("#categoria4 img").preload();
	$("#categoria5 img").preload();
	$("#categoria6 img").preload();
	
	
	$("#categoria").hide();
	$("#categoria2").hide();
	$("#categoria3").hide();
	$("#categoria4").hide();
	$("#categoria5").hide();
	$("#categoria6").hide();
	
	$.fn.fancyzoom.defaultsOptions.imgDir='./js/ressources/';
	
	$('#show').cycle({ 
		fx:    'fade', 
		pause:  1 
	});
	
	$("#loading").hide();
	
	$().ajaxStart(function() { $('#loading').show(); });
  	$().ajaxStop(function() { $('#loading').hide(); });
	
	(function($) {
	  var cache = [];
	  // Arguments are image paths relative to the current page.
	  $.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
		  var cacheImage = document.createElement('img');
		  cacheImage.src = arguments[i];
		  cache.push(cacheImage);
		}
	  }
	})(jQuery)
	
	// CONTATO
	$("#chama_contato").click(function() {
			$('#show').cycle('pause');
			$("#inicio").hide();
			$("#categoria2").hide();
			$("#categoria3").hide();
			$("#categoria4").hide();
			$("#categoria5").hide();
			$("#categoria6").hide();
			$("#categoria").show();
			$("#categoria").load("_contato.php", "opt=", function() {
				$("#categoria").animate({
					opacity: 1.0,
					marginLeft: "10%", 
					marginRight: "10%",
					marginTop: "85px"
				}, 500);
		  });
	});
	
	$("#chama_direita").click(function() {
		// Move para a esquerda
		/* $.ajax({ 
			url: "_contato.php", 
			cache: true,
			success: function(message) 
			{
				$("#categoria").empty().append(message);
			} 
		 });*/
		 $("#inicio").animate({
			 opacity: 0.0,
			 marginLeft: "0%"
			 }, 500, function () { // Chama a div para aparecer pela direita
				$('#show').cycle('pause');
				$("#inicio").hide();
				$("#categoria").show();
		  });
		  $("#categoria").load("_contato.php", "opt=", function() {
				$("#categoria").animate({
					opacity: 1.0,
					marginLeft: "10%", 
					marginRight: "10%",
					marginTop: "85px"
				}, 500);												   
		  });
	});

	$("#volta_direita").click(function() {
		// Move para a direita
		 $("#categoria").animate({
			opacity: 0.0,
			marginRight: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita
			  $("#categoria").hide();
			  $("#inicio").show();
			  $('#show').cycle('resume');
			  $("#inicio").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
		} );
	});	
	
	// IMPRENSA
	$("#chama_imprensa").click(function() {
			$('#show').cycle('pause');
			$("#inicio").hide();
			$("#categoria").hide();
			$("#categoria3").hide();
			$("#categoria4").hide();
			$("#categoria5").hide();
			$("#categoria6").hide();
			$("#categoria2").show();
			$("#conteudo_imprensa").load("_imprensa.php", "opt=", function() {
				$("#categoria2").animate({
					opacity: 1.0,
					marginLeft: "10%", 
					marginRight: "10%",
					marginTop: "85px"
				}, 500);
			});
	});
	
	$("#chama_topodireita").click(function() {
		// Move para a esquerda pra baixo
		 $("#inicio").animate({
					/*opacity: 0,
					filter: "alpha(opacity=0)",
					marginLeft: "0%",
					marginRight: "50%",
					marginTop: "50%"*/
					opacity: 0.0,
			 		marginLeft: "0%"
				  }, 500, function () { // Chama a div para aparecer pela direita por cima
					  $('#show').cycle('pause');
					  $("#inicio").hide();
					  $("#categoria2").show();
					  $("#conteudo_imprensa").load("_imprensa.php", "opt=", function() {
						  $("#categoria2").animate({
							  opacity: 1.0,
						      marginLeft: "10%", 
					          marginRight: "10%",
					          marginTop: "85px"
						  }, 500);
					  });
				});
	});	
	
	$("#volta_topodireita").click(function() {
		// Move para a esquerda
		 $("#categoria2").animate({
			/*opacity: 0.0,
			marginTop: "0%",
			marginLeft: "90%"*/
			opacity: 0.0,
			marginRight: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita
			  $("#categoria2").hide();
			  $("#inicio").show();
			  $('#show').cycle('resume');
			  $("#inicio").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
		} );
	});	
	
	// CHOCOLATE É...
	$("#chama_chocolate").click(function() {
			$('#show').cycle('pause');
			$("#inicio").hide();
			$("#categoria").hide();
			$("#categoria2").hide();
			$("#categoria4").hide();
			$("#categoria5").hide();
			$("#categoria6").hide();
			$("#categoria3").show();
			$("#conteudo_chocolate").load("_chocolate.php", "opt=1", function() {
				$("#categoria3").animate({
					opacity: 1.0,
					marginLeft: "10%", 
					marginRight: "10%",
					marginTop: "85px"
				}, 500);
				$('#show_chocolate').cycle({ 
					fx:     'fade',
					pause:  2
				});
		  });
	});
	
	$("#chama_esquerda").click(function() {
		// Move para a esquerda
		 $("#inicio").animate({
			opacity: 0.0,
			marginRight: "0%"
		  }, 500, function () { // Chama a div para aparecer pela esquerda
			  $('#show').cycle('pause');
			  $("#inicio").hide();
			  $("#categoria3").show();
			  $("#conteudo_chocolate").load("_chocolate.php", "opt=1", function() {
				  $("#categoria3").animate({
					  opacity: 1.0,
					  marginLeft: "10%", 
					  marginRight: "10%",
					  marginTop: "85px"
				  }, 500);
				  $('#show_chocolate').cycle({ 
					fx:     'fade',
					pause:  2
				  });
			   });
		});
	});
	
	$("#chocolate_1").click(function() {
		//$("#loading").show();
		$("#conteudo_chocolate").html('');
		$("#conteudo_chocolate").load("_chocolate.php","opt=1");//, function() { $('#conteudo_chocolate').jScrollPane(); });
		//$("#loading").hide();
	});
	
	$("#chocolate_2").click(function() {
		//$("#loading").show();
		$("#conteudo_chocolate").html('');
		$("#conteudo_chocolate").load("_chocolate.php","opt=2");//, function() { $('#conteudo_chocolate').jScrollPane(); });
		//$("#loading").hide();
	});
	
	$("#volta_esquerda").click(function() {
		// Move para a esquerda
		 $('#show_chocolate').cycle('stop');
		 $("#categoria3").animate({
			opacity: 0.0,
			marginLeft: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita
			  $("#categoria3").hide();
			  $("#inicio").show();
			  $('#show').cycle('resume');
			  $("#inicio").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
		} );
	});	
	
	// EMPRESA
	$("#chama_empresa").click(function() {
			$('#show').cycle('pause');
			$("#inicio").hide();
			$("#categoria").hide();
			$("#categoria2").hide();
			$("#categoria3").hide();
			$("#categoria5").hide();
			$("#categoria6").hide();
			$("#categoria4").show();
			$("#conteudo_empresa").load("_empresa.php", "opt=", function() {
				$("#categoria4").animate({
					opacity: 1.0,
					marginLeft: "10%", 
					marginRight: "10%",
					marginTop: "85px"
				}, 500);
		  });
	});
	
	$("#chama_topoesquerda").click(function() {
		// Move para a esquerda pra baixo
		  $("#inicio").animate({
					/*opacity: 0.0,
					marginTop: "500px",
					marginLeft: "500px"*/
					opacity: 0.0,
					marginRight: "0%"
				  }, 500, function () { // Chama a div para aparecer pela direita por cima
					  $('#show').cycle('pause');
					  $("#inicio").hide();
					  $("#categoria4").show();
					  $("#conteudo_empresa").load("_empresa.php", "opt=", function(){
						  $("#categoria4").animate({
							  opacity: 1.0,
							  marginLeft: "10%", 
							  marginRight: "10%",
							  marginTop: "85px"
						  }, 500);
			      });
		  });
	});	
	
	$("#volta_topoesquerda").click(function() {
		// Move para a esquerda
		 //$("#loading").show();
		 $("#categoria4").animate({
			/*opacity: 0.0,
			marginTop: "-500px",
			marginLeft: "-500px"*/
			opacity: 0.0,
			marginLeft: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita
			  $("#categoria4").hide();
			  $("#inicio").show();
			  $('#show').cycle('resume');
			  $("#inicio").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
		} );
	});	
	
	// NOSSOS CHOCOLATES
	$("#chama_nossos").click(function() {
			$('#show').cycle('pause');
			$("#inicio").hide();
			$("#categoria").hide();
			$("#categoria2").hide();
			$("#categoria3").hide();
			$("#categoria4").hide();
			$("#categoria6").hide();
			$("#categoria5").show();
			$("#conteudo_nossos").load("_nossos.php", "opt=1", function() {
				$("#categoria5").animate({
					opacity: 1.0,
					marginLeft: "10%", 
					marginRight: "10%",
					marginTop: "85px"
				}, 500);
		  });
			
	});
	
	$("#nossos_1").click(function() {
		//$("#loading").show();
		$("#conteudo_nossos").html('');
		$("#conteudo_nossos").load("_nossos.php","opt=2");//, function() { $('#conteudo_nossos').jScrollPane(); });
		//$("#loading").hide();
	});
	
	$("#nossos_2").click(function() {
		//$("#loading").show();
		$("#conteudo_nossos").html('');
		$("#conteudo_nossos").load("_nossos.php","opt=3");//, function() { $('#conteudo_nossos').jScrollPane(); });
		//$("#loading").hide();
	});
	
	$("#nossos_3").click(function() {
		//$("#loading").show();
		$("#conteudo_nossos").html('');
		$("#conteudo_nossos").load("_nossos.php","opt=4");//, function() { $('#conteudo_nossos').jScrollPane(); });
		//$("#loading").hide();
	});
	
	$("#nossos_4").click(function() {
		//$("#loading").show();
		$("#conteudo_nossos").html('');
		$("#conteudo_nossos").load("_nossos.php","opt=5");//, function() { $('#conteudo_nossos').jScrollPane(); });
		//$("#loading").hide();
	});
	
	$("#chama_rodapeesquerda").click(function() {
		// Move para a esquerda pra baixo
		 $("#inicio").animate({
			/*opacity: 0.0,
			marginTop: "-500px",
			marginLeft: "500px"*/
			opacity: 0.0,
			marginRight: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita por cima
			  $('#show').cycle('pause');
			  $("#inicio").hide();
			  $("#categoria5").show();
			  $("#conteudo_nossos").load("_nossos.php", "opt=1", function() {
				  $("#categoria5").animate({
					  opacity: 1.0,
					  marginLeft: "10%", 
					  marginRight: "10%",
					  marginTop: "85px"
				  }, 500);
			  });
		});
	});	
	
	$("#volta_rodapeesquerda").click(function() {
		// Move para a esquerda
		 $("#show_chocolate1").cycle('stop');
	     $("#show_chocolate2").cycle('stop');
	     $("#show_chocolate3").cycle('stop');
	     $("#show_chocolate4").cycle('stop');
		 $("#show_chocolate1").html('');
	     $("#show_chocolate2").html('');
	     $("#show_chocolate3").html('');
	     $("#show_chocolate4").html('');
		 $("#legenda_chocolate").html('');
		 $("#categoria5").animate({
			/*opacity: 0.0,
			marginTop: "500px",
			marginLeft: "-500px"*/
			opacity: 0.0,
			marginLeft: "0%"
		  }, 600, function () { // Chama a div para aparecer pela direita
			  $("#categoria5").hide();
			  $("#inicio").show();
			  $('#show').cycle('resume');
			  $("#inicio").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
		} );
	});	
	
	function URLencode(sStr) {
    return escape(sStr).
             replace(/\+/g, '%2B').
                replace(/\"/g,'%22').
                   replace(/\'/g, '%27').
                     replace(/\//g,'%2F');
	}
	
	function onAfterCollection()
	{
		$("#conteudo_colecoes").load("_colecoes.php" , "opt=" + URLencode(this.alt));//, function() { $('#conteudo_colecoes').jScrollPane(); });
	}
	
	// NOSSAS COLECOES
	$("#chama_colecoes").click(function() {
			$('#show').cycle('pause');
			$("#inicio").hide();
			$("#categoria").hide();
			$("#categoria2").hide();
			$("#categoria3").hide();
			$("#categoria4").hide();
			$("#categoria5").hide();
			$("#categoria6").show();
			$("#categoria6").animate({
			  opacity: 1.0,
			  marginLeft: "10%", 
			  marginRight: "10%",
			  marginTop: "85px"
			  }, 500);
			  $('#show_colecoes').cycle({ 
				fx:     'scrollRight',
				timeout:  0,
				next:   '#next_colecoes',
				after: onAfterCollection
			 });
			 
	});
	
	$("#chama_rodapedireita").click(function() {
		// Move para a esquerda pra baixo
		 $("#inicio").animate({
			/*opacity: 0.0,
			marginTop: "-500px",
			marginLeft: "-500px"*/
			opacity: 0.0,
			marginLeft: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita por cima
			  $('#show').cycle('pause');
			  $("#inicio").hide();
			  $("#categoria6").show();
			  $("#categoria6").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
			  $('#show_colecoes').cycle({ 
				fx:     'scrollRight',
				timeout:  0,
				next:   '#next_colecoes',
				after: onAfterCollection
			 });
		} );
	});
	
	$("#volta_rodapedireita").click(function() {
		// Move para a esquerda
		 $('#show_colecoes').cycle('stop');
		 $("#categoria6").animate({
			/*opacity: 0.0,
			marginTop: "500px",
			marginLeft: "500px"*/
			 opacity: 0.0,
			 marginRight: "0%"
		  }, 500, function () { // Chama a div para aparecer pela direita
			  $("#categoria6").hide();
			  $("#inicio").show();
			  $('#show').cycle('resume');
			  $("#inicio").animate({
			      opacity: 1.0,
				  marginLeft: "10%", 
				  marginRight: "10%",
				  marginTop: "85px"
			  }, 500);
		} );
	});
	
});