document.speed = 10; // 1 pix scroll every speed ms.
document.interval = new Array();

function GetObject(id) {
   if (document.getElementById) {
      return document.getElementById(id);
   }
   if (document.layers) {
      return eval('document.'+id);
   }
   if (document.all) {
      return eval('document.all.'+id);
   }
}

function getLeft(id) {
	obj = GetObject(id);
	var l = "";
	if(obj.style.left!=undefined && obj.style.left!=null) {
		l = obj.style.left;
	} else {
		l = "0";
	}
	l = l.replace("px","");
	l = l.replace(";","");

	return parseInt(l);
}

function getTop(id) {
	obj = GetObject(id);
	var t = "";
	if(obj.style.top!=undefined && obj.style.top!=null) {
		t = obj.style.top;
	} else {
		t = "0";
	}
	t = t.replace("px","");
	t = t.replace(";","");

	return parseInt(t);
}

function scroll(slidename,dir) {
	respath = eval("document.SL_" + slidename + "_obj.respath");
	obj = GetObject(slidename + "_thumbsdiv");
	l = getLeft(slidename + "_thumbsdiv");
	t = getTop(slidename + "_thumbsdiv");
	container = GetObject(slidename + "_thumbsdivcontainer");
	arrowb = GetObject(slidename + "_arrow_b");
	arrowf = GetObject(slidename + "_arrow_f");

	// update arrow icons
	if(dir=="left" || dir=="right") {
		if(l<=(container.offsetWidth-obj.offsetWidth)) {
			if(arrowf.src != (respath + "/arrow_f_fade.jpg")) arrowf.src = respath + "/arrow_f_fade.jpg";
		} else {
			if(arrowf.src != (respath + "/arrow_f.jpg")) arrowf.src = respath + "/arrow_f.jpg";
		}
		if(l>=0) {
			if(arrowb.src != (respath + "/arrow_b_fade.jpg")) arrowb.src = respath + "/arrow_b_fade.jpg";
		} else {
			if(arrowb.src != (respath + "/arrow_b.jpg")) arrowb.src = respath + "/arrow_b.jpg";
		}
	}
	if(dir=="top" || dir=="bottom") {
		if(t<=(container.offsetHeight-obj.offsetHeight)) {
			if(arrowf.src != (respath + "/arrow_f_fade.jpg")) arrowf.src = respath + "/arrow_f_fade.jpg";
		} else {
			if(arrowf.src != (respath + "/arrow_f.jpg")) arrowf.src = respath + "/arrow_f.jpg";
		}
		if(t>=0) {
			if(arrowb.src != (respath + "/arrow_b_fade.jpg")) arrowb.src = respath + "/arrow_b_fade.jpg";
		} else {
			if(arrowb.src != (respath + "/arrow_b.jpg")) arrowb.src = respath + "/arrow_b.jpg";
		}
	}
	// scroll
	switch(dir) {
	case "left":
		if(l<=(container.offsetWidth-obj.offsetWidth)) {
			stopScroll();
			return;
		}
		l = l - 3;
		break;
	case "right":
		if(l>=0) {
			stopScroll();
			return;
		}
		l = l + 3;
		break;
	case "bottom":
// alert("bottom " + t + "   " + container.offsetHeight + "   " + obj.offsetHeight);
		if(t<=(container.offsetHeight-obj.offsetHeight)) {
			stopScroll();
			return;
		}
		t = t - 3;
		break;
	case "top":
		if(t>=0) {
			stopScroll();
			return;
		}
		t = t + 3;
		break;
	}

	if(dir=="left" || dir=="right") obj.style.left = l+"px";
	if(dir=="top" || dir=="bottom") obj.style.top = t+"px";
}

function startScroll(slidename,dir) {
	document.interval[slidename] = setInterval("scroll(\"" + slidename + "\",\"" + dir + "\")",document.speed);
}

function stopScroll(slidename) {
	clearInterval(document.interval[slidename]);
}
