
function newImage(arg) {
   if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
   }
}

function changeImages() {
   if (document.images) 
   {
      for (var i=0; i<changeImages.arguments.length; i+=2) {
         document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
      }
   }
}


var imgNum = 0;
// hrefcontent is href='blah' and any subsequeny text
function imageOverLink(text, hrefcontent, upImage, downImage, width, height)
{
   var imgname = "img" + imgNum;
   var out = "<a " + hrefcontent + 
      "onmouseover=\"window.status='" + text + "'; changeImages('" + imgname + "', '" + downImage + "'); return true;\"" +
      "onmouseout=\"window.status=''; changeImages('" + imgname + "', '" + upImage + "'); return true;\"" +
      "onmousedown=\"changeImages('" + imgname + "', '" + downImage + "'); return true;\"" + 
      "onmouseup=\"changeImages('" + imgname + "', '" + downImage + "'); return true;\">" +
      "<img name='" + imgname + "' src='" + upImage + "' width='" + width + "' height='" + height + "' border='0' alt='" + text + "'></a>";
   imgNum++;

   document.write(out);
}



function newImageWindow(url, title, arg_width, arg_height) {
   // <a href="javascript:newImageWindow(url, title, width, height)">Open Window</a>
   
   if ( arg_width == null ) {
      arg_width = screen.width * 0.95;
   }
   if ( arg_height == null ) {
      arg_height = screen.height * 0.9;
   }

   var winl = (screen.width - arg_width) / 2;
   var wint = (screen.height-55 - arg_height) / 2;
   
   // Netscape window position
   var winPos = "screenX="+winl+",screenY= ,"+wint+",";
   // IE window Position
   winPos += "left="+winl+", top="+wint+",";

   var newWindow = 
      window.open( url, '',
   'scrollbars=' + 'yes' + 
   ', menubar=no, height=' + arg_height + 
   ', width=' + arg_width + winPos +
   ', resizable=yes, toolbar=no, location=no,status=no'); 

   // if (title != "" ) {
   //    newWindow.document.title = title;
   // }

}

//--------------------------------------------------
// A helper function to getElementById in all browsers
function getElementById(element_id)
{
  // This method returns the element corresponding to the id

  if (document.getElementById) {
    return document.getElementById(element_id);
  }
  else if (document.all) {
    return document.all[element_id];
  }
  else if (document.layers) {
    return document.layers[element_id];
  } else {
    return undefined;
  }
}

// ----internal window size ----
// blatantly stolen and adapted from http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function windowSize() {
  this.width = 0, this.height = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    this.width = window.innerWidth;
    this.height = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    this.width = document.documentElement.clientWidth;
    this.height = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    this.width = document.body.clientWidth;
    this.height = document.body.clientHeight;
  }
  //console.log( 'Width = ' + this.width );
  //console.log( 'Height = ' + this.height );
}

function scrollOffset() {
   // Determine the scroll bar offsets
  this.x = 0, this.y = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    this.y = window.pageYOffset;
    this.x = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    this.y = document.body.scrollTop;
    this.x = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    this.y = document.documentElement.scrollTop;
    this.x = document.documentElement.scrollLeft;
  }
}
 
// Determine the center point of the displayed document (so that we can offset a css layer based on where the
// user is currently point
function displayCenter() {
   var win = new windowSize();
   var scroll = new scrollOffset();

   // console.log(win);
   // console.log(scroll);

   this.x = (win.width/2) + scroll.x;
   this.y = (win.height/2) + scroll.y;

   delete win;
   delete scroll;
}

// Fading scripts ------------------------------------------------------------
function fader() { };
   fader.prototype.fadeTimer = 0;
   fader.prototype.fade_interval = 50;
   fader.prototype.crossfade_duration = 3000;
   fader.prototype.pause_interval = 4000;
   fader.prototype.pauseTimer = 0;
   fader.prototype.fadeClock = 0;
   fader.prototype.currentElement = 0;
   fader.prototype.prevElement = 1;

fader.prototype.autoFade = function()
{
   this.currentElement = (this.currentElement+1) % this.displayElements.length;
   this.prevElement    = (this.prevElement+1) % this.displayElements.length;

   //console.log (this.displayElements.length);
   //console.log ("cur: " + this.currentElement + " prev: " + this.prevElement);
   this.triggerFade();
};

fader.prototype.triggerFade = function()
{

   this.displayElements[this.currentElement].style.visibility = "visible";
   
   this.fadeClock = 0;
        
   var p=this;

   // Be sure to clear the fadeTimer before we display another element...
   clearInterval( this.fadeTimer );
   this.fadeTimer = setInterval(function() { p._fade(); }, this.fade_interval );
};


// Internal fade function that will be called every fade_interval msec by the
// displayItem function
fader.prototype._fade = function()
{
   this.fadeClock += this.fade_interval;

   var ieop = Math.round( this._easeInOut(this.fadeClock, 0, 1, this.crossfade_duration) * 100 );
   var op = ieop / 100;

   // CurrentElement and PrevElement shorthand
   var ce = this.displayElements[this.currentElement];
   var pe;

   // fade in the new element
   ce.style.opacity = op;
   ce.style.filter = "alpha(opacity="+ieop+")";


   // fade out the old element
   if (this.prevElement > -1)
   {
      pe = this.displayElements[this.prevElement];
      pe.style.opacity = 1 - op;
      pe.style.filter = "alpha(opacity="+(100 - ieop)+")";
   }

   // If we've reached the clock boundary, stop the interval
   if (this.fadeClock >= this.crossfade_duration)
   {
      clearInterval( this.fadeTimer );

      // hide the previous element
      if (this.prevElement > -1) 
      {
         pe.style.visibility = "hidden"; 
         pe.style.opacity = 0;
         pe.style.filter = "alpha(opacity=0)";
      }

      // Set the self perpetuating interval
      clearInterval( this.pauseTimer );
      var p=this;
      this.pauseTimer = setInterval(function() { p.autoFade(); }, this.pause_interval );
   }
};

fader.prototype._easeInOut = function(t,b,c,d) { return c/2 * (1 - Math.cos(Math.PI*t/d)) + b; };




