var w          = false;
var timer      = false;
var current_bg = false;
var menu_bgs   = new Array("a", "b", "c");
var interval   = 12; // Hintergrundwechsel in Sekunden

function edit(page, person) {
  if (!w || w.closed) {
    w = window.open("/" + person + "/edit/" + page , "popup", "width=571,height=680");
  } else {
    w.focus();
  }
}

function toggle_background() {
  var menu_without_current = $.grep(menu_bgs, function(n) { return (n != current_bg) ? true : false });
  new_bg = menu_without_current[(1 + Math.round(Math.random() * (menu_without_current.length-1))) - 1];
  $("#bg_" + person + "_" + current_bg).fadeOut(1000);
  $("#bg_" + person + "_" + new_bg).fadeIn(1000);
  current_bg = new_bg;
  document.cookie = "last_bg=" + current_bg;
}

$(document).ready(function() {
  $(menu_bgs).each(function() { (new Image()).src = "/_img/bg_" + person + "_" + this + ".jpg"; });
  $("#inhalt").jScrollPane({ dragMinHeight: 28, dragMaxHeight: 28, scrollbarWidth: 11 });
  timer = window.setInterval("toggle_background()", interval * 1000);
});
