// Layer shrine scroll functions v1.32 - 16/Oct/2000
// requires 'layer.js' to work!
// adapted from LargeMedia's 'dHtmlScrollFuncs.js' to work on Netscape 6
// + added some extra gimmicks
// (C) Mikko Karvonen 2000

Layer.prototype.scrollUp = LayerScrollUp;
Layer.prototype.scrollDown = LayerScrollDown;
Layer.prototype.doScroll = doLayerScroll;
Layer.prototype.resetScroll = resetScrollLayer;
Layer.prototype.resetButtons = resetScrollButtons;
Layer.prototype.initScroll = initScrollLayer;

var mouse_down = false;

function LayerScrollUp(e) {
	if ((is_nav && e.which != 1) || (is_ie && event.button != 1)) return false;
	mouse_down = true;
	scrollDOWN = false;
	sref = this.id.replace("ID","")+".scrollref";
	var s = eval(sref+"");
  if (s.upObjFast)
    if (this.id == s.upObjFast.id) s.speed = s.scrollspeedfast;
    else s.speed = s.scrollspeed;
	s.contentH = s.getContentHeight();
	if (s.imgUP && (s.imgDOWN == s.imgDOWNSTOP)) s.upObj.changeImage(s.imgUPname,s.imgUP);
	if (s.imgUPfast && (s.imgDOWNfast == s.imgDOWNSTOPfast)) s.upObjFast.changeImage(s.imgUPnamefast,s.imgUPfast);
	if (s.imgDOWN) s.downObj.changeImage(s.imgDOWNname,s.imgDOWN);
	if (s.imgDOWNfast) s.downObjFast.changeImage(s.imgDOWNnamefast,s.imgDOWNfast);
  OO = setInterval('doLayerScroll(sref)',s.scrolldelay);
	return false;
}

function LayerScrollDown(e) {
	if ((is_nav && e.which != 1) || (is_ie && event.button != 1)) return false;
	mouse_down = true;
	scrollDOWN = true;
	sref = this.id.replace("ID","")+".scrollref";
	var s = eval(sref+"");
  if (s.downObjFast)
    if (this.id == s.downObjFast.id) s.speed = s.scrollspeedfast;
    else s.speed = s.scrollspeed;
  s.contentH = s.getContentHeight();
	if (s.imgDOWN && (s.imgUP == s.imgUPSTOP)) s.downObj.changeImage(s.imgDOWNname,s.imgDOWN);
	if (s.imgDOWNfast && (s.imgUPfast == s.imgUPSTOPfast)) s.downObjFast.changeImage(s.imgDOWNnamefast,s.imgDOWNfast);
	if (s.imgUP) s.upObj.changeImage(s.imgUPname,s.imgUP);
	if (s.imgUPfast) s.upObjFast.changeImage(s.imgUPnamefast,s.imgUPfast);
	OO = setInterval('doLayerScroll(sref)',s.scrolldelay);
	return false;
}

function LayerScrollStop(e) {
	mouse_down = false;
	return true;
}

function doLayerScroll(scrollref) {
	var s = eval(scrollref+"");
	var amount;

	if (scrollDOWN) {
		amount = -s.speed;
		if (s.y < -s.contentH+s.clipBottom-s.clipTop+s.startY) {
			mouse_down = false;	//stops moving - out of bounds
			if (s.imgDOWNSTOP) s.downObj.changeImage(s.imgDOWNname,s.imgDOWNSTOP);
			if (s.imgDOWNSTOPfast) s.downObjFast.changeImage(s.imgDOWNnamefast,s.imgDOWNSTOPfast);
      s.downObj.outofbounds = true;
      if (s.downObjFast) s.downObjFast.outofbounds = true;
		}
	}
	else { // up
		amount = s.speed;
		if (s.y >= s.startY) {
			mouse_down = false;
			if (s.imgUPSTOP) s.upObj.changeImage(s.imgUPname,s.imgUPSTOP);
			if (s.imgUPSTOPfast) s.upObjFast.changeImage(s.imgUPnamefast,s.imgUPSTOPfast);
      s.upObj.outofbounds = true;
      if (s.upObjFast) s.upObjFast.outofbounds = true;
		}
	}

	if (mouse_down) {
    s.clipBy(null,-amount,null,-amount);
    s.moveBy(null,amount);
    s.downObj.outofbounds = false;
    if (s.downObjFast) s.downObjFast.outofbounds = false;
    s.upObj.outofbounds = false;
    if (s.upObjFast) s.upObjFast.outofbounds = false;
  }
	else clearInterval(OO);
}

function resetScrollLayer() {
	this.y = this.startY;
	this.x = this.startX;
	var l = this.clipLeft = this.startClipLeft;
	var t = this.clipTop = this.startClipTop;
	var r = this.clipRight = this.startClipRight;
	var b = this.clipBottom = this.startClipBottom;
	this.moveTo(this.x,this.y);
	this.clip(l,t,r,b);

  // fix the 'up' images
	if (this.imgUPSTOP)	this.upObj.changeImage(this.imgUPname,this.imgUPSTOP);
  this.upObj.outofbounds = true;
  if (this.upObjFast) {
    if (this.imgUPSTOPfast) this.upObjFast.changeImage(this.imgUPnamefast,this.imgUPSTOPfast);
    this.upObjFast.outofbounds = true;
  }

  // fix the 'down' images
  if (this.y < -this.getContentHeight()+this.clipBottom-this.clipTop+this.startY) {
		if (this.imgDOWNSTOP) this.downObj.changeImage(this.imgDOWNname,this.imgDOWNSTOP);
    this.downObj.outofbounds = true;
    if (this.downObjFast) {
		  if (this.imgDOWNSTOPfast) this.downObjFast.changeImage(this.imgDOWNnamefast,this.imgDOWNSTOPfast);
      this.downObjFast.outofbounds = true;
    }
	}
  else {
    if (this.imgDOWN) this.downObj.changeImage(this.imgDOWNname,this.imgDOWN);
    this.downObj.outofbounds = false;
    if (this.downObjFast) {
      if (this.imgDOWNfast) this.downObjFast.changeImage(this.imgDOWNnamefast,this.imgDOWNfast);
      this.downObjFast.outofbounds = false;
    }
  }
}
	
function resetScrollButtons() {
  if (this.y >= this.startY) {
		if (this.imgUPSTOP) this.upObj.changeImage(this.imgUPname,this.imgUPSTOP);
    this.upObj.outofbounds = true;
    if (this.upObjFast) {
		  if (this.imgUPSTOPfast) this.upObjFast.changeImage(this.imgUPnamefast,this.imgUPSTOPfast);
      this.upObjFast.outofbounds = true;
    }
	}
  else if (this.y < -this.getContentHeight()+this.clipBottom-this.clipTop+this.startY) {
		if (this.imgDOWNSTOP) this.downObj.changeImage(this.imgDOWNname,this.imgDOWNSTOP);
    this.downObj.outofbounds = true;
    if (this.downObjFast) {
		  if (this.imgDOWNSTOPfast) this.downObjFast.changeImage(this.imgDOWNnamefast,this.imgDOWNSTOPfast);
      this.downObjFast.outofbounds = true;
    }
	}
  else {
    if (this.imgUP) this.upObj.changeImage(this.imgUPname,this.imgUP);
    if (this.imgDOWN) this.downObj.changeImage(this.imgDOWNname,this.imgDOWN);
    this.upObj.outofbounds = false;
    this.downObj.outofbounds = false;
    if (this.upObjFast) {
      if (this.imgUPfast) this.upObjFast.changeImage(this.imgUPnamefast,this.imgUPfast);
      this.upObjFast.outofbounds = false;
    }
    if (this.downObjFast) {
      if (this.imgDOWNfast) this.downObjFast.changeImage(this.imgDOWNnamefast,this.imgDOWNfast);
      this.downObjFast.outofbounds = false;
    }
  }
}

function LayerImageLite(e) {
  sref = this.id.replace("ID","")+".scrollref";
  var s = eval(sref+"");
  if (this.id == s.downObj.id && s.imgDOWN && s.imgDOWNLITE && !s.downObj.outofbounds) s.downObj.changeImage(s.imgDOWNname,s.imgDOWNLITE);
  if (this.id == s.upObj.id && s.imgUP && s.imgUPLITE && !s.upObj.outofbounds) s.upObj.changeImage(s.imgUPname,s.imgUPLITE);
  if (s.downObjFast)
    if (this.id == s.downObjFast.id && s.imgDOWNfast && s.imgDOWNLITEfast && !s.downObjFast.outofbounds) s.downObjFast.changeImage(s.imgDOWNnamefast,s.imgDOWNLITEfast);
  if (s.upObjFast)
    if (this.id == s.upObjFast.id && s.imgUPfast && s.imgUPLITEfast && !s.upObjFast.outofbounds) s.upObjFast.changeImage(s.imgUPnamefast,s.imgUPLITEfast);
}

function LayerImageNormal(e) {
  mouse_down = false; // make sure the scrolling stops on mouseout in case the browser loses the mouseup event
  sref = this.id.replace("ID","")+".scrollref";
  var s = eval(sref+"");
  if (this.id == s.downObj.id && s.imgDOWN && s.imgDOWNLITE && !s.downObj.outofbounds) s.downObj.changeImage(s.imgDOWNname,s.imgDOWN);
  if (this.id == s.upObj.id && s.imgUP && s.imgUPLITE && !s.upObj.outofbounds) s.upObj.changeImage(s.imgUPname,s.imgUP);
  if (s.downObjFast)
    if (this.id == s.downObjFast.id && s.imgDOWNfast && s.imgDOWNLITEfast && !s.downObjFast.outofbounds) s.downObjFast.changeImage(s.imgDOWNnamefast,s.imgDOWNfast);
  if (s.upObjFast)
    if (this.id == s.upObjFast.id && s.imgUPfast && s.imgUPLITEfast && !s.upObjFast.outofbounds) s.upObjFast.changeImage(s.imgUPnamefast,s.imgUPfast);
}

function initScrollLayer(upobj,downobj,speed,delay,upname,downname,upimage,downimage,upstopimage,downstopimage,upliteimage,downliteimage,upobjfast,downobjfast,speedfast,upnamefast,downnamefast,upimagefast,downimagefast,upstopimagefast,downstopimagefast,upliteimagefast,downliteimagefast) {
	this.scrollspeed = (speed != null) ? speed : 5;
  this.speed = this.scrollspeed;
	this.scrolldelay = (delay != null) ? delay : 10;
	this.imgUPname = (upname != null) ? upname : false;
	this.imgDOWNname = (downname != null) ? downname : false;
	this.imgUP = (upimage != null) ? upimage : false;
	this.imgDOWN = (downimage != null) ? downimage : false;
	this.imgUPSTOP = (upstopimage != null) ? upstopimage : false;
	this.imgDOWNSTOP = (downstopimage != null) ? downstopimage : false;
  this.imgUPLITE = (upliteimage != null) ? upliteimage : false;
  this.imgDOWNLITE = (downliteimage != null) ? downliteimage : false;
	this.startY = this.y;
	this.startX = this.x;
	this.startClipTop = this.clipTop;
	this.startClipRight = this.clipRight;
	this.startClipBottom = this.clipBottom;
	this.startClipLeft = this.clipLeft;
	this.downObj = downobj;
	this.upObj = upobj;
  this.downObj.outofbounds = false;
  this.upObj.outofbounds = false;
	downobj.scrollref = this;
	upobj.scrollref = this;
  
	upobj.elm.onmousedown = LayerScrollUp;
	downobj.elm.onmousedown = LayerScrollDown;
	upobj.elm.onmouseup = LayerScrollStop;
	downobj.elm.onmouseup = LayerScrollStop;
	upobj.elm.onmouseover = LayerImageLite;
	downobj.elm.onmouseover = LayerImageLite;
	upobj.elm.onmouseout = LayerImageNormal;
	downobj.elm.onmouseout = LayerImageNormal;

	if (is_nav4) {
		upobj.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT);
		downobj.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT);
	}

  if (upobjfast != null && downobjfast != null) {
    this.scrollspeedfast = (speedfast != null) ? speedfast : 10;
    this.imgUPnamefast = (upnamefast != null) ? upnamefast : false;
    this.imgDOWNnamefast = (downnamefast != null) ? downnamefast : false;
    this.imgUPfast = (upimagefast != null) ? upimagefast : false;
    this.imgDOWNfast = (downimagefast != null) ? downimagefast : false;
    this.imgUPSTOPfast = (upstopimagefast != null) ? upstopimagefast : false;
    this.imgDOWNSTOPfast = (downstopimagefast != null) ? downstopimagefast : false;
    this.imgUPLITEfast = (upliteimagefast != null) ? upliteimagefast : false;
    this.imgDOWNLITEfast = (downliteimagefast != null) ? downliteimagefast : false;
    this.downObjFast = downobjfast;
    this.upObjFast = upobjfast;
    this.downObjFast.outofbounds = false;
    this.upObjFast.outofbounds = false;
    downobjfast.scrollref = this;
    upobjfast.scrollref = this;
	  upobjfast.elm.onmousedown = LayerScrollUp;
	  downobjfast.elm.onmousedown = LayerScrollDown;
	  upobjfast.elm.onmouseup = LayerScrollStop;
	  downobjfast.elm.onmouseup = LayerScrollStop;
	  upobjfast.elm.onmouseover = LayerImageLite;
	  downobjfast.elm.onmouseover = LayerImageLite;
	  upobjfast.elm.onmouseout = LayerImageNormal;
	  downobjfast.elm.onmouseout = LayerImageNormal;
	  if (is_nav4) {
		  upobjfast.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT);
		  downobjfast.elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER | Event.MOUSEOUT);
	  }
  }
  this.resetScroll(); // for setting the scroll button images correctly
}

