/* default JavaScript for public art pages */

var isGecko = (document.getElementById) ? true : false;
var isIe5 = (document.all) ? true : false;

/**
 *  Toggles the display of elements and the plus/minus images in the table of
 *  contents.
 *
 *  @param {String} id    id attrib of target element
 *  @type void
 */
function toggle(id)
{
  var element;
  var whichImg;

  if (isIe5) {
    element = document.all[id];
    whichImg = event.srcElement;

    if (element.style.display == "none") {
      element.style.display = "";
      whichImg.src = "../graphics/minus.gif";
      whichImg.alt = "Shrink list";
    }
    else {
      element.style.display = "none";
      whichImg.src = "../graphics/plus.gif";
      whichImg.alt = "Expand list";
    }
  }
  else if (isGecko) {
    element = document.getElementById(id);
    whichImg = document.getElementById("img_" + id);

    if(element.style.display == "none") {
      element.style.display = "block";
      whichImg.setAttribute("src", "../graphics/minus.gif");
      whichImg.setAttribute("alt", "Shrink list");
    }
    else {
      element.style.display = "none";
      whichImg.setAttribute("src", "../graphics/plus.gif");
      whichImg.setAttribute("alt", "Expand list");
    }
  }
  colAdjust();
}

/**
 *  Builds the search string for the urls in the table of contents. Sets keys
 *  id, page, and next or prev. Determines the display state of toc items and
 *  sets key t.
 *
 *  @param {String}   mode        page to display: main, type, or default
 *  @param {int}      id          record ids are greater than 0; no id: -1
 *  @param {int}      page        page numbers are greater than 0; no page: -1
 *  @param {String}   nextOrPrev  next or previous page; values: next || prev
 *  @return location search string
 *  @type String
 */

function buildSearch(mode, id, page, nextOrPrev)
{
  var element;
  var newQuery = "";
  var is1st = true;

  switch (mode) {
    case 'main':
    case 'big':
    case 'types':
      newQuery += "mode=" + mode;
      is1st = false;
      break;
  }

  if (id != -1) {
    newQuery += (!is1st) ? "&" : "";
    newQuery += "id=" + id;
    is1st = false;
  }

  if (page != -1) {
    newQuery += (!is1st) ? "&" : "";
    newQuery += "page=" + page;
    is1st = false;
  }

  switch (nextOrPrev) {
    case "next":
      newQuery += (!is1st) ? "&" : "";
      newQuery += "next=1";
      is1st = false;
      break;

    case "prev":
      newQuery += (!is1st) ? "&" : "";
      newQuery += "prev=1";
      is1st = false;
      break;
  }

  if (isIe5) {
    element = document.all["artworks"];
    newQuery += (!is1st) ? "&" : "";
    newQuery += (element.style.display == "none") ?
      "a=0" : "a=1";
    is1st = false;

    element = document.all["types"];
    newQuery += (!is1st) ? "&" : "";
    newQuery += (element.style.display == "none") ?
      "t=0" : "t=1";
  }
  else if (isGecko) {
    element = document.getElementById("artworks");
    newQuery += (!is1st) ? "&" : "";
    newQuery += (element.style.display == "none") ?
      "a=0" : "a=1";
    is1st = false;

    element = document.getElementById("types");
    newQuery += (!is1st) ? "&" : "";
    newQuery += (element.style.display == "none") ?
      "t=0" : "t=1";
  }
  return newQuery;
}