// load state of tools from cookie
var opened_state = $.cookie("tools"),
    to_open = null,
    cookieData = null,
    i = 0;
if (opened_state) {
    to_open = opened_state.split(',');
    for (i=0; i < to_open.length; i++) {
        if (to_open[i]) {
            $('#tools > div#' + to_open[i]).addClass('open');
        }
    }
}

// install click handler for tools
$("#tools > div.tool > h3").each(function() {
    $(this).click(function() {
        $(this).parent().toggleClass('open');
        cookieData = '';
        $("#tools > div.tool.open").each(function() {
            cookieData += $(this).attr('id') + ",";
        });
        $.cookie('tools', cookieData, {path: '/', expires: 1000});
    });
});

