$(document).ready(function() {
    $("span.drop_down").addClass("drop_down");

    $("#sidebar h4 > span").click(function() {
        if (parseInt($('#sidebar ul:animated').length) == 0) {
            $(this).parent().next("ul").slideToggle("slow");
            $(this).toggleClass("drop_down");
        }
    });



    $("#sidebar li.items").hover(function() {
        $(this).children("ul").slideToggle("fast");
    }, function() {
        $(this).children("ul").slideToggle("fast");
    });
    
    $("#top_menu a[href='#cat']").hover(function() {
        $('span.menu_toggle_block').slideToggle("slow");
    });    
    
    $("span.menu_toggle_block .close").click(function() {
        $('span.menu_toggle_block').slideToggle("slow");
    });        

    $(".block > h3").click(function() {
        if (parseInt($('div.block_inner:animated').length) == 0) {
            $(this).next("div.block_inner").slideToggle("slow");
        }
    });

    var sub_items = $("#sub_menu > div");
    var max_width = parseInt($("#sub_menu").width());
    var page_number = parseInt($("#top_menu a.self").attr("rel"));
    $("#sub_menu > div[id='rel" + page_number + "']").show();

    $("#top_menu > h3 a").hover(function() {

        if ( (parseInt($('#sub_menu:animated').length) == 0) && 
             (parseInt($(this).attr("rel")) != page_number) ) {
            max_width = parseInt($("#sub_menu").width());
            $('span.menu_toggle_block').slideUp("slow");
            page_number = parseInt($(this).attr("rel"));
            mt_w = parseInt($("#sub_menu > div[id='rel" + page_number + "']").width());
            $("#sub_menu").animate({"width": (mt_w + 20) + "px"},
                                   450,
                                   function() {
                                       $("#sub_menu > div").hide();
                                       $("#sub_menu > div[id='rel" + page_number + "']").show();
                                       $("#sub_menu").animate({
                                                "width": max_width + "px"},
                                                450
                                            )
                                   });
        }

    });
});
