/*
		dw_lyr_scroll.js
		requires dw_scroll.js
		version date: August 2002
		contains functions for "scrolling layer content"
		i.e., for onmouseover and onclick scrolling
		
		This code is from Dynamic Web Coding 
    at http://www.dyn-web.com/
    Copyright 2001-2 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.		
*/

var scrTimer = 20; // interval between calls to scroll onmouseover
var scrTmId=0;	// for setTimeouts

// control scroll speed/amount
var jump_inc = 100; // amount of scroll per click (jump functions)
// amount of scroll per loop during onmouseover
var movr_inc = 20;		// higher number for faster scroll

function stopScroll() {
	clearTimeout(scrTmId);
	scrTmId = 0;
	movr_inc = 1;
}

/////////////////////////////////////////////////////////////////////
// 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: 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.
/////////////////////////////////////////////////////////////////////
function loadScrLyr(num,lyr,id) {
	if (!pgLoaded) return; // avoid not loaded errors
	if (typeof wndo[num].cnt != "undefined") wndo[num].cnt.hide();
	wndo[num].cnt = new dw_scrollObj(lyr,id);
	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
} 


// These functions are for onmouseover scrolling
function inchDown(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.top);
	if (y>-wndo[num].maxY) { 
		wndo[num].cnt.shiftBy(0,-inc);
		scrTmId = setTimeout("inchDown("+num+","+inc+")",scrTimer);	
	}
}

function inchUp(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.top);
	if (y<0) { 
		wndo[num].cnt.shiftBy(0,inc);
		scrTmId = setTimeout("inchUp("+num+","+inc+")",scrTimer);	
  }
}

function inchRight(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.left);	
	if (y>-wndo[num].maxX) { 
		wndo[num].cnt.shiftBy(-inc,0);
		scrTmId = setTimeout("inchRight("+num+","+inc+")",scrTimer);	
	}
}

function inchLeft(num,inc) {
	if (!pgLoaded||!wndo[num]) return;
	if (scrTmId) clearTimeout(scrTmId);
	var y = parseInt(wndo[num].cnt.css.left);
	if (y<0) { 
		wndo[num].cnt.shiftBy(inc,0);
		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); 
	}
}
//


var currXpos  = 0
var inc = 1

function slideInit(num) {
	currXpos = parseInt(wndo[num].cnt.css.left);
}

function slide(num,xpos) {
	stopScroll();
	// alter depending on image size...
	xpos = (xpos * 200) // - 200
	inc = 1;
	inc = 4 * (currXpos / xpos)
	if (currXpos > xpos) {
		//scroll right
		slideRight(num,xpos)
	} else if (currXpos < xpos) {
		//scroll left
		slideLeft(num,xpos);
	} else {
		stopScroll();
		//status = 'Stopped: currXpos = ' + currXpos;
	}
}

function slideLeft(num,xpos){
	inc = inc + movr_inc;
	if ( currXpos < xpos ) {
		status = 'Scroll left: currXpos = ' + currXpos + ' - xpos = ' + xpos + ' - inc = ' + inc;
		if ((currXpos + inc) > xpos) {
				inc = (xpos - currXpos)
				//status = 'Scroll left: currXpos = ' + currXpos + ' - xpos = ' + xpos + ' - inc = ' + inc;
				//stopScroll;
				//return;
		}
		jumpRight(num, inc);
		
		currXpos = currXpos + inc;
		scrTmId = setTimeout("slideLeft("+num+","+xpos+")",scrTimer);	
	} else {
		stopScroll();
		//jumpRight(num, xpos - currXpos);
		//currXpos = xpos;
		//status = 'Scroll left: currXpos = ' + currXpos + ' - xpos = ' + xpos + ' - inc = ' + inc;
	}
}

function slideRight(num,xpos){
	inc = inc + movr_inc;
	if ( currXpos > xpos ) {
		//status = 'Scroll Right: currXpos = ' + currXpos + ' - xpos = ' + xpos + ' - inc = ' + inc;
		if ((currXpos - inc) < xpos) {
				inc = (currXpos - xpos)
				status = 'Scroll Right: currXpos = ' + currXpos + ' - xpos = ' + xpos + ' - inc = ' + inc;
		}
		jumpLeft(num, inc);
		currXpos = currXpos - inc;
		scrTmId = setTimeout("slideRight("+num+","+xpos+")",scrTimer);	
	} else {
		stopScroll();
		//jumpLeft(num, xpos - currXpos);
		//currXpos = xpos;
		//status = 'Scroll Right: currXpos = ' + currXpos + ' - xpos = ' + xpos + ' - inc = ' + inc;
	}
}



