// arquivo: javascript.js

$(document).ready(function(){
	
	$(function() {$('a[rel*=external]').click( function() {window.open(this.href);return false;});});

	if ($('#menuexterno').length > 0) {
		jQuery(function(){jQuery('ul.sf-menu').superfish();});
	}
	
	$("#linguagem a").click ( function () {
		var idioma = $(this).attr("id");
		var acao = window.location.pathname;
		document.forms[0].lang.value = idioma;
		document.forms[0].action = acao;
		document.forms[0].submit();
	});
		
	$("#ctrl_autoservico").click ( function(e) {
		e.preventDefault();
		$("body").scrollTop(0);
		larguratotal = $("#blacklayer").width();
		alturatotal = $("#blacklayer").height();
		$("#whitelayer").load("/autoservico", function() {
			largurajanela = $("#whitelayer").width();
			alturajanela = $("#whitelayer").height();
			largurafinal = larguratotal/2 - largurajanela/ 2;
			alturafinal = alturatotal/2 - alturajanela/2 - 100;
			$("#whitelayer").css({"top":alturafinal, "left": largurafinal});
			$("#blacklayer").css({ opacity: 0.5 });
			$("#blacklayer, #whitelayer").show("fast");
		});
	});
	
	$("#win_close").live ("click", function(e) {
		e.preventDefault();
		$("#blacklayer, #whitelayer").hide();
	});
	
	$("#dologin").live ("click", function(e) {
		e.preventDefault();
		$("#not_found, #inc_pass1, #inc_pass2, #bloqueio").hide();
		$.post("/auth/loginusuario", $("#form_login").serialize(), function(data) {
			switch(data) {
				case "usuario":
				$("#not_found").show();
				break;
				case "senha2":
				$("#inc_pass2").show();
				break;
				case "senha1":
				$("#inc_pass1").show();
				break;
				case "bloquear":
				$("#bloqueio").show();
				break;
				default:
				window.location = "/administracao"
				break;
			}
		});
	});
	
	$(".pasta").live ("click", function(e) {
		e.preventDefault();
		 if($(this).find("div").length > 0) {
		 	$(this).find("div").remove();
		 } else {
			var codigo = $(this).find("a").attr("href");
			$(this).append("<div></div>");
			$(this).find("div").load('/procedimentos/viewfolder/id/' + codigo);
		 }
	});
	
	$(".arquivo").live ("click", function(e) {
		e.preventDefault();
		var codigo = $(this).find("a").attr("href");
		window.open('/procedimentos/viewdoc/id/' + codigo);
	});
	
	if ($("#fale_conosco").length > 0) {
		$("#foneinput").mask("(99) 9999-9999");
	}
	
	$("#submitinput").click ( function(e) {
		e.preventDefault();
		$.post("/faleconosco/send",$("#myForm").serialize(), function(data) {
			if (data == "Mensagem enviada. Obrigado!" || data == "Message sent. Thank you!" || data == "Mensaje enviado. Gracias!") {
				alert(data);
				window.location = "/"
			} else {
				alert(data);
			}
		});
	});
	
	$("#subprodutos li a").click ( function(e) {
		e.preventDefault();
		$(".itensmercado").hide();
		var id = $(this).attr("href");
		$("#im" + id).show();
		$("#subprodutos li a").removeClass("clickitem");
		$(this).addClass("clickitem");
	});
	
	  $('#subprodutos li a').mouseenter(function() {
	    $("#leds").show();
	  });
	  $('#subprodutos li a').mouseleave(function() {
	    $("#leds").hide();
	  });

});

function galeria() {
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
	jQuery(function( $ ){
		$('#slideshow').serialScroll({
			items:'li',
			prev:'#screen a.prev',
			next:'#screen a.next',
			//offset: -230, //when scrolling to photo, stop 230 before reaching it (from the left)
			//start:0, //as we are centering it, start at the 2nd
			duration:7500,
			force:true,
			//stop:false,
			//lock:false,
			//cycle:true, //don't pull back once you reach the end
			//jump: true, //click on the images to scroll to them
			axis:'x',
			easing:'easeOutQuart',
			lazy:true,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
			interval:1, // yeah! I now added auto-scrolling
			step:1 // scroll 2 news each time
	
		});
	});
	
	$("#screen .next, #screen .prev").click ( function() {
		$('#slideshow').trigger('stop');
	});
}

function menu_vertical() {
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
	jQuery(function( $ ){
		$('#vertical_ss').serialScroll({
			items:'li',
			prev:'#vert_screen a.prev',
			next:'#vert_screen a.next',
			//offset: -230, //when scrolling to photo, stop 230 before reaching it (from the left)
			//start:0, //as we are centering it, start at the 2nd
			duration:10000,
			force:true,
			//stop:true,
			//lock:false,
			//cycle:true, //don't pull back once you reach the end
			//jump: true, //click on the images to scroll to them
			axis:'y',
			easing:'easeOutQuart',
			navigarion: '#vertical_ss a',
			lazy:true,// NOTE: it's set to true, meaning you can add/remove/reorder items and the changes are taken into account.
			interval:1, // yeah! I now added auto-scrolling
			step:1 // scroll 2 news each time
	
		});
	});
	
	$("#vert_screen .next, #vert_screen .prev").click ( function() {
		$('#vertical_ss').trigger('stop');
	});
}



function mercados() {
	$(".tabelas_mercado ul li").hover ( function () {
		$("#leds").show()},
		function () {
		$("#leds").hide()});
}

function setBackground(dados) {
	var css = dados.split(":");
	var path = "../../../public/imagens/mercados/" + css[0] + ".jpg";
	$("#box_mercados").css({"background-image": "url(" + path + ")"});
	$("#box_mercados").height(css[1] + "px");
}
