/*
		dw_scroll.js
		requires dw_core.js
		last revised: March 2003
		Contains functions for "scrolling layer content"
		i.e., for onmouseover and onclick scrolling

    Functions now included for glide-scroll onclick
    which requires dw_slide.js

		This code is from Dynamic Web Coding
    at http://www.dyn-web.com/
    Copyright 2001-3 by Sharon Paine
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    Permission granted to use this code
    as long as this entire notice is included.
*/

///////////////////////////////////////////////////////////////////////////////
//  NOTE: dynObj in dw_core.js now used for wndo and scrolling content objects.
//  Argument for creating wndo objects:	id of wndo div.
//	Arguments for creating content (done in loadScrLyr function):
//	id of content div, id of html element that contains content.
//	NOTE: Netscape 6 needs that html container and its id
//	in order to get width for horizontal scrolling.
//	If only using vertical scrolling, that extra container
//	is not necessary.
//	You can set left/top in style sheet or pass it to constructor.
//	Width/height (and clip) need to be set in style sheet
//	(opera and ns4 can't reflow content)
///////////////////////////////////////////////////////////////////////////////

var scrTimer = 20; // interval between calls to scroll onmouseover

function stopScroll(num) {
  if (pgLoaded && wndo[num]) {
  	clearTimeout(wndo[num].scrTmId);
  	wndo[num].scrTmId = 0;
  }
}


function getElement(id) {
	if(document.getElementById)
		return document.getElementById(id);
	else if(document.all)
		return document.all[id];
	else if(document.layers)
		return getLyrRef(id, document);
	else
		return null;
}
/////////////////////////////////////////////////////////////////////
// loadScrLyr function: loads scrollable content div(s)
//	arg's: wndo array number, id of scrollable div,
//	and id of table or other html element that contains div content.
//	NOTE: Ns6+/Mozilla need that html container and its id
//	in order to get width for horizontal scrolling.
//	If only using vertical scrolling, that extra container
//	is not necessary.
/////////////////////////////////////////////////////////////////////
function loadScrLyr(num,lyr,id) {
	if (!pgLoaded) return; // avoid not loaded errors
	if (typeof wndo[num].cnt != "undefined") wndo[num].cnt.hide();
  wndo[num].scrTmId = 0;
	wndo[num].cnt = new dynObj(lyr);
  // mainly for ns6+/mozilla when scrolling horizontally
	if (id && document.getElementById)
		wndo[num].cnt.width = document.getElementById(id).offsetWidth;
	wndo[num].cnt.show();
	wndo[num].cnt.shiftTo(0,0);	// restore top/left to 0
	wndo[num].maxX = wndo[num].cnt.width - wndo[num].width;
	wndo[num].maxY = wndo[num].cnt.height - wndo[num].height;

	var gerard = getElement("gerard_majax");
	if(gerard) {
		if(wndo[num].maxY < 0) {
			// Gerard is a magician, he disappears !
			// By magic !
			gerard.style.visibility = "hidden";
		} else {
			gerard.style.visibility = "visible";
		}
	}
}

// These functions are for onmouseover scrolling
function inchDown(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (wndo[num].scrTmId) clearTimeout(wndo[num].scrTmId);
	var y = parseInt(wndo[num].cnt.css.top);
	if (y>-wndo[num].maxY) {
    if ((y-inc)>(-wndo[num].maxY)) wndo[num].cnt.shiftBy(0,-inc);
		else wndo[num].cnt.shiftBy(0,-(wndo[num].maxY-Math.abs(y)));
		wndo[num].scrTmId = setTimeout("inchDown("+num+","+inc+")",scrTimer);
	}
}

function inchUp(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (wndo[num].scrTmId) clearTimeout(wndo[num].scrTmId);
	var y = parseInt(wndo[num].cnt.css.top);
	if (y<0) {
    if ((y+inc)<=0) wndo[num].cnt.shiftBy(0,inc);
		else wndo[num].cnt.shiftBy(0,-y);
		wndo[num].scrTmId = setTimeout("inchUp("+num+","+inc+")",scrTimer);
  }
}

function inchRight(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (wndo[num].scrTmId) clearTimeout(wndo[num].scrTmId);
	var x = parseInt(wndo[num].cnt.css.left);
	if (x>-wndo[num].maxX) {
    if ((x-inc)>(-wndo[num].maxX)) wndo[num].cnt.shiftBy(-inc,0);
		else wndo[num].cnt.shiftBy(-(wndo[num].maxX-Math.abs(x)),0);
		wndo[num].scrTmId = setTimeout("inchRight("+num+","+inc+")",scrTimer);
	}
}

function inchLeft(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (wndo[num].scrTmId) clearTimeout(wndo[num].scrTmId);
	var x = parseInt(wndo[num].cnt.css.left);
	if (x<0) {
    if ((x+inc)<=0) wndo[num].cnt.shiftBy(inc,0);
		else wndo[num].cnt.shiftBy(-x,0);
		wndo[num].scrTmId = setTimeout("inchLeft("+num+","+inc+")",scrTimer);
  }
}


// These functions are for onclick scrolling
function jumpDown(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var y = parseInt(wndo[num].cnt.css.top);
	if (y>(-wndo[num].maxY)) {
		if ((y-jump)>(-wndo[num].maxY)) wndo[num].cnt.shiftBy(0,-jump);
		else wndo[num].cnt.shiftBy(0,-(wndo[num].maxY-Math.abs(y)));
  }
}

function jumpUp(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var y = parseInt(wndo[num].cnt.css.top);
	if (y<0) {
		if ((y+jump)<=0) wndo[num].cnt.shiftBy(0,jump);
		else wndo[num].cnt.shiftBy(0,-y);
	}
}

function jumpRight(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var x = parseInt(wndo[num].cnt.css.left);
	if (x>(-wndo[num].maxX)) {
		if ((x-jump)>(-wndo[num].maxX)) wndo[num].cnt.shiftBy(-jump,0);
		else wndo[num].cnt.shiftBy(-(wndo[num].maxX-Math.abs(x)),0);
  }
}

function jumpLeft(num,jump) {
	if (!pgLoaded||!wndo[num]) return;
	var x = parseInt(wndo[num].cnt.css.left);
	if (x<0) {
		if ((x+jump)<=0) wndo[num].cnt.shiftBy(jump,0);
		else wndo[num].cnt.shiftBy(-x,0);
	}
}

// Functions for glide-scrolling onclick
// NOTE: dw_slide.js needed for glide-scroll
function glideRight(num,dist) {
	if (!pgLoaded||!wndo[num]) return;
	var x = parseInt(wndo[num].cnt.css.left);
	if (x>(-wndo[num].maxX)) {
		if ((x-dist)>(-wndo[num].maxX)) wndo[num].cnt.slideBy(-dist,0,500);
		else wndo[num].cnt.slideBy(-(wndo[num].maxX-Math.abs(x)),0,500);
  }
}

function glideLeft(num,dist) {
	if (!pgLoaded||!wndo[num]) return;
	var x = parseInt(wndo[num].cnt.css.left);
	if (x<0) {
		if ((x+dist)<=0) wndo[num].cnt.slideBy(dist,0,500);
		else wndo[num].cnt.slideBy(-x,0,500);
	}
}

function glideDown(num,dist) {
	if (!pgLoaded||!wndo[num]) return;
	var y = parseInt(wndo[num].cnt.css.top);
	if (y>(-wndo[num].maxY)) {
		if ((y-dist)>(-wndo[num].maxY)) wndo[num].cnt.slideBy(0,-dist,500);
		else wndo[num].cnt.slideBy(0,-(wndo[num].maxY-Math.abs(y)),500);
  }
}

function glideUp(num,dist) {
	if (!pgLoaded||!wndo[num]) return;
	var y = parseInt(wndo[num].cnt.css.top);
	if (y<0) {
		if ((y+dist)<=0) wndo[num].cnt.slideBy(0,dist,500);
		else wndo[num].cnt.slideBy(0,-y,500);
	}
}