var Eq = Number(0);
var Valor = "";
var Quant = "";
var Looping = "";
var id = "";
var Cont = Number(0);
var Divs = 0;
var Carro = "";

/* LIGHTBOX(NOTICIAS DETALHES) */
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
	}
});
/* FIM LIGHTBOX(NOTICIAS DETALHES) */
$(document).ready(function() {
	$("input[idvalidacao='telefone']").mask("(99) 9999 9999");
	$("input[idvalidacao='data']").mask("99/99/9999");
	$("input[idvalidacao='data-nascimento']").mask("99/99/9999");
	$("input[idvalidacao='horario']").mask("99:99");

	/* MENU */
	$("#menu li").hover(
		function () {
			if(!$(this).hasClass("selected")) {
				$(this).children("a").children("img + img").fadeIn("500");				
			}
		},
		function () {
			if(!$(this).hasClass("selected")) {
				$(this).children("a").children("img + img").fadeOut("500");
				
			}
		}
	);
	$("#menu li.last a").click(function() {
		$("#busca").show();
		$("input[name='buscar']").focus();
	});
	$("#busca label").click(function() {
		$("#busca").hide();
	});

	/* BUSCA AVANCADA */
	$("#busca-avancada + a").click(function() {
		if(!$("#busca-avancada").hasClass("selected")){
			$("#busca-avancada").addClass("selected");
			$("#busca-avancada").slideDown("500");
		}else{
			$("#busca-avancada").removeClass("selected");
			$("#busca-avancada").slideUp("500");
		};
	});

	/* LOJAS */
	$("#telefone-lojas li + li").hover(function() {
		$(this).children("div").show();
		$(this).children("div").animate({opacity:1, top:"-46px"}, 200 );
	},
	function() {
		$(this).children("div").animate({opacity:0, top:"-35px"}, 300, function() {
			$(this).hide();
		});
	});
	$("#telefone-lojas li:first-child").hover(function() {
		$(this).children("div").show();
		$(this).children("div").animate({opacity:1, top:"-106px"}, 200 );
	},
	function() {
		$(this).children("div").animate({opacity:0, top:"-94px"}, 300, function() {
			$(this).hide();
		});
	});

	/* DESTAQUES */
	$(function() {
		$(".scrollable").scrollable({ vertical: true, circular: true, speed: 2000, easing: "swing" });
	});
	$(".scrollable .items li, #carros li").hover(function() {
		$(this).find("a + a").fadeIn("300");
	},
	function() {
		$(this).find("a + a").fadeOut("300");
	});

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

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

	/* 	BANNER */
	banner(0);
	$(".flash").each(function() {
		Id = $(this).attr("id");
		$("div#" + Id).flash(
			{
				src: '_uploads/banner/' + Id + '.swf',
				width: 938,
				height: 217,
				wmode: 'transparent',
				expressInstall: true,
				version: '10'
			}
		);
	});
	Divs = $("#banner .images > div").length;
	$("#prev").click(function() {
		clearTimeout(Looping)
		Eq = $(this).attr("alt");
		banner(Eq - 2);
	});
	$("#next").click(function() {
		clearTimeout(Looping)
		Eq = $(this).attr("alt");
		banner(Eq++);
	});

	/* VEICULO */
	$("form#agendamento select[name='veiculo'] option").click(function() {

		if($(this).parent().val() == "outros") {
			$("form#agendamento input[name='outros-veiculos']").parent().remove();
			$(this).parent().parent().after("<div class='text'><label for='outros-veiculos'>Outros Veículos</label><input type='text' name='outros-veiculos' /></div>");
		}else{
			$("form#agendamento input[name='outros-veiculos']").parent().remove();
		}
	});

	/* TRABALHE CONOSCO */
	if ($("#trabalhe-conosco div.file input").val() != "") {
		arquivo = $("#trabalhe-conosco div.file input").val();
		$("#trabalhe-conosco div.file input").parent().children("input + p").text(arquivo);
	}
	$("#trabalhe-conosco div.file input").change(function() {
		arquivo = $(this).val();
		$(this).parent().children("input + p").text(arquivo);
	});

	/* FAQ */
	$("div.faq").prev().addClass("custom");
	$(".faq ul li h5").click(function() {
		if(!$(this).parent().hasClass("selected")){
			$(".faq ul li").removeClass("selected");
			$(this).parent().addClass("selected");
		}else{
			$(".faq ul li").removeClass("selected");
		};
	});

	/* NOTICIAS */
	$("#noticias").prev().addClass("acento");
});

function banner(Eq) {
	Eq = Eq + 1;
	if (Eq == -Divs) {
		Eq = 4
	}
	if (Eq == Divs + 1) {
		Eq = 1
	}
	$("#prev").attr("alt", Eq);
	$("#next").attr("alt", Eq);
	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);
};

$("#click-proposta").live("click", function() {
    $("#overlay").show();
    Carro = $(this).parent().children("a:first-child").children("img").attr("alt");
    $("#proposta").children("input#ctl00_cphConteudo_hfNomeVeiculoNovoProposta").val(Carro);
    $("#proposta").children("input#cphConteudo_hfNomeVeiculoNovoProposta").val(Carro);
});
$("#proposta a").live("click", function() {
	$("#overlay").hide();
});

/* FLOAT BANNER */
$(document).ready(function() {
    $("#fechaPromo").click(function() {
        $.ajax({
            type: "GET",
            cache: false,
            async: true,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            url: "Ajax/ajax.ashx",
            success: function() {
                $("#fechaPromo").parent().fadeOut(700);
            }
        });
    });
    $("#linkPromo").click(function() {
        $.ajax({
            type: "GET",
            cache: false,
            async: true,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            url: "Ajax/ajax.ashx",
            success: function() {
                window.location.href = "feirao";
            }
        });
    });
});	
