var currentURL;
var currentState;
currentState = new Array();
function isManagedModule(mod) {
    if ((mod != "") &&
	(mod != "default"))
      return false;
    return true;
}
function getOptions(url) {
    var ops;
    var res;
    var elem;
    ops = url.split("&");
    res = new Array();
    for (i=0; i<ops.length; i++) {
      elem = ops[i].split("=");
      if (elem.length > 1)
      res[elem[0]] = elem[1];
    }
    return res;
}
function changeActiveSection(section) {
  if (currentState["s"] == section) {
    return;
  }
  if(currentState["s"] != "") {
    element = $(".menu ul");
    element.hide("medium", function() {
      element.remove();
    });
  }
  currentState["s"] = section;
  if (section != "") {
    $.get("jquery/lmenu.php", {selected: section}, function(res) {
      txt=($("content", res).text());
      $("a").click(buttonClicked);
      $("#menu_"+section).html($("content", res).text());
      $("#menu_"+section+" ul").show("slow");
    });
  }
}
function buttonClicked(e) {
  e.preventDefault();
  var lnk = ($(this).attr("href"));
  if (lnk.charAt(0) != "?") {
    $("body").hide("slow", function () {
      window.location = lnk;
    });
    return;
  }
  var ops, currentURLspl, currsec, co, nkey;
  nkey = "";
  ops = getOptions(lnk.substring(1));
  currentURLspl = currentURL.split("?");
  currsec = "";
  if (currentURLspl.length > 1) {
    currentState = getOptions(currentURLspl[1]);
  }
  if ("o" in ops) nkey = ops["o"];
  if (("m" in ops) && !isManagedModule(ops["m"])) {
    $("body").hide("slow", function () {
      window.location = lnk;
    });
    return;
  }
  if ("s" in ops)
    changeActiveSection(ops["s"]);
  else
    changeActiveSection("");
  $(".content").hide("medium", function() {
    $.get("jquery/lnews.php", {key: nkey}, function(res) {
      $(".content").html($("content", res).text());
      $(".content").show("slow");
      document.title = $("title", res).text();
      $("a").click(buttonClicked);
    });
  });
}
$(document).ready(function() {
  if ($.browser.msie) {
    return;
  }
  currentURL = ""+window.location;
  var currentURLspl;
  currentURLspl = currentURL.split("?");
  if (currentURLspl.length > 1) {
    currentState = getOptions(currentURLspl[1]);
    if (!("s" in currentState))
      currentState["s"] = "";
  }
  $("a").click(buttonClicked);
});
