  var scrollInterval;
  var drag = -1;
  var mousePositionY = 0;
  var mousePositionYOld = 0;
  
  document.onmousemove = mouseMove;
  document.onmouseup = function () {drag=-1};
  
  function mouseWheel( event )
  {  	
  	if( !event )
  	  event = window.event;
  	  		
  	delta = 0;
  	
  	if( event.wheelDelta )
  	  delta = event.wheelDelta;
    else
  	  if( event.detail )
  		delta = event.detail * (-1);
  		
    if( delta < 0 )
      scroll( "down" );

    if( delta > 0 )
      scroll( "up" );    	
  }
  
  function mouseMove( event )
  {
    if (!event)
      event = window.event;

    mousePositionY = event.clientY;
    
  	if( drag >= 0 )
	{	 	
  	  if( drag < mousePositionY )
  	  {
	    scroll( "mouseDown" );
	    if( mousePositionYOld > mousePositionY )
	  		drag = mousePositionY;
	  }
	  else
	  {
	    scroll( "mouseUp" );
	    if( mousePositionYOld < mousePositionY )
	  		drag = mousePositionY;
	  }	  
	}
	
	mousePositionYOld = mousePositionY;	  
  };

  function scrollClick( dragSwitch )
  {  	
  	if( dragSwitch )
	  drag = mousePositionY;
	else
	  drag = -1;
  	  
  }
  
  function removePX( height )
  {
    if( height.indexOf("px") > 0 )
	  return 1*height.substring( 0, height.length-2 );
	else
	  return height;	
  }

  function setScrollLineHeight()
  {   		
  	innerHeight = removePX( document.getElementById("ContentInnerDiv").style.height );
  	outerHeight = removePX( document.getElementById("ContentOuterDiv").style.height );
  	scrollBarHeight = outerHeight - 40;

	if( innerHeight < outerHeight )
	  scaleValue = 1;
	else
	  scaleValue = outerHeight / innerHeight;
	  
    document.getElementById("ScrollLineImg").style.height = scrollBarHeight * scaleValue; 
  }
    
  function scroll( direction )
  {   		  	
  	if( !document.getElementById("ScrollLineImg") )
  	  return;
  	  
	var top = removePX( document.getElementById("ContentInnerDiv").style.top );
  	var maxTop = removePX( document.getElementById("ContentInnerDiv").style.height );
  	var contentHeight = removePX( document.getElementById("ContentOuterDiv").style.height );
  	var scrollLine = document.getElementById("ScrollLineImg");
  	maxTop = maxTop - contentHeight;
	
	scrollLength = 20;

    if( direction == "mouseDown" )
    {          	
      diff = Math.abs(mousePositionYOld - mousePositionY);
	  scrollLength = contentHeight * diff / removePX(scrollLine.style.height);
      direction = "down";
    }

    if( direction == "mouseUp" )
    {
      diff = Math.abs(mousePositionYOld - mousePositionY);
	  scrollLength = contentHeight * diff / removePX(scrollLine.style.height);
      direction = "up";
    }
			
    if( direction == "pageUp" )
    {
      scrollLength = 200;
      direction = "up";
    }

    if( direction == "pageDown" )
    {
      scrollLength = 200;
      direction = "down";
    }

    if( direction == "toPos1" )
    {
      scrollLength = 10000;
      direction = "up";
    }

    if( direction == "toEnd" )
    {
      scrollLength = 10000;
      direction = "down";
    }
    
  	if( (direction == "up") && (top < 0) )
  	{	    		  	    	  
  	  top = top + scrollLength;

	  if( top > 0 )
	    top = 0;

	  document.getElementById("ContentInnerDiv").style.top = top + "px";
	}
	
	if( (direction == "down") && (maxTop+contentHeight > 330) )
  	{	  		    		
      top = top - scrollLength;
        
	  if( (top < -maxTop) )  
	    top = -maxTop;

	  document.getElementById("ContentInnerDiv").style.top = top + "px";
	}	

	scrollLine.style.top = -top * (contentHeight - 40 - removePX(scrollLine.style.height)) / maxTop;			 	
  }