/* Javascript Show/Hide Function ([...]/httpdocs/resources/showhide.js)
 *
 * DESCRIPTION:
 * The function in this file governs display toggling for elements that can
 * optionally be hidden or shown in my user interface template, and in the
 * individual pages that import it. It is used most prominently in the various
 * peripheral information sections on my Journal page.
 *
 * AUTHOR:
 * The Confessor <http://confessor.org/contact.php>
 *
 * COPYRIGHT:
 * 2007-2010 The Confessor
 *
 * LICENSE:
 * Use of all or portions of my website source code in your own projects is
 * subject to the terms and conditions listed here:
 * <http://confessor.org/termsofuse.php>
 *
 */

var prevtarget = null;

function toggle(target,action,prevtarget_action) {

  element = document.getElementById(target+'element');
  img = document.getElementById(target+'img');

  if (prevtarget) {
    prevelement = document.getElementById(prevtarget+'element');
    previmg = document.getElementById(prevtarget+'img');
  }

  if (element.style.display != "" && (action == 'hide' || action == 'both')) {
    element.style.display = '';
    img.src = '/resources/toggle_closed.gif';
    if (prevtarget == target) {
      prevtarget = null;
    }
    try {eval(target+'_onhide();');}
    catch(err) {}
  }

  else if (element.style.display == "" && (action == 'show' || action == 'both')) {
    if (!prevtarget || prevtarget_action != 'interrupt') {
      if (prevtarget && prevtarget_action == 'hide') {
        prevelement.style.display = '';
        previmg.src = '/resources/toggle_closed.gif';
      }
      element.style.display = 'block';
      img.src = '/resources/toggle_open.gif';
      if (prevtarget_action != 'ignore') {
        prevtarget = target;
      }
      try {eval(target+'_onshow();');}
      catch(err) {}
    }
  }
}
