//Damn you Mootools
jQuery.noConflict();

jQuery(document).ready(function() {
    jQuery("#catalog").tree({ui: {theme_name: "apple", animation: 200, dots: "false"}, callback: {beforeopen: function(node, tree) {
        jQuery("#catalog > ul > li > ul > li.open").not(jQuery(node).parent().parent()).each(function() {
            jQuery.tree_reference("catalog").close_branch(jQuery(this));
        });
    }}});
    jQuery("#products").hide();
    jQuery("#products").addClass("products-hidden");
    jQuery.tree_reference("catalog").open_branch(jQuery("#catalog li:first"));
    jQuery("#catalog > ul > li").each(function() {
        jQuery.tree_reference("catalog").open_branch(jQuery(this));
    });
    jQuery("#catalog a").click(function() {
        if(jQuery(this).parent("li").hasClass("open")) {
            jQuery.tree_reference("catalog").close_branch(jQuery(this).parent("li"));
        } else {
            jQuery.tree_reference("catalog").open_branch(jQuery(this).parent("li"));
        }
    });
});

jQuery(document).ready(function() {
    jQuery("#catalog a[rel=folder]").click(function() {
        if(jQuery("#products").hasClass("products-hidden")) {
            jQuery("#content").hide('100', function() {
                jQuery("#products").show('100');
            });
            jQuery("#products").removeClass("products-hidden");
        }
        jQuery("#products table").hide();
        jQuery(this).next().find("a[rel]").each(function() {
            var id = jQuery(this).attr("rel");
            jQuery("#products table[title='"+id+"']").show();
        });
    });
});

jQuery(document).ready(function() {
    jQuery("#hideProducts").click(function(event) {
        jQuery("#products").hide('100', function() {
            jQuery("#content").show('100');
        });
        jQuery("#products").addClass("products-hidden");
        event.preventDefault();
    });
});

jQuery(document).ready(function() {
    jQuery("#catalog .product.last.leaf").prev().addClass("last").addClass("leaf");
});
