// collect other js files we need
document.write('<script type="text/javascript" src="/scripts/browserdetect_lite.js"></script>');

// MacIE doesn't understand Array.push(), so we'll clue it in
if (typeof Array.prototype.push == "undefined")
{
  Array.prototype.push = function()
  {
    var i=0;
    b = this.length
    a = arguments;
    for(i;i<a.length;i++)this[b+i]=a[i];
    return this.length
  };
}

// onload will process an array we can
// push any functions to that we want
window.onload = function () {
    for(var ii = 0; arguments.callee.actions.length > ii; ii++)
        arguments.callee.actions[ii]();
};
window.onload.actions = [];

function statusBar()
{
  window.status = 'Know. Act. Succeed.';
}
window.onload.actions.push(statusBar);

// accessibilizeLinks
// added 9-8-03
// copy mouse events to keyboard events if no keyboard event exists
// Author: Ryan Carver | fivesevensix.com
function accessibilizeLinks()
{
  if (!document.getElementsByTagName) return;
  var events = {
  'onmousedown':  'onkeydown',
  'onmouseup':  'onkeyup',
  'onclick':   'onkeypress',
  'onmouseover':  'onfocus',
  'onmouseout':  'onblur'
  }
  var anchors = document.getElementsByTagName("a");
  for(var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    for (var e in events)
    {
      if (a[e] && !a[events[e]])
      a[events[e]] = a[e];
    }
  }
}
window.onload.actions.push(accessibilizeLinks);

// enlarge & reduce
function enlarge(what)
{
  var images = document.getElementById("map" + what).getElementsByTagName("img");
  var mapImage = images[0];
  var imagePath = mapImage.src;
  var imageNumber = imagePath.replace(".gif","");
  imageNumber = imagePath.substr(imagePath.indexOf("maps/map") + 9,2);
  imageNumber = parseInt(imageNumber);
  if (imageNumber > 1) {
    imageNumber = imageNumber - 1;
  }
  var newImagePath = "/images/maps/map" + what + imageNumber + ".gif";
  mapImage.setAttribute("src",newImagePath);
}
function reduce(what)
{
  var images = document.getElementById("map" + what).getElementsByTagName("img");
  var mapImage = images[0];
  var imagePath = mapImage.src;
  var imageNumber = imagePath.replace(".gif","");
  imageNumber = imagePath.substr(imagePath.indexOf("maps/map") + 9,2);
  imageNumber = parseInt(imageNumber);
  if (imageNumber < 10) {
    imageNumber = imageNumber + 1;
  }
  var newImagePath = "/images/maps/map" + what + imageNumber + ".gif";
  mapImage.setAttribute("src",newImagePath);
}

var setup = {
  init:  function(){
    setup.links.init();
  },
  links: {
    init:  function(){
      if( !document.getElementById &&
          !document.createElement &&
          !document.appendChild ) return;
      var txt = '(opens in a new window)';
      var links = document.getElementsByTagName( 'a' );
      var len = links.length;
      for( var i=0; i < len; i++ ){
        if( /\bexternal\b/.exec( links[i].getAttribute( 'rel' ) ) ||
            /\bdocument\b/.exec( links[i].getAttribute( 'rel' ) ) ){
          var title = links[i].getAttribute( 'title' )
          if( title ){
            links[i].setAttribute( 'title', title+' '+txt );
          } else {
            links[i].setAttribute( 'title', txt );
          }
          title = false;
          links[i].onclick = links[i].onkeypress = setup.links.open;
        } else if( links[i].getAttribute( 'href' ).match( /#.*/ ) ){
          var func = function(){
                       easy.to( this.getAttribute( 'href' ).replace( /#(.*)/, "$1" ) );
                       return false;
                     }
          links[i].onclick = links[i].onkeypress = func;
        } else {
          // do nothing
        }
      }
    },
    open:  function( e ){
      if( !e ) var e = window.event;
      // Abort if a modifier key is pressed
      if( e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) return;
      var newWindow = window.open( this.getAttribute('href'), '_blank' );
      if( newWindow ){
        if( newWindow.focus ) newWindow.focus();
        return false;
      } else {
        return true;
      }
    }
  }
}
window.onload.actions.push( setup.init );
