var current_open_pane = new Boolean(false);
var top_pane_tab   = "none";
var pane_element_to_update = "pane_updater";
var selector_for_vortex_effect = "div.lower_pane";
var current_tab_class_name = "current";

function toggle_pane(tab, default_menu_item, path) {
  if (top_pane_tab == tab && current_open_pane) {
    close_pane();
  }
  else {
    load_pane(tab, default_menu_item, path);
  }
}
function load_pane(tab, menu_item, path) {
  //new Ajax.Updater('pane_updater', path, {method : 'get'});
  new Ajax.Request(path, {
    method:         'get',
    onLoading:      open_pane(tab), 
    onComplete:     fill_pane
  });
}
function open_pane(tab) {
  // another pane open under this tab
  if (current_open_pane == true && top_pane_tab == tab) {
    add_vortex_by_selector(selector_for_vortex_effect);  
  }
  // another pane open under a different tab
  else if (current_open_pane == true) {
    $(pane_element_to_update).update('');
    addDarkSpinner(pane_element_to_update);
    set_current_tab(tab);
  }
  else {
    Effect.SlideDown('pane_container', {
      duration:     0.33,
      queue:        'end'
    });
    addDarkSpinner(pane_element_to_update);
    set_current_tab(tab);
    current_open_pane = true;
  }
}
function fill_pane(response, response_header) {
  $(pane_element_to_update).update(response.responseText);
}
function close_pane() {
  Effect.SlideUp('pane_container', {
    duration:0.33,
    queue:'end'
  });
  $(pane_element_to_update).update('');
  remove_current_class_name('a.top_pane_tab');
  current_open_pane = false;
}
function message_then_reload_pane(el, text, path) {
  $(el).update(text);
  funktion = "load_pane('messages','none','" + path + "')"
  window.setTimeout(funktion , 750);
}

function set_current_tab(tab) {
  remove_current_class_name('a.top_pane_tab');
  Element.addClassName(tab, current_tab_class_name);
  top_pane_tab = tab;
}
function remove_current_class_name(selector) {
  $$(selector).each(function(element){
    Element.removeClassName(element, current_tab_class_name)
    });
}