// set hidden/visible vars for Netscape 4 compatibility
if (document.layers) {
  var hidden = "hide";
  var visible = "show";
} else {
  var hidden = "hidden";
  var visible = "visible";
}
var toggle = "toggle";


/*
WM_checkIn()
Takes the ID of a positioned HTML element and returns an object reference.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Taylor
Author Email: taylor@wired.com
Author URL: http://www.taylor.org/

Usage: WM_checkIn('id')
*/
function WM_checkIn(WM_id) { 
  // First we initialize all the variables.
  var theObj,ss,sr,i,j,WM_layers=new Array();
  // This chunk handles the IE portion of the checkIn code.
  if (document.all) {
    // This checks to see if the inline style declaration has 
    // a position property associated with it. If not, it will 
    // scan the global stylesheets for the ID.
    if((document.all[WM_id].style.position != 'absolute') && (document.all[WM_id].style.position != 'relative')){
      // This little loop I'm very proud of, because it's kinda 
      // slick and I wrote it all myself. It loops through all 
      // global stylesheets and all the rules in each stylesheet, 
      // tests for the selected ID, then returns that as the object.
      for (ss=0 ; ss < document.styleSheets.length; ss++) {
        for (sr=0 ; sr < document.styleSheets(ss).rules.length; sr++) { 
          if (document.styleSheets(ss).rules(sr).selectorText == '#' + WM_id) {
            theObj = document.styleSheets(ss).rules(sr).style;
            break;
          }
        }
      }
    } else {
      // This works the same as in the light version, so you can 
      // use inline styles.
      theObj = document.all[WM_id].style;
    }
  } else if(document.layers) {
    // Now we're in Netscapeland. The main problem here 
    // is finding the object in a maze of hierarchy.
    // I wish I could say that I'm proud of this code, 
    // because it's really slick. Unfortunately, I ripped 
    // it off from Macromedia Dreamweaver's drag layer code 
    // (with permission, of course :-) 
    // Dreamweaver/Configuration/Behaviors/Actions/Drag Layer.htm 
    // It works wonderfully and solves the problem.
    WM_layers = new Array();
    with (document) {
      for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
        for (i=0; i<WM_layers.length; i++) {
          if (WM_layers[i].document && WM_layers[i].document.layers) {
            for (j=0; j<WM_layers[i].document.layers.length; j++) {
              WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
            }
            if(WM_layers[i].name == WM_id){
              // So if the code matches the name of the layer, 
              // return the reference. 
              theObj = WM_layers[i];
            }
          }
        }
      }
    }
  }
  return theObj;
}


/*
WM_changeVisibility()
Changes whether a layer is visible or hidden.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

usage: WM_changeVisibility('targetLayer1',[visible|hidden|toggle],'targetLayer2',[visible|hidden|toggle],...,'targetLayerN',[visible|hidden|toggle])

*/
function WM_changeVisibility() {
  if (document.layers || document.all) {
    var inc, endInc=arguments.length;
    // run through the args (objects) and set the visibility of each
    for (inc=0; inc<endInc; inc+=2) {
      // get a good object reference
      var daObj = WM_checkIn(arguments[inc]);
      if (arguments[inc+1] == hidden) {
        // hide the object
        daObj.visibility = hidden;
      } else if (arguments[inc+1] == visible) {
        // show the object
        daObj.visibility = visible;
      } else if (arguments[inc+1] == toggle) {
        // toggle the object's visibility
        if (daObj.visibility == visible) {
          daObj.visibility = hidden;
        } else if (daObj.visibility == hidden) {
          daObj.visibility = visible;
        }
      }
    }
  }
}




/*

WM_moveTo()

Moves an object from its current location to a new location and optionally fires a function when it's done.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: WM_moveTo('objectName', endingLeft, endingTop, numberOfSteps, delayBetweenSteps, 'functionToFire()'); 

*/
function WM_moveTo(daObject, endLeft, endTop, numSteps, delay, endFunction) {
  // Declare variables.
  var leftInc, topInc, daObj = new Object;
  // The first time through, create document.WM.WM_moveTo
  if (typeof document.WM == 'undefined'){
    document.WM = new Object;
    document.WM.WM_moveTo = new Object;
  } else if (typeof document.WM.WM_moveTo == 'undefined') {
    document.WM.WM_moveTo = new Object;
  }
  // Store endFunction to execute when the move is finished.
  if(endFunction) document.WM.WM_moveTo.endFunction = endFunction;
  // Get a good object reference (call it daObj) from WM_checkIn().
  // But if we've already done so, don't check it in again.
    if (daObject == "sameObj") {
      daObj = document.WM.WM_moveTo.daObj;
    } else {
      daObj = WM_checkIn(daObject);
      document.WM.WM_moveTo.daObj = daObj;
    }
  // If this is the last step, go to the end point and run endFunction.
  if (numSteps == 1) {
    daObj.left = endLeft;
    daObj.top = endTop;
    // If an endFunction was set, execute it and then delete it.
    if(document.WM.WM_moveTo.endFunction) {
      daFunction = document.WM.WM_moveTo.endFunction;
      document.WM.WM_moveTo.endFunction = '';
      eval(daFunction);
    }
  } else {
    // Otherwise, figure out how far to move.
    leftInc = (endLeft - parseInt(daObj.left)) / numSteps;
    topInc = (endTop - parseInt(daObj.top)) / numSteps;
    // Then move, decrement numSteps, and do it all again.
    daObj.left = parseInt(daObj.left) + leftInc;
    daObj.top = parseInt(daObj.top) + topInc;
    numSteps--;
    setTimeout ('WM_moveTo(\'sameObj\', ' + endLeft + ', ' + endTop + ', ' + numSteps + ', ' + delay + ')', delay);
  }
}


/*
  WM_imageSwap()
  Changes the source of an image.

  Source: Webmonkey Code Library
  (http://www.hotwired.com/webmonkey/javascript/code_library/)

  Author: Shvatz
  Author Email: shvatz@wired.com

  Usage: WM_imageSwap(originalImage, 'newSourceUrl');

  Requires: WM_preloadImages() (optional, but recommended)
  Thanks to Ken Sundermeyer (ksundermeyer@macromedia.com) for his help
  with variables in ie3 for the mac. 
  */
function WM_imageSwap(daImage, daSrc){
  var objStr,obj;

  // Check to make sure that images are supported in the DOM.
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(daImage) == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}


/*
WM_preloadImages()
Loads images into the browser's cache for later use.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: WM_preloadImages('image 1 URL', 'image 2 URL', 'image 3 URL', ...);
*/
function WM_preloadImages() {
  // Don't bother if there's no document.images
  if (document.images) {
    if (typeof(document.WM) == 'undefined'){
      document.WM = new Object();
    }
    document.WM.loadedImages = new Array();
    // Loop through all the arguments.
    var argLength = WM_preloadImages.arguments.length;
    for(arg=0;arg<argLength;arg++) {
      // For each arg, create a new image.
      document.WM.loadedImages[arg] = new Image();
      // Then set the source of that image to the current argument.
      document.WM.loadedImages[arg].src = WM_preloadImages.arguments[arg];
    }
  }
}
