/*
	Doku startScroll:
	
	----------------------------------------------------------------------------
	sID			: inner DIV, which will be scrolled.			!! need CSS-Style "position:relative;" and "top:ABpx;" bzw. "left:BCpx;"
	sIDCont		: outer DIV, in which the Scoller is placed.	!! need CSS-Style "overflow:hidden;"
	direction	: direction to srcoll. r=right, l=left, t=up, d=down
	----------------------------------------------------------------------------
	
	!! Add the Function stopScroll() to the Event "onMouseOut"
	
*/


/* --- basic Scroller --- */
function startScroll(sID,sIDCont,direction){

	oSitedata.scroller.bDoScroll = false;
	if(!oSitedata.scroller.bDoScroll){
		oSitedata.scroller.bDoScroll = true;
		// directions: t,d = vertical ; l,r = horizontal
		if(direction == 't' || direction == 'd'){
			scrollVert(sID,sIDCont,direction);
		}else{
			scrollHoriz(sID,sIDCont,direction);
		}
	}
}
function stopScroll(){
	oSitedata.scroller.bDoScroll = false;
}


function scrollVert(sID,sIDCont,direction){

	obj = document.getElementById(sID);
	objCont = document.getElementById(sIDCont);
	
	if(direction != 't'){
		y = (oSitedata.scroller.sScrollPx*-1);
	}else{
		y = oSitedata.scroller.sScrollPx;
	}
	
	sTop = obj.style.top;
	iHeight = obj.offsetHeight*-1;
	iHeightCont = objCont.offsetHeight;
	iTop = parseInt(sTop.replace("px", ""));

	iNewTop = iTop + y;
	
	//alert("iHeightCont: " + iHeightCont + "\niTop: " + iTop +  "\niHeight: " + iHeight  + "\niNewTop: " + iNewTop);

	if(iNewTop <= 3 && iHeightCont < (iHeight*-1) && iNewTop-iHeightCont+oSitedata.scroller.sScrollPx > iHeight && oSitedata.scroller.bDoScroll){
		obj.style.top = iNewTop + "px";
		setTimeout("scrollVert('"+sID+"','"+sIDCont+"','"+direction+"')",oSitedata.scroller.sScrollspeed);
	}else{
		stopScroll();
	}
}
function scrollHoriz(sID,sIDCont,direction){

	obj = document.getElementById(sID);
	objCont = document.getElementById(sIDCont);
	
	if(direction != 'l'){
		x = (oSitedata.scroller.sScrollPx*-1);
	}else{
		x = oSitedata.scroller.sScrollPx;
	}

	sLeft = obj.style.left;	
	iWidth = obj.offsetWidth*-0.8;
	iWidthCont = objCont.offsetWidth;
	iLeft = parseInt(sLeft.replace("px", ""));

	iNewLeft = iLeft + x;
	//alert(iNewLeft + " <= 0 && " + iNewLeft + " >= " + (iWidth+(iWidthCont/2)) + " && " + oSitedata.scroller.bDoScroll);
	if(iNewLeft <= 3 && iWidthCont < (iWidth*-1) && iNewLeft-iWidthCont+oSitedata.scroller.sScrollPx > iWidth && oSitedata.scroller.bDoScroll){
		obj.style.left = iNewLeft + "px";
		setTimeout("scrollHoriz('"+sID+"','"+sIDCont+"','"+direction+"')",oSitedata.scroller.sScrollspeed);
	}else{
		stopScroll();
	}
}


/* --- unlimited Scroller --- */

function scrollVertUnlimited(sID,sIDCont,direction){

	obj = document.getElementById(sID);
	objCont = document.getElementById(sIDCont);
	
	if(direction != 't'){
		y = (oSitedata.scrollerUmlimited.sScrollPx*-1);
	}else{
		y = oSitedata.scrollerUmlimited.sScrollPx;
	}
	
	sTop = obj.style.top;
	iHeight = obj.offsetHeight*-1;
	iHeightCont = objCont.offsetHeight;
	iTop = parseInt(sTop.replace("px", ""));

	iNewTop = iTop + y;
	
	if(iNewTop <= 0 && iNewTop >= (iHeight/2) && oSitedata.scrollerUmlimited.bDoScroll){
		obj.style.top = iNewTop + "px";
		setTimeout("scrollVertUnlimited('"+sID+"','"+sIDCont+"','"+direction+"')",oSitedata.scrollerUmlimited.sScrollspeed);
	}else if(oSitedata.scrollerUmlimited.bDoScroll){
		obj.style.top = "0px";
		setTimeout("scrollVertUnlimited('"+sID+"','"+sIDCont+"','"+direction+"')",oSitedata.scrollerUmlimited.sScrollspeed);
	}else{
		stopScrollUnlimited();
	}
}
function stopScrollUnlimited(){
	oSitedata.scrollerUmlimited.bDoScroll = false;
}



