//		Script: ToolBox: Dragable ScrollBar
//		------------------------------------------------------
//		This code is property of:
//
//		©	Faber+Partner
//			Rothenburger Straße 43
//			01099 Dresden
//			Tel: 0351 / 84 389 700
//			Fax: 0351 / 84 389 702
//			www.Faber-Partner.de
//
//		and may not be used without written permission.
//		Neither for private nor for commercial use. This
//		prohibition does also include any open source
//		projects.
//
//		Violation will be at least EUR 30.000
//
//		Author:	Claus Faber, September 2003
//
//	***********************************************************

var	gl_iSBOffsetTop=-1;
var	gl_iSBHeightMax=-1;

var	gl_iDragTop=-1;
var	gl_iSBLeft=-1;
var	gl_iSBWidth=-1;
var	gl_iDragHeight=-1;
var	gl_iSBMouseOver=false;
var	gl_iXStart=0;
var	gl_iYStartDrag=0;
var	gl_iYStartTxt=0;

var	gl_bSBDragging=false;
var	gl_fScrollDelta=0;

var	gl_iX=0;
var	gl_iY=0;
var	gl_iMenuIndex=-1;
var	gl_hScroll=-1;
var	gl_iScrollSpeed=50;
var	gl_iTxtTotalHeight=0;


function	pGetElement(sID)
{
	var p;
	if(gl_bIDDOM){
		p=document.getElementById(sID);//.style;
	}else	if(gl_bAllDOM){
		p=document.all(sID);//.style;
	}else{
		p=document.layers[sID];
	}
	
	return	p;
}

function	pGetImage(sID)
{
	if(gl_bNS4){
		return	document.layers['FPSBDragArea'].document.images[sID];
	}else{
		return	pGetElement(sID);
	}
}

function	pGetStyle(pElement)
{
	var	pStyle;
	if(gl_bIE){
		pStyle=pElement.style;
	}else	if(gl_bNS){
		if	(gl_bNS4){
			pStyle=pElement;
		}else{
			pStyle=pElement.style;
		}
	}else{
		pStyle=pElement.style;
	}
	return	pStyle;
}

function	pGetFloatArea()
{
	return	pGetElement('FPSBFloatArea');
}

function	pGetDragArea()
{
	return	pGetElement('FPSBDragArea');
}

function	SetElementTop(pElement, iY)
{
	var	pStyle=pGetStyle(pElement);
	if(gl_bIE){
		pStyle.pixelTop=iY;
	}else{
		pStyle.top=parseInt(iY);
	}
	return;
}

function	iGetElementTop(pElement)
{
	var	pStyle=pGetStyle(pElement);
	if(gl_bIE){
		return	pStyle.pixelTop;
	}else{
		return	parseInt(pStyle.top);
	}
}

function	iGetElementWidth(pElement)
{
	var	pStyle=pGetStyle(pElement);
	if(gl_bIE){
		return	pStyle.pixelWidth;
	}else{
		return	parseInt(pStyle.width);
	}
}

function	iGetElementLeft(pElement)
{
	var	pStyle=pGetStyle(pElement);
	if(gl_bIE){
		return	pStyle.pixelLeft;
	}else{
		return	parseInt(pStyle.left);
	}
}



function	SetElementHeight(pElement, iY)
{
	var	pStyle=pGetStyle(pElement);
	if(gl_bIE){
		pStyle.pixelHeight=iY;
	}else{
		pStyle.height=parseInt(iY);
	}
	return;
}


function	iGetElementHeight(pElement)
{
	var	pStyle=pGetStyle(pElement);
	if(gl_bIE){
		return	pStyle.pixelHeight;
	}else	if(gl_bNS4){
		return	parseInt(pStyle.clip.height);
	}else{
		return	parseInt(pStyle.height);
	}
}


function	StopPropagation(event)
{
	if(gl_bIE){
	}else	if(gl_bNS4){
	}else{
		event.stopPropagation();
	}
	
	return;
}

function	PreventDefault(event)
{
	if(gl_bIE){
	}else	if(gl_bNS4){
	}else{
			event.preventDefault();
	}
	
	return;
}




	function	Scroll(iDY)
	{
		clearTimeout(gl_hScroll);
		DoMove(iDY);
		gl_iDragTop=iGetElementTop(pGetDragArea());
		gl_iYStartTxt=iGetElementTop(LstContent[gl_iMenuIndex].m_pCSS);
		gl_hScroll=setTimeout("Scroll("+iDY+")", gl_iScrollSpeed);
		
		return;
	}
	
	function	NoScroll()
	{
		clearTimeout(gl_hScroll);
	}	



function	bLeftMouseBtnPressed(event)
{
	if(gl_bNS){
		return	event.which==1;
	}else{
		return	event.button==1;
	}
}

function	GrabIt(event)
{
	if(gl_bIE){
		event=window.event;
	}else{
	}

	if(!bLeftMouseBtnPressed(event)){
	}else{
		gl_iX=event.clientX;
		gl_iY=event.clientY;
		if(gl_iX<gl_iSBLeft){
			//	out
		}else	if(gl_iX>gl_iSBLeft+gl_iSBWidth){
		}else	if(gl_iY<gl_iDragTop){
		}else	if(gl_iY>gl_iDragTop+gl_iDragHeight){
		}else{
			gl_iYStartTxt=iGetElementTop(LstContent[gl_iMenuIndex].m_pCSS);
			gl_iYStartDrag=event.clientY;
			gl_bSBDragging=true;
	
			StopPropagation(event);
			PreventDefault(event);
		}
	}
	return;
}

function	DoMove(iDY)
{
	var	iNewYDrag;
	var	iNewYTxt;
	if((iNewYDrag=gl_iDragTop+iDY)<gl_iSBOffsetTop){
		//	top position
		iNewYDrag=gl_iSBOffsetTop;
		iNewYTxt=0;
	}else	if(iNewYDrag+gl_iDragHeight>gl_iSBOffsetTop+gl_iSBHeightMax){
		//	bottom position
		iNewYDrag=gl_iSBOffsetTop+(gl_iSBHeightMax-gl_iDragHeight);
		iNewYTxt=-(gl_iTxtTotalHeight-gl_iSBHeightMax);
	}else{
		iNewYTxt=gl_iYStartTxt-(gl_fScrollDelta*iDY);
	}
	SetElementTop(pGetDragArea(), iNewYDrag);
	SetElementTop(LstContent[gl_iMenuIndex].m_pCSS, iNewYTxt);
	return;
}

//	-----------------------------------------------------------------
//	MoveIt()
//	Handler to move drag bar
//	29.09.03/cf	Start
//	-----------------------------------------------------------------

function	MoveIt(event)
{	
	var	bRet=true;
	var	iDY;
	
	if(gl_bIE){
		event=window.event;
	}else{
	}

	if(!gl_bSBDragging){
	}else{
		if((iDY=event.clientY-gl_iYStartDrag)==0){
			//	didn't move
		}else{
			DoMove(iDY);
		}
		bRet=false;
		StopPropagation(event);
	}
	event.returnValue=bRet;
	return bRet;
}

function	DropIt(event)
{
	var	bRet=true;
	if(gl_bIE){
		event=window.event;
	}else{
	}
	
	//	can't use bLeftMouseBtnPressed() to detect if mouse button is released
	//	mac returns event.button==0
	//	win returns event.button==1
	if(!gl_bSBDragging){
	}else{
		gl_bSBDragging=false;
		gl_iDragTop=iGetElementTop(pGetDragArea());
		gl_iYStartTxt=iGetElementTop(LstContent[gl_iMenuIndex].m_pCSS);
		bRet=false;
		StopPropagation(event);
	}
	event.returnValue=bRet;
	return;
}


function	InitScrollBar()
{
	var	pFloatArea;
	var	pDrag;
	
	if (typeof(document.addEventListener)=="function"){
		document.addEventListener("mousedown",GrabIt,true);
		document.addEventListener("mousemove",MoveIt,true);
		document.addEventListener("mouseup",DropIt,true);
	}else{
		document.onmousedown=GrabIt;
		document.onmousemove=MoveIt;
		document.onmouseup=DropIt;
	}

	pFloatArea=pGetFloatArea();
	pDrag=pGetDragArea();

	
	if(gl_bIE){
	}else{
	}
	gl_iSBLeft=iGetElementLeft(pDrag);
	gl_iSBWidth=iGetElementWidth(pDrag);
	gl_iDragTop=iGetElementTop(pDrag);
	gl_iSBHeightMax=iGetElementHeight(pFloatArea);
	gl_iSBOffsetTop=gl_iDragTop;
	return;
}

function AdjustDragHeight(iHeight)
{
	var	pImg;
	var	pDrag;
	var	pFloatArea;
	var	iH;
	
	pImg=pGetImage('FPSBDragImg');
	pDrag=pGetDragArea();
	pFloatArea=pGetFloatArea();

	//	set drag bar to top position
	SetElementTop(pDrag, gl_iSBOffsetTop);

	//	start position of text
	gl_iYStartTxt=0;
	//	no dragging at the beginning
	gl_bSBDragging=false;
	
	gl_iDragTop=iGetElementTop(pDrag);
	if(iHeight<iGetElementHeight(pFloatArea)){
		iH=gl_iSBHeightMax;
	}else{
		iH=(iGetElementHeight(pFloatArea)*iGetElementHeight(pFloatArea))/iHeight;
	}
	gl_fScrollDelta=iHeight/iGetElementHeight(pFloatArea);
	pImg.height=iH;
	gl_iDragHeight=pImg.height;
	SetElementHeight(pDrag, gl_iDragHeight);
	return;
}


		//	Comment:	Constructor for clContentEntry
		//	a clContentEntry wraps one text
		//	sIDDivParent	our DIV Tag is wrapped into a DIV Tag
		//					with the ID sIDDivParent
		//	sID				unique ID for that Text
		//	sHColor			hover color
	function	clContentEntry(sID, sPathAImg, sPathHImg, sPrefix, sAColor, sHColor)
	{
		this.m_sID=sID;
		this.m_sPathAImg=sPathAImg;
		this.m_sPathHImg=sPathHImg;
		this.m_sAColor=sAColor;
		this.m_sHColor=sHColor;
		this.m_sPrefix=sPrefix;

		if(gl_bIDDOM){
			this.m_pCSS=document.getElementById(sPrefix+this.m_sID);//.style;
		}else	if(gl_bAllDOM){
			this.m_pCSS=document.all(sPrefix+this.m_sID);//.style;
		}else{
			this.m_pCSS=document.layers['FPText'].document.layers[sPrefix+this.m_sID];
		}
		return;
	}
	
	//	-----------------------------------------------------------------
	//	set hover state (change image and change text color) for 
	//	element specified by sID
	//	sID
	//	iIn			unused
	//	sImgSrcID	ID of the source image to be replaced.
	//				set ="" if each image has it's own source image (like sub navi
	//				elements for Ops.Salo)
	//	sLayer		NS4.7 only
	//	-----------------------------------------------------------------
	function	ChangeImage(sID, iIn, sImgSrcID, sLayer)
	{
		var	pCSS;
		var	pImg;
		var	i;
		var	sCID;
		

		for(i=1;i<=LstContent.length-1;i++){

			sCID=LstContent[i].m_sID;
//			alert(LstContent[i].m_sPathHImg);

			if(LstContent[i].m_sPathHImg==""){
				//	no hover image specified -> done
			}else{
				if(sImgSrcID==""){
					//	there's no source image specified -> take from array
					sImgSrc="Img"+sCID;
				}else{
					sImgSrc="Img"+sImgSrcID;
				}
				if(gl_bNS4){
					pCSS=0;
					pImg=document.layers[sLayer].document.images[sImgSrc];
				}else{
					if(pGetElement("Btn"+sCID)==0){
						pCSS=0;
					}else{
						pCSS=pGetStyle(pGetElement("Btn"+sCID));
					}
					pImg=pGetElement(sImgSrc);
				}

				if(sCID==sID){
					if(LstContent[i].m_sPathHImg==""){
					}else{
						pImg.src=LstContent[i].m_sPathHImg;
					}
					if(pCSS==0){
					}else{
						pCSS.color=LstContent[i].m_sHColor;
					}
				}else{
					if(sImgSrcID!=""){
						//	we're using a dummy image -> do not reactivate that dummy image
					}else	if(LstContent[i].m_sPathAImg==""){
					}else{
						pImg.src=LstContent[i].m_sPathAImg;
					}
					if(pCSS==0){
					}else{
						pCSS.color=LstContent[i].m_sAColor;
					}
				}	//	endif
			}	//	endif no hover image specified
		}	//	next
		return;
	}
	
	function	ChangeImagePlain(sRoot, sName, sTarget, sLayer)
	{
		var	pI;
//		sName=sRoot+"images/GER/"+sName;
		sName=sRoot+"images/"+sName;
		if(gl_bNS4){
			pI=document.layers[sLayer].document.images[sTarget];
		}else{
			pI=document.images[sTarget];
		}
		pI.src=sName;
		return;
	}

	function	DisplayText(sID)
	{
		var i;
		var	sI;
		var	pStyle;
		gl_iMenuIndex=-1;
		for(i=1;i<=LstContent.length-1;i++){
			if(sID==LstContent[i].m_sID){
				sDIVID=LstContent[i].m_sPrefix+LstContent[i].m_sID;
				if(gl_bIE){
					gl_iTxtTotalHeight=pGetElement(sDIVID).offsetHeight;
				}else{
					gl_iTxtTotalHeight=2500;
				}
				AdjustDragHeight(gl_iTxtTotalHeight);
				pStyle=pGetStyle(LstContent[i].m_pCSS);
				pStyle.visibility='visible';
				SetElementTop(LstContent[i].m_pCSS, 0);
				gl_iMenuIndex=i;
			}else{
				pStyle=pGetStyle(LstContent[i].m_pCSS);
				pStyle.visibility='hidden';
			}
		}	//	next
	
		return;
	}
	