/*
	Scrolls a banner div in any direction, with variable speed.
	Banner div must be contained within container div with overflow hidden. Also best to have banner div z-index higher than container div (2 and 1 for example).
	Example usage with body tag: onload="scroll('scrollcon','right',2);"
	If limit is provided, assumes a continuous scroll effect is required where first part of banner is showing at start and restarts after "limit" pixels.
	If in the above case the banner div height/width should normally be greater than the (container div + limit) height/width.
	If this is not so, scrolling starts with first part of banner revealed as normal, but then scrolls until last part of banner has disappered.
	If limit is omitted, assumes a classic marquee effect is required where banner is hidden at start and scrolls until end of banner has disappeared, then restarts.
	If limit is greater than banner div width/height (dependent on scrolling direction), limit is set to banner width/height as appropriate.
	Note that stposn and posn are NOT expected at initialisation - in fact if stposn is supplied (for a down or right scroll) it will prevent the correct checking of the limit variable.

		Copyright (c) 2007 - QNet Computer Services - All rights reserved.
	*/
function scroll(target,dirn,speed,limit,stposn,posn)
{
	var cid = document.getElementById(target);
	var pid = document.getElementById(target).offsetParent;

	if (typeof(dirn)=='undefined') dirn="left";
	if (typeof(speed)=='undefined') speed=3;

	if (dirn=="up")
	{
		if (typeof(limit)=='undefined')
		{
			limit = cid.clientHeight;
			stposn = pid.clientHeight;
		}
		if (limit>cid.clientHeight) limit=cid.clientHeight;
		if (typeof(stposn)=='undefined') stposn=0;
		if (typeof(posn)=='undefined') posn=stposn;
		cid.style.top = posn+'px'; /* px required for firefox to work reliably */
		if (posn > -limit) setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(posn-1)+")",speed * 25);
		else  setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(stposn-1)+")",speed * 25);
	}
	if (dirn=="down")
	{
		if (typeof(limit)=='undefined')
		{
			limit = pid.clientHeight;
			stposn = -cid.clientHeight;
		}
		//following can only occur when limit is defined during first pass, but stposn is not
		if (typeof(stposn)=='undefined')
		{
			stposn=-(cid.clientHeight-pid.clientHeight);
			//need to redefine limit since we are going in a downwards direction and measure is from "top" paramter
			if (cid.clientHeight<pid.clientHeight) limit=pid.clientHeight;
			else
			{
				limit = cid.clientHeight-(limit+pid.clientHeight);
				if (limit<0) limit=pid.clientHeight;
			}
			
		}
		if (typeof(posn)=='undefined') posn=stposn;
		cid.style.top = posn+'px'; /* px required for firefox to work reliably */
		if (posn < limit) setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(posn+1)+")",speed * 25);
		else  setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(stposn+1)+")",speed * 25);
	}
	if (dirn=="left")
	{
		if (typeof(limit)=='undefined')
		{
			limit = cid.clientWidth;
			stposn = pid.clientWidth;
		}
		if (limit>cid.clientWidth) limit=cid.clientWidth;
		if (typeof(stposn)=='undefined') stposn=0;
		if (typeof(posn)=='undefined') posn=stposn;
		cid.style.left = posn+'px'; /* px required for firefox to work reliably */
		if (posn > -limit) setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(posn-1)+")",speed * 25);
		else  setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(stposn-1)+")",speed * 25);
	}
	if (dirn=="right")
	{
		if (typeof(limit)=='undefined')
		{
			limit = pid.clientWidth;
			stposn = -cid.clientWidth;
		}
		//following can only occur when limit is defined during first pass, but stposn is not
		if (typeof(stposn)=='undefined')
		{
			stposn=-(cid.clientWidth-pid.clientWidth);
			//need to redefine limit since we are going in a rightwards direction and measure is from "left" paramter
			if (cid.clientWidth<pid.clientWidth) limit=pid.clientWidth;
			else
			{
				limit = cid.clientWidth-(limit+pid.clientWidth);
				if (limit<0) limit=pid.clientWidth;
			}
		}
		if (typeof(posn)=='undefined') posn=stposn;
		cid.style.left = posn+'px'; /* px required for firefox to work reliably */
		if (posn < limit) setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(posn+1)+")",speed * 25);
		else  setTimeout("scroll('"+target+"','"+dirn+"',"+speed+","+limit+","+stposn+","+(stposn+1)+")",speed * 25);
	}
/* UNCOMMENT BELOW TO DEBUG - writes info to div with id="infoo" */
/*
	var strg = ""
	+ "left: " + cid.style.left + "<br/>"
		+ "scrollWidth: " + cid.scrollWidth + "<br/>"
		+ "scrollHeight: " + cid.scrollHeight + "<br/>"
		+ "scrollTop: " + cid.scrollTop + "<br/>"
		+ "scrollLeft: " + cid.scrollLeft + "<br/>"
		+ "offsetWidth: " + cid.offsetWidth + "<br/>"
		+ "offsetHeight: " + cid.offsetHeight + "<br/>"
		+ "offsetTop: " + cid.offsetTop + "<br/>"
		+ "offsetLeft: " + cid.offsetLeft + "<br/>"
		+ "clientWidth: " + cid.clientWidth + "<br/>"
		+ "clientHeight: " + cid.clientHeight + "<br/>"		
		+ "Parent id: " + pid.id + "<br/>"
		+ "Parent scrollWidth: " + pid.scrollWidth + "<br/>"
		+ "Parent scrollHeight: " + pid.scrollHeight + "<br/>"
		+ "Parent offsetWidth: " + pid.offsetWidth + "<br/>"
		+ "Parent offsetHeight: " + pid.offsetHeight + "<br/>"
		+ "Parent clientWidth: " + pid.clientWidth + "<br/>"
		+ "Parent clientHeight: " + pid.clientHeight + "<br/>"
		+ "position: "+posn+"<br/>"
		+ "limit: "+limit+"<br/>";
		
	document.getElementById("infoo").innerHTML = strg;
*/
}