/*
		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 stopScroll2(num) {
  if (pgLoaded && wndo2[num]) {
  	clearTimeout(wndo2[num].scrTmId);
  	wndo2[num].scrTmId = 0;
  }
}

/////////////////////////////////////////////////////////////////////
// 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 loadScrLyr2(num,lyr,id) {
	if (!pgLoaded) return; // avoid not loaded errors
	if (typeof wndo2[num].cnt != "undefined") wndo2[num].cnt.hide();
  wndo2[num].scrTmId = 0;
	wndo2[num].cnt = new dynObj(lyr);
  // mainly for ns6+/mozilla when scrolling horizontally
  if (id && document.getElementById) 
    wndo2[num].cnt.width = document.getElementById(id).offsetWidth;
	wndo2[num].cnt.show();
	wndo2[num].cnt.shiftTo(0,0);	// restore top/left to 0 
	wndo2[num].maxX = wndo2[num].cnt.width - wndo2[num].width;
	wndo2[num].maxY = wndo2[num].cnt.height - wndo2[num].height
} 

// These functions are for onmouseover scrolling
function inchDown2(num,inc) {
	if (!pgLoaded||!wndo2[num]) return;
	if (wndo2[num].scrTmId) clearTimeout(wndo2[num].scrTmId);
	var y = parseInt(wndo2[num].cnt.css.top);
	if (y>-wndo2[num].maxY) { 
    if ((y-inc)>(-wndo2[num].maxY)) wndo2[num].cnt.shiftBy(0,-inc);
		else wndo2[num].cnt.shiftBy(0,-(wndo2[num].maxY-Math.abs(y)));
		wndo2[num].scrTmId = setTimeout("inchDown("+num+","+inc+")",scrTimer);	
	}
}

function inchUp2(num,inc) {
	if (!pgLoaded||!wndo2[num]) return;
	if (wndo2[num].scrTmId) clearTimeout(wndo2[num].scrTmId);
	var y = parseInt(wndo2[num].cnt.css.top);
	if (y<0) { 
    if ((y+inc)<=0) wndo2[num].cnt.shiftBy(0,inc); 
		else wndo2[num].cnt.shiftBy(0,-y);
		wndo2[num].scrTmId = setTimeout("inchUp("+num+","+inc+")",scrTimer);	
  }
}

function inchRight2(num,inc) {
	if (!pgLoaded||!wndo2[num]) return;
	if (wndo2[num].scrTmId) clearTimeout(wndo2[num].scrTmId);
	var x = parseInt(wndo2[num].cnt.css.left);	
	if (x>-wndo2[num].maxX) { 
    if ((x-inc)>(-wndo2[num].maxX)) wndo2[num].cnt.shiftBy(-inc,0);
		else wndo2[num].cnt.shiftBy(-(wndo2[num].maxX-Math.abs(x)),0);
		wndo2[num].scrTmId = setTimeout("inchRight2("+num+","+inc+")",scrTimer);	
	}
}

function inchLeft2(num,inc) {
	if (!pgLoaded||!wndo2[num]) return;
	if (wndo2[num].scrTmId) clearTimeout(wndo2[num].scrTmId);
	var x = parseInt(wndo2[num].cnt.css.left);
	if (x<0) { 
    if ((x+inc)<=0) wndo2[num].cnt.shiftBy(inc,0); 
		else wndo2[num].cnt.shiftBy(-x,0); 
		wndo2[num].scrTmId = setTimeout("inchLeft2("+num+","+inc+")",scrTimer);	
  }
}


// These functions are for onclick scrolling
function jumpDown2(num,jump) {
	if (!pgLoaded||!wndo2[num]) return;
	var y = parseInt(wndo2[num].cnt.css.top);
	if (y>(-wndo2[num].maxY)) { 
		if ((y-jump)>(-wndo2[num].maxY)) wndo2[num].cnt.shiftBy(0,-jump);
		else wndo2[num].cnt.shiftBy(0,-(wndo2[num].maxY-Math.abs(y)));	
  }
}

function jumpUp2(num,jump) {
	if (!pgLoaded||!wndo2[num]) return;
	var y = parseInt(wndo2[num].cnt.css.top);
	if (y<0) { 
		if ((y+jump)<=0) wndo2[num].cnt.shiftBy(0,jump); 
		else wndo2[num].cnt.shiftBy(0,-y); 
	}
}

function jumpRight2(num,jump) {
	if (!pgLoaded||!wndo2[num]) return;
	var x = parseInt(wndo2[num].cnt.css.left);
	if (x>(-wndo2[num].maxX)) {
		if ((x-jump)>(-wndo2[num].maxX)) wndo2[num].cnt.shiftBy(-jump,0);
		else wndo2[num].cnt.shiftBy(-(wndo2[num].maxX-Math.abs(x)),0);	
  }
}

function jumpLeft2(num,jump) {
	if (!pgLoaded||!wndo2[num]) return;
	var x = parseInt(wndo2[num].cnt.css.left);
	if (x<0) { 
		if ((x+jump)<=0) wndo2[num].cnt.shiftBy(jump,0); 
		else wndo2[num].cnt.shiftBy(-x,0); 
	}
}

// Functions for glide-scrolling onclick  
// NOTE: dw_slide.js needed for glide-scroll
function glideRight2(num,dist) {
	if (!pgLoaded||!wndo2[num]) return;
	var x = parseInt(wndo2[num].cnt.css.left);
	if (x>(-wndo2[num].maxX)) {
		if ((x-dist)>(-wndo2[num].maxX)) wndo2[num].cnt.slideBy(-dist,0,500);
		else wndo2[num].cnt.slideBy(-(wndo2[num].maxX-Math.abs(x)),0,500);	
  }
}

function glideLeft2(num,dist) {
	if (!pgLoaded||!wndo2[num]) return;
	var x = parseInt(wndo2[num].cnt.css.left);
	if (x<0) { 
		if ((x+dist)<=0) wndo2[num].cnt.slideBy(dist,0,500); 
		else wndo2[num].cnt.slideBy(-x,0,500); 
	}
}

function glideDown2(num,dist) {
	if (!pgLoaded||!wndo2[num]) return;
	var y = parseInt(wndo2[num].cnt.css.top);
	if (y>(-wndo2[num].maxY)) { 
		if ((y-dist)>(-wndo2[num].maxY)) wndo2[num].cnt.slideBy(0,-dist,500);
		else wndo2[num].cnt.slideBy(0,-(wndo2[num].maxY-Math.abs(y)),500);	
  }
}

function glideUp2(num,dist) {
	if (!pgLoaded||!wndo2[num]) return;
	var y = parseInt(wndo2[num].cnt.css.top);
	if (y<0) { 
		if ((y+dist)<=0) wndo2[num].cnt.slideBy(0,dist,500); 
		else wndo2[num].cnt.slideBy(0,-y,500); 
	}
}
