// change speed of slide here
var slide_in_speed = 600;	// millisecond duration of slide into view
var slide_out_speed = 500;// millisecond duration of slide out of view

function initGlideLayers() {


  // args: id, left, top, w, h, duration of glide to location onscroll, acceleration factor
  // acceleration factor should be -1 to 1. -1 is full deceleration
  var statLyr = new Glider("glideDiv0",40,120,null,null,1000,-1);


  var glideLyrs = new Array();

  // Set up your layers here
  // arguments: id, left=0 (offset calculated based on width), top
  glideLyrs[0] = new Glider('glideDiv0', 15, 200, 2, 475, 1000, -1);

  for (var i=0; glideLyrs[i]; i++) {
		// hold original left position
		glideLyrs[i].xOff = -(glideLyrs[i].w - 14);
		glideLyrs[i].shiftTo( glideLyrs[i].xOff, glideLyrs[i].y );
		glideLyrs[i].show();
  }

}

var curGlideLyr;
function slideEm(id) {
  var oldLyr, newLyr;
  // if link for current layer clicked, slide it out of view
	if (curGlideLyr == id) {
    oldLyr = dynObj.getInstance(curGlideLyr);
		oldLyr.slideTo(oldLyr.xOff, null, slide_out_speed, -1);
    curGlideLyr = ""; return;
  }
	// if layer currently in view, set up to slide new one into view
	// after current one slides away
	if (curGlideLyr)
	{
    	oldLyr = dynObj.getInstance(curGlideLyr);
		oldLyr.onSlideEnd = function()
		{
			dynObj.holder[curGlideLyr].slideTo(0, null, slide_in_speed, -1);
			this.onSlideEnd = function() { if (this.el) this.el = null }
		}
		// slide current layer out of view
		oldLyr.slideTo(oldLyr.xOff, null, slide_out_speed, -1);
	}
	else
	{
		// if no layer currently in view
    	newLyr = dynObj.getInstance(id);
    	newLyr.slideTo(0, null, slide_in_speed, -1);
  	}
	curGlideLyr = id;
}

function slideIntoView() {
  var glideLyr = dynObj.getInstance(this.id);
  glideLyr.slideTo(2, null, 600, -1);
}

function slideOutOfView(e) {
  var glideLyr = dynObj.getInstance(this.id);
	e = e? e: window.event;
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if ( toEl != glideLyr.el && !contained(toEl, glideLyr.el) )
	  glideLyr.slideTo( -(glideLyr.w - glideLyr.xOff), null, 500, -1);
}


// returns true if oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}