var Estilo = "";
var Cont = Number(0);
var Cont2 = Number(0);
var id = "";
var Linkage = "";
var Eq = Number(0);
var Eq2 = Number(0);
var Valor = "";
var Valor2 = "";
var Quant = "";
var Quant2 = "";
var Looping = "";
var Looping2 = "";
var arquivo = "";
var Largura = "";
var Detalhe = "";

/* LIGHTBOX */
hs.graphicsDir = 'images/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.fadeInOut = true;
hs.headingEval = 'this.thumb.alt';
hs.headingOverlay.position = 'below';
hs.addSlideshow({
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .75,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});

function Mascaras() {
    /* MASCARAS */
    $("[id$='Cep']").mask("99999-999");
    $("[id$='Cpf']").mask("999.999.999-99");
    $("[id$='Rg']").mask("9999999999");
    $("[id$='Cnpj']").mask("99.999.999/9999-99");
    $("input[name='emissao']").mask("99/99/9999");
    $("[id$='Nascimento']").mask("99/99/9999");
    $("[id$='Telefone1']").mask("(99)9999-9999");
    $("[id$='Telefone2']").mask("(99)9999-9999");
    
}

$(document).ready(function() {
/* BUSCA */
	$("#ctl00_cphConteudo_txtTelefone").mask("(99) 9999-9999");
	$("[id$='Busca']").live("focus", function() {
        if ($("[id$='Busca']").val() == "Digite aqui o que procura...") {
            $("[id$='Busca']").val("");
		}
    });
	$("[id$='Busca']").live("blur", function() {
		if($(this).val() == "") {
			$(this).val("Digite aqui o que procura...");
		}
	});

	/* JANELAS */
	$("#link-indisponivel").click(function() {
		$("#avise-me").show();
	});
	$("#avise-me > div > a").live("click", function() {
		$("#avise-me").hide();
	});
	$("#login a").click(function() {
		$("#esqueci").show();
	});
	$("#esqueci > div > a").live("click", function() {
		$("#esqueci").hide();
	});

	/* MENU */
	$("#menu ul li").corner("3px");

	/* TRILHA DE NAVEGACAO */
	$("#trilha li:last-child").addClass("last");

	/* EBIS */
	$("#link").mouseover(function() {
		$("#ebis img").stop();
		$("#ebis img:first-child").animate({top:0, opacity: 0}, 250, function() {
			$(this).animate({top:15, opacity: 1}, 250);
			$("#ebis img + img").animate({top:35, opacity: 1}, 250);
		});
	});
	$("#link").mouseout(function() {
		$("#ebis img").stop();
		$("#ebis img + img").animate({top:45, opacity: 0}, 250);
		$("#ebis img:first-child").animate({top:0, opacity: 0}, 250, function() {
			$(this).animate({top:15, opacity: 1}, 250);
		});
	});

	$("#ctl00_cphConteudo_txtLoginSenha").keydown(function(event) {
	    if (event.keyCode == 13) {
	        $("#ctl00_cphConteudo_btnLogin").click();
	    }
	});

	$("#ctl00_txtBusca").keydown(function(event) {
	    if (event.keyCode == 13) {
	        $("#ctl00_btnBuscar").click();
	    }
	});

//	$("#ctl00_cphConteudo_txtLoginEmail").keydown(function(event) {
//	    if (event.keyCode == 13) {
//	        $("#ctl00_cphConteudo_btnLogin").click();
//	    }
//	});
//	

	/* RESIZE PRODUTOS */
	$(window).resize(function() {
		LarguraAltura();
	});
	setTimeout(function() {
		LarguraAltura();
	}, 500);

	/* NEWSLETTER */
	if ($("#newsletter div input").val() != "") {
		$("#newsletter div label").css('display', 'none');
	}
	$("#newsletter div label").mouseup(function() {
		$(this).parent().children("input").focus();
	});
	$("#newsletter div input").focus(function() {
		$(this).parent().children("label").css('display', 'none');
	});
	$("#newsletter div input").blur(function() {
		if ($(this).val() == "") {
			$(this).parent().children("label").css('display', 'block');
		}
	});

	/* PRODUTOS QUANTIDADE */
	if ($(".lista-produtos li div.text input").val() != "") {
		$(".lista-produtos li div.text label").css('display', 'none');
	}
	$(".lista-produtos li div.text label").mouseup(function() {
		$(this).parent().children("input").focus();
	});
	$(".lista-produtos li div.text input").focus(function() {
		$(this).parent().children("label").css('display', 'none');
	});
	$(".lista-produtos li div.text input").blur(function() {
		if ($(this).val() == "") {
			$(this).parent().children("label").css('display', 'block');
		}
	});

	/* EMPRESAS */
	var quanTelas = ($("#empresas ul li").length);
	var Resto = quanTelas%15;
	quanTelas = quanTelas - Resto;
	quanTelas = quanTelas/15;
	var i = 0;
	if(quanTelas > 1){
		var anim = 360;
		$("#empresas ul").height((quanTelas + 1)*360);
		$("#arrow-top").click(function() {
			if(i > 0) {
				$('#arrow-bottom').show();
				i = i - 1;
				$('#empresas ul').animate({top: -(i)*anim}, 900, function() {
					if(i == 0) {
						$("#arrow-top").hide();
					}
				});
			}
		});
		$("#arrow-bottom").click(function(){
			if(i < quanTelas) {
				$('#arrow-top').show();
				i = i + 1;
				$('#empresas ul').animate({top: -(i)*anim}, 900, function() {
					if(i == quanTelas)
						$("#arrow-bottom").hide();
				});
			}
		});
	}else{
		$("#arrow-bottom").remove();
	};

	/* PRODUTOS DETALHES */
	$("#links-detalhes li a").click(function() {
		$("#links-detalhes li, #detalhes li").removeClass("selected");
		$(this).parent().addClass("selected");
		Detalhe = $(this).attr("id");
		$("#detalhes-" + Detalhe).addClass("selected");
	});

	/*	DESTAQUES */
	if($("#destaques .images > div").length > 1) {
	    $("#destaques .images > div").each(function() {
		    Cont2 = Cont2 + 1;
		    $("#destaques .slidetabs").append("<a href='javascript:;' alt='" + Cont2 + "'>" + Cont2 + "</a>");
	    });
	}
	banner2(0);

	/* BANNER */
	if($("#banner .images > div").length > 1) {
	    $("#banner .images > div").each(function() {
		    Cont = Cont + 1;
		    $("#banner .slidetabs").append("<a href='javascript:;' alt='" + Cont + "'>" + Cont + "</a>");
	    });
	}
	banner(0);
	$(".flash").each(function() {
		Id = $(this).attr("id");
		Linkage = $(this).attr("tittle");
		$("div#" + Id).flash(
			{
				src: base + 'public/files/' + Id + '.swf',
				width: "100%",
				height: 195,
				wmode: 'transparent',
				expressInstall: true,
				version: '10'
			}
		);
	});
});
function banner(Eq) {
	if($("#banner .images > div").length > 1) {
	    Eq = Eq + 1;
	    Valor = $("#banner .images > div").eq(Eq - 1).attr("alt");
	    Quant = $("#banner .images > div").length;
	    $("#banner .images > div").fadeOut(1000);
	    $("#banner .images > div").eq(Eq - 1).fadeIn(1000);
	    $("#banner .slidetabs a").removeClass("current");
	    $("#banner .slidetabs a").eq(Eq - 1).addClass("current");
	    Looping = setTimeout(function() {
		    if(Eq == Quant) {
			    Eq = 0;
		    }
		    banner(Eq);
	    }, Valor);
	}else{
	    $("#banner .images > div").fadeIn(1000);
	}
};

$("#banner .slidetabs a").live("click", function() {
	clearTimeout(Looping)
	Eq = $(this).attr("alt");
	banner(Eq - 1);
});

function banner2(Eq2) {
	if($("#destaques .images > div").length > 1) {
	    Eq2 = Eq2 + 1;
	    Valor2 = 8000;
	    Quant2 = $("#destaques .images > div").length;
	    $("#destaques .images > div").fadeOut(1000);
	    $("#destaques .images > div").eq(Eq2 - 1).fadeIn(1000);
	    $("#destaques .images > div").eq(Eq2 - 1).find("span").animate({"opacity": "1", "left": "0"}, 500);
	    $("#destaques .images > div").eq(Eq2 - 1).find("h3").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div").eq(Eq2 - 1).find("p").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div").eq(Eq2 - 1).find("h4").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div").eq(Eq2 - 1).find("h5").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div div").eq(Eq2 - 1).find("img").animate({"opacity": "1", "left": "0"}, 1000);
	    setTimeout(function() {
		    $("#destaques .images > div").eq(Eq2 - 2).find("span").css("left", "-50px");
		    $("#destaques .images > div").eq(Eq2 - 2).find("h3").css("left", "150px");
		    $("#destaques .images > div").eq(Eq2 - 2).find("p").css("left", "100px");
		    $("#destaques .images > div").eq(Eq2 - 2).find("h4").css("left", "75px");
		    $("#destaques .images > div").eq(Eq2 - 2).find("h5").css("left", "50px");
		    $("#destaques .images > div div").eq(Eq2 - 2).find("img").css("left", "25px");
	    }, 1000);
	    $("#destaques .slidetabs a").removeClass("current");
	    $("#destaques .slidetabs a").eq(Eq2 - 1).addClass("current");
	    Looping2 = setTimeout(function() {
		    if(Eq2 == Quant2) {
			    Eq2 = 0;
		    }
		    banner2(Eq2);
	    }, Valor2);
	}else{
	    $("#destaques .images > div").fadeIn(1000);
	    $("#destaques .images > div").find("span").animate({"opacity": "1", "left": "0"}, 500);
	    $("#destaques .images > div").find("h3").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div").find("p").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div").find("h4").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div").find("h5").animate({"opacity": "1", "left": "0"}, 1000);
	    $("#destaques .images > div div").find("img").animate({"opacity": "1", "left": "0"}, 1000);
	}
};

$("#destaques .slidetabs a").live("click", function() {
	clearTimeout(Looping2)
	Eq2 = $(this).attr("alt");
	banner2(Eq2 - 1);
});

function LarguraAltura() {
	if($(".lista-produtos").hasClass("four")) {
		if($(".lista-produtos").width() >= 1500) {
			$(".lista-produtos li").width("12%");
		}else{
			$(".lista-produtos li").width("24%");
		}
	}else{
		if($(".lista-produtos").width() >= 1100) {
			$(".lista-produtos li").width("16%");
		}else{
			$(".lista-produtos li").width("32%");
		}
	}
	Largura = $(".lista-produtos li").width();
	Largura = (Largura-199)/2;
	$(".lista-produtos li > div").css("left", Largura);

	var Left = $("#left").height();
	$("#content").height("auto");
	var Center = $("#content").height();
	var Right = $("#right").height();
	if(Left > Center && Left > Right) {
		$("#content").height(Left);
	}else if(Right > Center && Right > Left) {
		$("#content").height(Right);
	}else {
		$("#content").height(Center);
	}
}
