var currentURL;
var currentState;
currentState = new Array();
function isManagedModule(mod) {
    if ((mod != "") &&
	(mod != "default") &&
	(mod != "inscr") &&
	(mod != "chessres"))
      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"));
  var cnt = $(".content");
  if (cnt.length == 0) {
    cnt = $(".largecontent");
  }
  if (lnk.charAt(0) != "?") {
      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"];
  else nkey = "";
  if (("m" in ops) && !isManagedModule(ops["m"])) {
    cnt.hide("slow", function () {
      window.location = lnk;
    });
    return;
  }
  if ("m" in ops) nmod = ops["m"];
  else nmod = "";
  if ("id" in ops) nid = ops["id"];
  else nid = "";
  if ("rnd" in ops) nrnd = ops["rnd"];
  else nrnd = "";
  if ("s" in ops)
    changeActiveSection(ops["s"]);
  else
    changeActiveSection("");
  cnt.hide("medium", function() {
    $.get("jquery/lnews.php", {key: nkey, m: nmod, id: nid, rnd: nrnd}, function(res) {
      var hidelogos  = $("hidelogos", res);
      var cnt = $(".content");
      if (cnt.length == 0) {
        cnt = $(".largecontent");
      }
      var elem = cnt[0];
      if (hidelogos.text() == '1') {
        elem.setAttribute("class", "largecontent");
        $(".logos").hide();
        cnt = $(".largecontent");
      } else {
        elem.setAttribute("class", "content");
        var l = $(".logos");
        elem = l[0];
        l.show();
        elem.setAttribute("style","");
        cnt = $(".content");
      }
      cnt.html($("content", res).text());
      cnt.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);
});

