function open_menu(id){
  document.getElementById(id).style.display ="block";
  //document.getElementById(id).setAttribute("style", "display: block;");
  document.getElementById(id+'_div').setAttribute("class", "topic_with_subnodes_pressed");
}

function close_menu(id){
  document.getElementById(id).style.display ="none";
  //document.getElementById(id).setAttribute("style", "display: none;");
  document.getElementById(id+'_div').setAttribute("class", "topic_with_subnodes");
}

function close_all(){
  var all_items = document.getElementsByClassName('topic_items');
  for  (i = 0; i < all_items.length;i++ ){
    all_items[i].style.display = "none";
    document.getElementById(all_items[i].id+'_div').setAttribute("class", "topic_with_subnodes");    
  }
}

function check_initial_state(yeold_id) {
  old_id = yeold_id
  if(old_id != '') {
    already_open = false
  } else {
    already_open = true
  }
}


function james(id){
  close_all();

  if(old_id!='') {
    close_menu(old_id);
  }

  if(old_id==id) {
    if(already_open==false){
      close_menu(id);
      already_open=true;
    } else {
      open_menu(id);
      already_open=false;
    }
  } else {
    open_menu(id);
    already_open=false;
  }

  old_id = id;

}




Event.addBehavior({
  "a.menu_script_button": function(event) {
    this.observe('click', function(event) {
      new Ajax.Request(this.href, {asynchronous:true, evalScripts:true});
      return false;
    }); return false;
  }

});
