JJ_Roll_Banner_obj = null;
JJ_Roll_Banner_StartTimeout = null;

function JJ_Init_RollBanner(){
  JJ_Roll_Banner_obj = new JJ_Roll_Banner(); 

  if ( JJ_Roll_Banner_obj.Ok ){
    JJ_Roll_Banner_obj.Run();
  }
}

function JJ_Roll_Banner (){
  this.Element = document.getElementById( 'RollBannerTop' );
  this.ElementRT = document.getElementById( 'RollBannerTopRechts' );
  this.ElementR = document.getElementById( 'RollBannerRechts' );

  this.RunnerInterval = null;
  this.StartTimeout = null;

  this.MinValue1 = 0;
  this.MaxValue1 = 100;

  this.MinValue2 = 40;
  this.MaxValue2 = 100;


  this.Step = 5;
  this.IntervalTime = 100;
  this.UpTime = 3000;

  this.CurrentIndex = 0;
  this.NextIndex = 1;

  this.Ok = false;
  this.Childs = new Array();
  this.ChildsRT = new Array();
  this.ChildsR = new Array();

  this.CurrentValue1 = this.CurrentValue2 = 0;

  if ( this.Element && this.ElementRT && this.ElementR ){
    this.Init();
  }

}

JJ_Roll_Banner.prototype.Init = function(){ 
  ch = this.Element.childNodes;
  for( i = ch.length - 1; i >= 0; i -- ){ 
    child = ch[ i ];
    if ( child.nodeName == 'DIV' ){ 
      this.Childs.push( child );
    }
  }
  ch = this.ElementRT.childNodes;
  for( i = ch.length - 1; i >= 0; i -- ){
    child = ch[ i ];
    if ( child.nodeName == 'DIV' ){
      this.ChildsRT.push( child );
    }
  }
  ch = this.ElementR.childNodes;
  for( i = ch.length - 1; i >= 0; i -- ){
    child = ch[ i ];
    if ( child.nodeName == 'DIV' ){
      this.ChildsR.push( child );
    }
  }
  if ( this.Childs.length > 1 ){ 
    this.Ok = true;
  }
}

JJ_Roll_Banner.prototype.Run = function(){
  clearTimeout( this.StartTimeout );
  this.StartTimeout = setTimeout( "JJ_Roll_Banner_obj.Start();", this.UpTime );
}

JJ_Roll_Banner.prototype.CalculateNextIndex =  function(){
  this.CurrentIndex = this.NextIndex;
  this.NextIndex = this.Childs.length == this.NextIndex + 1 ? 0 : this.NextIndex + 1;
}

JJ_Roll_Banner.prototype.Start = function(){
  this.Childs[ this.NextIndex ].style.visibility = 'visible';
  this.ChildsRT[ this.NextIndex ].style.visibility = 'visible';
  this.ChildsR[ this.NextIndex ].style.visibility = 'visible';
  this.CurrentValue1 = this.MaxValue1;
  this.CurrentValue2 = this.MinValue2;

  this.SetFilter();
  clearInterval( this.RunnerInterval );
  this.RunnerInterval = setInterval( "JJ_Roll_Banner_obj.NextStep();", this.IntervalTime );
}

JJ_Roll_Banner.prototype.NextStep = function(){

  this.CurrentValue1 = Math.max( this.CurrentValue1 - this.Step, this.MinValue1 );
  this.CurrentValue2 = Math.min( this.CurrentValue2 + this.Step, this.MaxValue2 );
  
  this.SetFilter();
  
  if ( this.CurrentValue1 == this.MinValue1 && this.CurrentValue2 == this.MaxValue2 ){
    this.Stop();
  }

}

JJ_Roll_Banner.prototype.Stop = function(){
  this.RunnerInterval = clearInterval( this.RunnerInterval );

  clearTimeout( this.StartTimeout );
  this.StartTimeout = setTimeout( "JJ_Roll_Banner_obj.Start();", this.UpTime );

  this.Childs[ this.CurrentIndex ].style.visibility = 'hidden';
  this.Childs[ this.NextIndex ].style.visibility = 'visible';
  this.ChildsRT[ this.CurrentIndex ].style.visibility = 'hidden';
  this.ChildsRT[ this.NextIndex ].style.visibility = 'visible';
  this.ChildsR[ this.CurrentIndex ].style.visibility = 'hidden';
  this.ChildsR[ this.NextIndex ].style.visibility = 'visible';


  this.CalculateNextIndex(); 
}

JJ_Roll_Banner.prototype.SetFilter = function( ){ 

  if ( this.Childs[ this.CurrentIndex ].filters && this.Childs[ this.CurrentIndex ].filters.alpha ) {
    this.Childs[ this.CurrentIndex ].filters.alpha.opacity = this.CurrentValue1;
    this.ChildsRT[ this.CurrentIndex ].filters.alpha.opacity = this.CurrentValue1;
    this.ChildsR[ this.CurrentIndex ].filters.alpha.opacity = this.CurrentValue1;
  } else {
    this.Childs[ this.CurrentIndex ].style.MozOpacity = this.CurrentValue1 / 100; 
    this.Childs[ this.CurrentIndex ].style.opacity = this.CurrentValue1 / 100; 
    this.ChildsRT[ this.CurrentIndex ].style.MozOpacity = this.CurrentValue1 / 100;
    this.ChildsRT[ this.CurrentIndex ].style.opacity = this.CurrentValue1 / 100;
    this.ChildsR[ this.CurrentIndex ].style.MozOpacity = this.CurrentValue1 / 100;
    this.ChildsR[ this.CurrentIndex ].style.opacity = this.CurrentValue1 / 100;
  }

  if ( this.Childs[ this.NextIndex ].filters && this.Childs[ this.NextIndex ].filters.alpha ) {
    this.Childs[ this.NextIndex ].filters.alpha.opacity = this.CurrentValue2;
    this.ChildsRT[ this.NextIndex ].filters.alpha.opacity = this.CurrentValue2;
    this.ChildsR[ this.NextIndex ].filters.alpha.opacity = this.CurrentValue2;
  } else {
    this.Childs[ this.NextIndex ].style.MozOpacity = this.CurrentValue2 / 100;
    this.Childs[ this.NextIndex ].style.opacity = this.CurrentValue2 / 100;
    this.ChildsRT[ this.NextIndex ].style.MozOpacity = this.CurrentValue2 / 100;
    this.ChildsRT[ this.NextIndex ].style.opacity = this.CurrentValue2 / 100;
    this.ChildsR[ this.NextIndex ].style.MozOpacity = this.CurrentValue2 / 100;
    this.ChildsR[ this.NextIndex ].style.opacity = this.CurrentValue2 / 100;
  }
}



