/**		scrollbar sim for blue-satellite.de		**/
/**		toDo: dragBar?												**/
/**		date: 2006-12-15		me@iacd									**/

var prompter = false;
var restarter = false;

function scrolly(){

  this.speed = 30;  // msec -> recall
  this.moveBy = 1;  // scroll step px
  this.scrollDiv = document.getElementById("contentDiv");
  this.scrollBar = document.getElementById("scrollBarDiv");
  this.getCurrentTop = getCurrentTop;
  this.doScrolling = false; 
  this.up = scrollUp;
  this.down = scrollDown;
  this.stop = stop;
  this.scrollLoop = scrollLoop;
  this.checkScrCond = checkScrCond;
  this.setCurrentTop = setCurrentTop;
  this.contentHeight = parseInt(document.getElementById("contentDiv").offsetHeight);
  if(!this.contentHeight) this.contentHeight = '600px';
  
  this.go2top = go2top;
  this.go2bottom = go2bottom;
  this.maxY = -1 * (this.contentHeight - parseInt(this.scrollBar.style.height)); 
  
  this.doAutoscroll = false;
	this.auto = autoScroll;
	this.reset = resetScroll;
	  
    function scrollUp(){
    	this.speed = 30;
	    clearAllTimers();
      this.doScrolling = true;
      this.scrollLoop('1');
    }
    function scrollDown(){
    	this.speed = 30;
    	clearAllTimers();
      this.doScrolling = true;
      this.scrollLoop('-1');
    }
        
    function scrollLoop(tmp){
      dir = tmp;
      if(this.checkScrCond()){
          strVal = this.getCurrentTop()+ (this.moveBy * dir) + 'px';
          this.setCurrentTop(strVal);
          setTimeout("scrolly.scrollLoop(dir)",this.speed);
      }
      else {
				this.doScrolling = false;
				if(this.doAutoscroll) {
					clearAllTimers();
					restarter = setTimeout("scrolly.reset()",3000);	
				}	
			}
      
    }
    function stop(){
        this.doScrolling = false;
    }
    function checkScrCond(){
        y = this.getCurrentTop();
        if(y>0) {this.doScrolling=false;this.setCurrentTop('0px');}
        if(y<this.maxY) {this.doScrolling=false;this.setCurrentTop(this.maxY+1+'px');}
        
    //    debug('contT:'+y+' - ContH:'+this.contentHeight+ ' T: '+prompter );
        if(this.doScrolling){
          return true;
        }
        else return false;
    }
    
    function getCurrentTop(){
      return parseInt(this.scrollDiv.style.top);
    }
    function setCurrentTop(val){
      this.scrollDiv.style.top = val;
    }
    
    function resetScroll(){
			this.setCurrentTop('0px');
		}
    
    function go2top(){
      this.doScrolling = false;
      this.setCurrentTop('0px');
    }
    function go2bottom(){
      this.doScrolling = false;
      this.setCurrentTop(this.maxY + 'px');
    }
    
    function autoScroll(){
      this.doScrolling = true;
      this.speed = 80;
      this.scrollLoop('-1');
		}
} // end:class

	//	prompter-> nach T autoscroll
		scrolly.prototype.setPrompter = function(){
			prompter = setTimeout("scrolly.startPrompter()",5000);
		}
		scrolly.prototype.startPrompter = function(){	
//d			alert("startPrompt!"+prompter);
			this.doAutoscroll = true;
			this.auto();
		}	

/***				init			***/		

function initScrolly(){
	contY = document.getElementById("contentDiv").offsetHeight;
	if(parseInt(contY) > 223 ) {
		scrolly = new scrolly();
		scrolly.setPrompter();
	}
	else {
		document.getElementById("scrollBarDiv").style.display = 'none';
	}
	
}

function clearAllTimers(){
	if(prompter) clearTimeout(prompter);
	if(restarter) clearTimeout(restarter);
	scrolly.doAutoscroll = false;
}

function debug(what){
  document.getElementById("ctrlDiv").innerHTML = what;  
}
/*
<div id="ctrlDiv" style="position:absolute;bottom:0px;left:0px;width:400px;height:50px;background-color:#EFEFEF;z-index:200"></div>
*/
