$(function() {
    $('ul.sortable').sortable({ axis: "y", stop: saveSettingsOrder, handle: '.handle' });
    $('.secondlevel a').click(changeTabs);
});

function saveSettingsOrder() {
    var ids = $('ul.sortable:visible').sortable('toArray');
    $.getJSON(base + 'settings.ivp/saveorder', { ids: ids, timestamp: new Date().toString() });
}

function changeTabs() {
    $('.secondlevel a').each(function(i, e) { $(e).removeClass('activeswitch'); if (!$(e).hasClass('switch')) $(e).addClass('switch'); });
    $(this).removeClass('switch').addClass('activeswitch');

    $('.tab').hide();
    $('.tab#' + $(this).attr('tab')).show();
    return false;
}