
function objWidth(obj)
	{
	if(obj.offsetWidth) 
		return obj.offsetWidth;
		
	if(obj.clip)
		return obj.clip.width;
		
	return 0;
	} 

function objHeight(obj) 
	{
	if(obj.offsetHeight) 
		return obj.offsetHeight; 
	
	if (obj.clip) 
		return obj.clip.height;
	
	return 0;
	} 
  
var ascroller = new Array();
function scroller(id)
  {
  this.overdiv = document.getElementById(id);
  this.flashupdir = "images/layout/flashup.png";
  this.flashwidth = 18;
  this.flashheight = 23;
  this.flashdowndir = "images/layout/flashdown.png";
  this.speed = 50;
  this.overlay = true;
  this.padding = 0;
  this.inmove = false;
  this.interval = '';
  var parent = this;
  
  this.scroller_id = ascroller.length;
  ascroller[this.scroller_id] = this;
  
  this.append = 
    function()
      {
      this.overdiv.style.overflow = "hidden";
      
      this.flashup = document.createElement('img');
      this.flashup.style.position = "absolute";
      this.flashup.style.border = "none";
      this.flashup.style.cursor = "pointer";
      this.flashup.src = this.flashupdir;
      this.flashup.onmouseover = new Function("scroller_start('down'," + this.scroller_id+ ");")
      this.flashup.onmouseout = new Function("scroller_stop( "+ this.scroller_id+ ");");
    
     
  
      this.flashdown = document.createElement('img');
      this.flashdown.style.position = "absolute";
      this.flashdown.style.border = "none";
      this.flashdown.style.cursor = "pointer";
      this.flashdown.src = this.flashdowndir;
      this.flashdown.onmouseover = new Function("scroller_start('up'," + this.scroller_id+ ");")
      this.flashdown.onmouseout =  new Function("scroller_stop( "+ this.scroller_id+ ");");
      
      this.movediv = document.createElement('div');
      this.movediv.innerHTML = this.overdiv.innerHTML; //Inhalt tauschen
      this.overdiv.innerHTML = '';
      this.movediv.style.position = "absolute";
      this.movediv.style.top = "0px";
      this.movediv.style.left = "0px";
      this.movediv.style.padding = this.padding + "px";
      
      if(this.overlay==true)
        this.movediv.style.width = objWidth(this.overdiv)+10-this.flashwidth-(2*this.padding) +'px' ;
      else
        this.movediv.style.width = objWidth(this.overdiv)-(2*this.padding)+10 +'px';
       
      this.flashup.style.right = '1px'; 
      this.flashup.style.top = '1px'; 
  
      this.flashdown.style.right = '1px'; 
      this.flashdown.style.bottom = '1px'; 
      
      this.overdiv.onmousewheel = new Function("scroller_wheel( "+ this.scroller_id+ ");");
      
      this.overdiv.appendChild(this.movediv);
      this.overdiv.appendChild(this.flashup);
      this.overdiv.appendChild(this.flashdown);
      this.reload();
      }
      
  this.reload = 
    function()
      {
      if(objHeight(this.overdiv)>objHeight(this.movediv))
         {
         this.movediv.style.top = "0px";
          
         this.flashdown.style.visibility="hidden"; 
         this.flashup.style.visibility="hidden"; 
         
         if(this.overlay==true)
           this.movediv.style.width = objWidth(this.overdiv) +'px';
       
         }
        else
         {
         this.flashdown.style.visibility="visible"; 
         this.flashup.style.visibility="visible";  
         
         if(this.overlay==true)
           this.movediv.style.width = objWidth(this.overdiv)-this.flashwidth-12 +'px';
         }
   }
   
  this.clear = 
    function()
      {
      this.movediv.style.top = "0px";
          
         this.flashdown.style.visibility="hidden"; 
         this.flashup.style.visibility="hidden"; 
         
         if(this.overlay==true)
           this.movediv.style.width = objWidth(this.overdiv) +'px';
        
      }
  }
 
 function scroller_start(direction,scrollerID)
          {
          scr = ascroller[scrollerID];
          
          if(direction=="down") 
            scr.interval = window.setInterval("scroller_down(" + scr.scroller_id+ ");",Math.ceil(2000/scr.speed));
          else if(direction=="up") 
            scr.interval = window.setInterval("scroller_up(" + scr.scroller_id+ ");",Math.ceil(2000/scr.speed));
          }
          
 function scroller_stop(scrollerID)
          {
          scr = ascroller[scrollerID];
          window.clearInterval(scr.interval);
          }
           
           
 function scroller_up(scrollerID) 
  {
  scr = ascroller[scrollerID];
  
  var ztop = parseInt(scr.movediv.style.top)-Math.ceil(scr.speed/6);
 
  if(ztop<((objHeight(scr.movediv)-objHeight(scr.overdiv))*-1))
    ztop=((objHeight(scr.movediv)-objHeight(scr.overdiv))*-1);
     
  
  scr.movediv.style.top = ztop+'px';  
  }
  
 function scroller_down(scrollerID) 
  {
  scr = ascroller[scrollerID];
  
  var ztop = parseInt(scr.movediv.style.top)+Math.ceil(scr.speed/6);
 
  if(ztop>0)
    ztop=0;
     
  scr.movediv.style.top = ztop+'px';  
  }

function scroller_wheel(scrollerID) 
  {
   scr = ascroller[scrollerID];
 
  if(objHeight(scr.movediv)>objHeight(scr.overdiv))
  if(event.wheelDelta>=1)
    scroller_down(scrollerID),scroller_down(scrollerID),scroller_down(scrollerID);
  else 
    scroller_up(scrollerID),scroller_up(scrollerID),scroller_up(scrollerID); 
  }

