﻿function init() {
    $("#lista").accordion({
        header: "h4.cat",
        autoheight: false,
        alwaysOpen: false,
        active: ":last"
    });

//    $("div.item").bind("mouseenter", function() {
//        $(this).addClass("high");
//    }).bind("mouseleave", function() {
//        $(this).removeClass("high");
//    });

    $("div.item a").click(function() {
        goAjax(this.getAttribute('rel'));
        return false;
    });

    $("select.menu").change(function() {
        if ($(this).val() != "") {
            document.location.href = $(this).val();
        }
    });
}

function goAjax(rel) {
    $.ajax({
        url: "Pacote.aspx",
        data: ({ id: rel }),
        cache: false,
        beforeSend: function() {
            $("div.switched").removeClass("switched");
            $("div[rel='" + rel + "']").addClass("switched");
            $cat = $("h4.selected");
            var y2 = $cat.offset().top;
            var y1 = $("#lista").offset().top;
            var y = (y2 - y1);
            $("#conteudo").css("margin-top", y + "px");
            $("#conteudo").html("<div class='carregando rounded'><img src='img/ajax-loader2.gif' alt='carregando...' /></div>");
            window.scrollTo(0, y2);
        },
        success: function(html) {
            $("#conteudo").html(html);
        },
        complete: function() {
            $("a.modal").fancybox({ frameWidth: 530, frameHeight: 480, overlayOpacity: 0.7 });
            window.scrollTo(0, $("h4.selected").offset().top);
        }
    });
};

function Abre(rel) {
    var active = $('h4.cat').index($('h4.selected'));
    var index = $('h4.cat').index($('h4[rel="' + rel + '"]'));
    if (active != index) $('#lista').accordion('activate', index);
}

function close() {
    $("#conteudo").html('');
}