﻿/*-------------------------------------------------------------------------
Funções atreladas ao Jquery
-------------------------------------------------------------------------*/
if ($('.TirarFiltros')) { $('#filtrosCategoria1').hide('fast'); }

var filtros = 4;
var map;

function pegafiltro(nomeDofiltro) {
    var nomeBox = "BoxFiltro" + nomeDofiltro
    var nomeAba = "AbaFiltro" + nomeDofiltro
    var numeroItens = 0;
    var colocaNoFimAba = "";
    //var LarguraMapa = $('#mapaGoogle').width();
    //alert(LarguraMapa);
    if ($("dl#" + nomeBox).length != 0) {
        numeroItens = $("dl#" + nomeBox + " dd").size();
        //alert(numeroItens);
        if (numeroItens > 0) {

            if (numeroItens > 7) {
                numeroItens = 6;
                colocaNoFimAba = "<dd> <a href='#' class='linkMaisFiltros' title='" + nomeDofiltro + "'> Mais opções</a> </dd>";

            }
            if ($("dl#" + nomeAba).length != 0) {
                for (i = 0; i < numeroItens; i++) {
                    $("dl#" + nomeAba).append("<dd>" + $("dl#" + nomeBox + " dd:eq(" + i + ")").html() + "</dd>");
                }
            } else { /*alert("aba " + nomeDofiltro + " não encontrada")*/ }
            $("dl#" + nomeAba).append(colocaNoFimAba);
        } else {
            $("dl#" + nomeAba).parent().hide("fast");
            $('dl#BoxFiltroGrupo').css('left', 0);
            $('dl#BoxFiltroFabricante').css('left', 170);
            $('dl#BoxFiltroModelo').css('left', 170);
            $('dl#BoxFiltroCidade').css('left', 170);
           // $('#mapaGoogle').width(LarguraMapa + 170);
           // $('dl.BoxFiltro').css('left',$('dl.BoxFiltro').css('left') - 170);
        }
    } else { /*alert("box " + nomeDofiltro + " não encontrado")*/ }
    return false;
}


$(document).ready(function () {

    /*-------------------------------------------------------------------------
    Filtros
    ----------------------------------});---------------------------------------*/

    $('#linkNovosFiltros').click(function () {

        $(".BoxFiltro").hide("fast");
        $('#NovosFiltros').slideToggle('slow');

        $(this).toggleClass('Mostra');

    });


    $('#linkMapaFiltros .esconder').click(function () {
        $("#NovosFiltros li").hide("fast");
        $(".mapinha").show("slow");
        $('#linkMapaFiltros').addClass('Mostra');
    });

    $('.proMapa a').click(function () {
        if ($('#linkMapaFiltros').hasClass('Mostra')) { 
           return true;
       }

       $("#NovosFiltros li").hide("fast");
       $(".mapinha").show("slow");
       $('#linkMapaFiltros').addClass('Mostra');
       return true;

    });

    $('#linkMapaFiltros .mostrar').click(function () {
        $("#NovosFiltros li").show("slow");
        $(".mapinha").hide("fast");
        $('#linkMapaFiltros').removeClass('Mostra');
    });


    $('#btnMostraFiltro').click(function () {
        $('div.lksFiltrosX div').toggleClass('mostra');
        $('div.lksFiltrosY div').toggleClass('mostra');
        $(this).toggleClass('mostra');
    });


    $('#btnExibeFiltro').click(function () {

        $('#filtrosCategoria1').slideToggle('fast'); //  if (!$('.TirarFiltros')) { }
        $('#filtrosCategoria2').slideToggle('slow');
        $(this).toggleClass('mostra');

    });

    //if ($('.TirarFiltros')) { $('#filtrosCategoria1').hide('fast'); }


    $('#fltGrupo').click(function () {

        $('#filtrosFabricantes').slideUp('fast');
        $('#filtrosGrupos').slideToggle('slow');
        $('#fltFabricante').removeClass('ativo');
        $('#fltGrupo').toggleClass('ativo');

    });

    $('#fltFabricante').click(function () {

        $('#filtrosGrupos').slideUp('fast');
        $('#filtrosFabricantes').slideToggle('slow');
        $('#fltGrupo').removeClass('ativo');
        $('#fltFabricante').toggleClass('ativo');
    });

    $('#filtrosGrupos').slideToggle('slow');
    $('#fltGrupo').toggleClass('ativo');


    $('#ftGrupo').click(function () {
        $('#lksGrupos').slideToggle('fast');
        $(this).toggleClass('menos');
    });

    $('#ftFabricante').click(function () {
        $('#lksFabricante').slideToggle('fast');
        $(this).toggleClass('menos');
    });

    $('#ftModelos').click(function () {
        $('#lksModelo').slideToggle('fast');
        $(this).toggleClass('menos');
    });

    $('span#balao').click(function () {
        $(this).fadeOut("slow");
    });

    pegafiltro("SubCategoria");
    pegafiltro("Grupo");
    pegafiltro("Fabricante");
    pegafiltro("Modelo");
    pegafiltro("Cidade");

    $('a.linkMaisFiltros').click(function () {
        var Filtro = $(this).attr('title');
        $(".BoxFiltro").hide("fast");
        $("#BoxFiltro" + Filtro).show("slow");
    });

    $('a.linkFecharFiltro').click(function () {
        var nomeBox = "#BoxFiltro" + $(this).attr('title');
        $(nomeBox).hide("slow");
    });

    $('a.verFone').click(function () {
        var fone = parseInt($(this).attr("rel"));
        //alert(fone);

        $('a.[rel=' + fone + ']').hide("fast");
        $('a.[rel=' + fone + '] span.lojaTelefone').show("fast");
        //$('a.[rel=' + fone + '] .skype_v3_tb_injection').css("display", "block!important") 
        $.post("Redirecionador.aspx", { foneId: fone });

    });




    $('a.IncluirLista').click(function () {
        var _destino = $(this).attr('href');

        $.ajax({
            type: "GET",
            url: _destino
        });

        $(this).parent().parent().parent().toggleClass("linkRetirarLista");
        $("#IndicadorListaCompras").show("fast");
        return false;

    });

    $('a.RetirarLista').click(function () {
        var _destino = $(this).attr('href');

        $.ajax({
            type: "GET",
            url: _destino
        });

        $(this).parent().parent().parent().toggleClass("linkRetirarLista");
        return false;

    });

    $(".mapinha").hide("fast");




});





