var clipTop = 0;
var clipWidth = 0;
var clipBottom = 0;
var clipHeight = 0;
var distfromtop = 0;     //distfromtop = -clipTop;
var clipareaHeight = 0;
var containerScrollboxHeight;
var 	DHTML = (document.getElementById || document.all || document.layers);
var time,stepsize,theTime,theHeight,DHTML,clipratio,scrollboxScale;

//-----arbeit 20070304 ---------------------------------------------------start
function initpage(){
		//initvariables();
	try {
		var objcliparea = new getObj('cliparea');
		if (!objcliparea){
		} else {
			initvariables();
		}
	} 
	catch(er) {
	}
}

function initvariables(){

	if (!DHTML) return;
	var objcontaintercliparea = new getObj('container_cliparea');
	var objcliparea = new getObj('cliparea');
	var objcontainerscrollbox = new getObj('containerscrollbox');
	var objscrollbox = new getObj('scrollbox');
	var objcontainerscrollbar = new getObj('containerscrollbar');
	
	clipWidth = objcontaintercliparea.obj.offsetWidth;
	clipBottom = objcontaintercliparea.obj.offsetHeight;
	clipHeight = objcontaintercliparea.obj.offsetHeight;
	
	clipareaHeight = objcliparea.obj.offsetHeight;	
	containerScrollboxHeight = objcontainerscrollbox.obj.offsetHeight
	
	clipratio = clipHeight / clipareaHeight
	scrollboxScale = containerScrollboxHeight / clipHeight
	scrollboxScale = scrollboxScale * clipratio
	
	if (document.getElementById || document.all)	{
		objcliparea.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		clipratio = (clipBottom)  / (clipareaHeight)
		if (clipratio < 1){
			objscrollbox.style.height = Math.round(clipratio * containerScrollboxHeight);
		} else {
			objscrollbox.style.height = containerScrollboxHeight;
			containerscrollbar.style.visibility="hidden";
		}
	}
	if (document.getElementById || document.all)	{
		//alert (clipWidth + "/" + clipBottom);
	} 
}

//-----arbeit 20070304 ---------------------------------------------------ende


function scrollayer(layername,amt,tim){	
	if (!DHTML) return;
	thelayer = new getObj(layername); //thelayer = cliparea
	if (!thelayer) return;	
	stepsize = amt;
	theTime = tim;	
	realscroll();
}
function realscroll(){	
	if (!DHTML) return;
	var objscrollbox = new getObj('scrollbox');
	if (clipareaHeight-clipBottom < stepsize){
		realamount = clipareaHeight-clipBottom;
	} else if (clipTop < -stepsize){
		realamount = -clipTop;
	} else {
		realamount = stepsize;
	}
	clipTop += realamount;	
	clipBottom += realamount;	
	distfromtop -= realamount;	
	if ( clipBottom > clipareaHeight || clipTop < 0)	{	
		clipTop -= realamount;
		clipBottom -= realamount;		
		distfromtop += realamount;		
	}	
	if (document.getElementById || document.all)	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;		
		thelayer.style.top = distfromtop + 'px';
		objscrollbox.style.top = Math.round(scrollboxScale * clipTop) +'px';	
	}
	time = setTimeout('realscroll()',theTime);
}


function stopscroll(){
	if (time) clearTimeout(time);
}
//drag scrollbar----------------------------------------------

var ddEnabled=false;
var scrollboxOldPosition;
var itsmescrollbox;

function startdrag(e) { 
	if(!document.all) { 
		objekt=e.target.id; 		
	} else { 
		objekt=event.srcElement.id; 
	} 
	if(objekt) { 
		if (objekt=="scrollbox"){
			itsmescrollbox=1;
		} else {
			itsmescrollbox=0;
		}
		if(!document.all) {
			event=e;
		} 
		startY=event.clientY;	
		ddEnabled=true;
		var objscrollbox = new getObj('scrollbox');
		scrollboxOldPosition = (parseInt(objscrollbox.style.top));
		if (isNaN(scrollboxOldPosition)){
			scrollboxOldPosition = 0;
		}	
		document.onmousemove=realdrag;	 
	} 
}
function realdrag(e) {
	if (ddEnabled){
		if(itsmescrollbox==1) {
			if(!document.all) {
				event=e;
			} 
			Ywert=event.clientY-startY;
			document.getElementById(objekt).style.top = scrollboxOldPosition + Ywert;
			if (Ywert > 0){		
				if (parseInt(document.getElementById(objekt).style.top) + parseInt(document.getElementById(objekt).style.height) > containerScrollboxHeight){
					window.status = parseInt(document.getElementById(objekt).style.top) + parseInt(document.getElementById(objekt).style.height);
					document.getElementById(objekt).style.top =  containerScrollboxHeight - parseInt(document.getElementById(objekt).style.height) ;
				}
			} else {
				if (parseInt(document.getElementById(objekt).style.top)<0){
					document.getElementById(objekt).style.top = 0;
				}
			}			
			wkstepsize = Math.round((parseInt(document.getElementById(objekt).style.top))/scrollboxScale);
			realdragdriven('cliparea',wkstepsize);
			
		}
	} 
	return false;
}  
function realdragdriven(layername,amt){	
	if (!DHTML) return;
	thelayer = new getObj(layername); //thelayer = cliparea
	if (!thelayer) return;	
	stepsize = -amt;
	clipTop = -stepsize;	
	clipBottom = clipTop+clipHeight;	
	distfromtop = stepsize;
	if (document.getElementById || document.all)	{
		clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,0)';
		thelayer.style.clip = clipstring;		
		thelayer.style.top = distfromtop + 'px';
	}
}
function stopdrag(){
	ddEnabled=false;
}

document.onmousedown=startdrag; 
document.onmouseup=stopdrag;
//document.onmouseout=stopdrag;

function getObj(name)
{
  if (document.getElementById)
  {
    this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
    this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}