if(!Control) var Control = {};
Control.HomepageImage = Class.create();

Control.HomepageImage.prototype = {
  initialize: function(element) {
    this.ele = $(element);
    this.appear_time = 1.5;
    this.move_time = 4;
    this.text_div = $('homepage-scroll-text');
    
  },
  
  load: function(after, text, x, y) {

    var ele = this.ele;
    var move_time = this.move_time;
    var appear_time = this.appear_time;
    var text_div = this.text_div;
    var frame = 100;
    
    text_div.innerHTML = text;
    
    text_div.style.top = y+'px';
    text_div.style.left = x +'px';

    new Effect.Appear(text_div, { duration: .5 });
    
    new Effect.Appear(this.ele, {
      duration: appear_time,
      
      afterFinish: function(obj) {
        var move = ele.className == 'reverse' ? 256 : -256;
        var tripped = false;        
        new Effect.Fade(text_div);
        
        new Effect.MoveBy(ele, 0, move, { 
          duration: move_time,
          transition: Effect.Transitions.sinoidal,
          afterUpdate: function(obj) {

            if(text != 'Sustainability') {
              if(obj.currentFrame >= frame - 10 && obj.currentFrame  <= frame + 10 && !tripped) {
                tripped = true;
                new Effect.Fade(ele, {
                  duration: 2,
                  afterFinish: function() {
                    if(after) {
                      after();
                    }
                  }
                });
              
              }
            }
          },
          afterFinish: function(obj) {
            if(text == 'Sustainability') {
              text_div.innerHTML = "T H E&nbsp;&nbsp;P O W E R&nbsp;&nbsp;O F&nbsp;&nbsp;3";
              text_div.style.fontSize = '50px';
              text_div.style.top = '1px';
              text_div.style.left = '20px';
              
              new Effect.Appear(text_div, { duration: 2, afterFinish: function() { 
                
                new Effect.Fade(ele, {
                  duration: 1,
                  afterFinish: function() {
                    if(after) {
                      after();
                    }
                  }
                });
                
              } });
            }
          }
        });
      }
    });

  }
}

function hp(e) {
  return new Control.HomepageImage(e);
}