//We wrap all the code in an object so that it doesn't interfere with any other code
var scroller = {
  init:   function() {

    //collect the variables
    scroller.docH = document.getElementById("content").offsetHeight;
    scroller.contH = document.getElementById("scrollWrapper").offsetHeight;
    scroller.scrollAreaH = document.getElementById("scrollAreaInner").offsetHeight;
      
    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)
    if ( scroller.contH >= scroller.docH ) {
    	//	Als er niet gescrolled hoeft te worden, dan maar weg met dat kreng!
    	scroller.scrollH = 0;							
    	document.getElementById("scroller").style.display = "none";
    }
    else {
	    scroller.scrollH = ( (scroller.contH * scroller.scrollAreaH) / scroller.docH );
    //if(scroller.scrollH < 15) scroller.scrollH = 15;
	    document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px";
    } 
    
    //what is the effective scroll distance once the scoller's height has been taken into account
    scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
    
    //make the scroller div draggable
    Drag.init(document.getElementById("scroller"),null,0,0,0,scroller.scrollDist);
    
    //add ondrag function
    document.getElementById("scroller").onDrag = function (x,y) {
      var scrollY = parseInt(document.getElementById("scroller").style.top);
      var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
      document.getElementById("content").style.marginTop = docY + "px";
    }
  }
}


scrollUp = function() {
	//	Top ophalen:
	var top = $('scroller').style.top;
	top = parseInt( top.replace('px','') );
	//	Hoogte ophalen:
	var height = $('scroller').style.height;
	height = parseInt( height.replace('px','') );

	if ( top > 0 ) {
		//	Eerste de scroller:
		var new_top = top - Math.floor( 10 , top );
		$('scroller').style.top = new_top + 'px';
		//	Dan de inhoud:
		var dist = Math.round($('scrollAreaInner').offsetHeight - parseInt( $('scroller').style.height ) );
		var docY = 0 - ( new_top * ($('content').offsetHeight - $('scrollWrapper').offsetHeight) / dist);
		$('content').style.marginTop = docY + "px";
	} // if
}


scrollDown = function() {
	//	Top ophalen:
	var top = $('scroller').style.top;
	top = parseInt( top.replace('px','') );
	//	Hoogte ophalen:
	var height = $('scroller').style.height;
	height = parseInt( height.replace('px','') );
	//	Maximale waarde ophalen:
	var max = $('scrollAreaInner').offsetHeight;

	if ( ( max - height ) > top ) {
		//	Eerst de scroller:
		var new_top = top + Math.floor( 10 , ( max - height - top ) );
		$('scroller').style.top = new_top + 'px';
		//	Dan de inhoud:
		var dist = Math.round($('scrollAreaInner').offsetHeight - parseInt( $('scroller').style.height ) );
		var docY = 0 - ( new_top * ($('content').offsetHeight - $('scrollWrapper').offsetHeight) / dist);
		$('content').style.marginTop = docY + "px";
	} // if
}

adjustScroller = function(){
	
	scroller.init();
	
}

onload = scroller.init;
/*
var scroller = {
  init:   function() {

    //collect the variables
    divs = document.getElementsByTagName('div');
    
    var divContent;
    for( i = 0; i < divs.length; i++ )
    	if( divs[i].className == 'content' )
    		divContent = divs[i];
    
    scroller.docH = divContent.offsetHeight;
    scroller.contH = document.getElementById("text").offsetHeight;
    scroller.scrollAreaH = document.getElementById("scrollArea").offsetHeight;
      
    //calculate height of scroller and resize the scroller div
    //(however, we make sure that it isn't to small for long pages)
    scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
    //if(scroller.scrollH < 15) scroller.scrollH = 15;
    document.getElementById("scroller").style.height = Math.round(scroller.scrollH) + "px";
    
    //what is the effective scroll distance once the scoller's height has been taken into account
    scroller.scrollDist = Math.round(scroller.scrollAreaH-scroller.scrollH);
    
    //make the scroller div draggable
    Drag.init(document.getElementById("scroller"),null,0,0,-1,scroller.scrollDist);
    
    //add ondrag function
    document.getElementById("scroller").onDrag = function (x,y) {
      var scrollY = parseInt(document.getElementById("scroller").style.top);
      var docY = 0 - (scrollY * (scroller.docH - scroller.contH) / scroller.scrollDist);
      divContent.style.top = docY + "px";
    }
  }
}

Event.observe(window, 'load', scroller.init );
*/
