/* Freepress javascript */
var currentLoc = "";

function setMenu() {
  if (document.getElementById) {
    var loc = window.location.href;
    var start = loc.indexOf('/',9);
    var firstDir = loc.substring(start + 1, loc.indexOf('/', start + 1));
    if (firstDir.indexOf('://') < 0) {
      currentLoc = firstDir;
      var lnk = document.getElementById('menu' + firstDir);
      lnk.className = 'current';
      if (lnk.firstChild && lnk.firstChild.tagName.toLowerCase() == 'img') {
        var src = lnk.firstChild.src;
        var i = src.indexOf('-off');
        if (i > 0) {
          var newSrc = src.substring(0, i) + "-on.png";
          lnk.firstChild.src = newSrc;
        }
      }
    }
  }
}

function menuSwap(menu, ison) {
  var to = '-on';
  var from = '-off';
  if (!ison) {
    to = '-off';
    from = '-on';
  }
  if (document.getElementById && menu != currentLoc) {
    var lnk = document.getElementById('menu' + menu);
    if (lnk.firstChild && lnk.firstChild.tagName.toLowerCase() == 'img') {
      var src = lnk.firstChild.src;
      var i = src.indexOf(from);
      if (i > 0) {
        var newSrc = src.substring(0, i) + to + ".png";
        lnk.firstChild.src = newSrc;
      }
    }
  }
}

function menuOn(menu) {
  menuSwap(menu, 1);
}
function menuOff(menu) {
  menuSwap(menu, 0);
}

function fpedit() {
  if (window.location.href.indexOf('freepress.int.aithal.org') > 0 ||
      window.location.href.indexOf('freepress.local') > 0) {
    document.write(" | <a href='/editor.php?page=" +
                   window.location.pathname + "'>Edit Page</a>");
  }
}
