var JJ_NewsBanners = new Array();
function JJ_NewsBanner_Start( id ){
  if ( JJ_NewsBanners[ id ] ){ 
    JJ_NewsBanners[ id ].Start();
  }
}

function JJ_NewsBanner_Run( id ){
  if ( JJ_NewsBanners[ id ] ){
    JJ_NewsBanners[ id ].Run();
  }
}

function JJ_NewsBanner( idToStart, NewHeight ){
  this.Setup( idToStart, NewHeight );

  if ( this.Ok ){ 
    setTimeout( 'JJ_NewsBanner_Start(\'' + this.id + '\')', this.UpTime );
  }

}

JJ_NewsBanner.prototype.Setup = function( id, ElementHeight ) {
  this.id = id;
  this.Element = document.getElementById( this.id );
  this.Childs = new Array(); 
  this.Height = ElementHeight;

  this.Pauze = false;

  this.Speed = 1;
  this.InterValTime = 25;
  this.UpTime = 3000;
  this.RunnerInterval = null;
  this.StartTimeout = null;
 
  this.CurrentHeight = 0;
  
  this.Top = 0;
 
  this.Ok = false;

  if ( this.Element ){
     this.Element.style.height = ElementHeight + 'px';

     this.Element.onmouseover = function(){ 
       JJ_NewsBanners[ this.id ].PauseBanner();
     };

     this.Element.onmouseout = function(){
       JJ_NewsBanners[ this.id ].ContinueBanner();
     };


     for( var i = 0; i < this.Element.childNodes.length; i++ ){ 
       var Child = this.Element.childNodes[ i ]; 
       if ( Child.tagName == 'DIV' ) {
         if ( this.Childs.length > 0 ){ 
           Child.style.top = this.Height + 'px';
         }
         this.Childs.push( Child );
       }
     } 

     if ( this.Childs.length ){
       this.Ok = true;
       this.CurrentVisible = 0;  
       this.NextVisible = 0;
       JJ_NewsBanners[ this.id ] = this;
     }
  }
}

JJ_NewsBanner.prototype.Start = function( ) {
  clearTimeout( this.StartTimeout );
  clearInterval( this.RunnerInterval );
  this.CurrentVisible = this.NextVisible;
  this.NextVisible = this.Childs.length - 1 == this.CurrentVisible ? 0 : this.CurrentVisible + 1;
  if ( this.NextVisible != this.CurrentVisible ){ 
    this.Childs[ this.NextVisible ].style.top = this.Height + 'px';
    this.Top = this.Height;
    this.CurrentHeight = this.Childs[ this.CurrentVisible ].offsetHeight;
    this.RunnerInterval = setInterval( 'JJ_NewsBanner_Run(\'' + this.id + '\')', this.InterValTime );
  }
}

JJ_NewsBanner.prototype.Run = function( ) {
  if ( this.Pauze ){ 
    return;
  }
  if ( this.Top > 0 ){ 
    this.Top = Math.max( this.Top - this.Speed, 0 );

    RestRuimte = this.Top;
    if ( RestRuimte < this.CurrentHeight ){
      CurrentTop = RestRuimte - this.CurrentHeight;
      this.Childs[ this.CurrentVisible ].style.top = CurrentTop + 'px';
    }
    this.Childs[ this.NextVisible ].style.top = this.Top + 'px';

  } else {
    clearInterval( this.RunnerInterval );
    setTimeout( 'JJ_NewsBanner_Start(\'' + this.id + '\')', this.UpTime );    
  }
}

JJ_NewsBanner.prototype.PauseBanner = function( ){
  this.Pauze = true;
}

JJ_NewsBanner.prototype.ContinueBanner = function( ){
  this.Pauze = false;
}
