﻿$(document).ready(function() {
    var iconCarregando = $('<img src="./imagens/ajax/barra1.gif" class="icon" /> <span class="destaque">Carregando. Por favor aguarde...</span>');
    $('#Arvore').empty();
    var url = './requisicoes_js/busca_menu.ashx';
    $.ajax({
        url: url,
        dataType: 'html',
        type: 'GET',
        timeout: 10000,
        beforeSend: function() {
            $('#Arvore').html(iconCarregando);
        },
        complete: function() {
            $(iconCarregando).remove();
        },
        success: function(data, textStatus) {
            //alert(data);
            $('#Arvore').empty();
            $('#Arvore').html(data);
            $('#menu').css('height', 'auto');
            $('#menu ul').hide();
        },
        error: function(xhr, er) {
            $('#Arvore').html('<p class="destaque">Lamento! Ocorreu um erro. Por favor tente mais tarde.')
        }
    });

    //Efeito de abrir e fechar menu
    $('#menu h3').live('click', function() {
        if ($(this).attr('class') != 'inativo') {
            $(this).next().slideToggle(400).siblings('ul:visible').slideUp(400);
            $(this).toggleClass('corrente');
            $(this).siblings('#menu h3').removeClass('corrente');
        }
    });
})
