ActionChain.add({

  "#login": function() {
    this.focus();
  },
        
  ".button_wrapper": function() {
    buttonWrapper(this);
  },

  "#header_navi": function() {
    this.getElement('.' + this.get('data-active')).addClass('current');
    this.getElements('li').addEvent('mouseover', function() {
      this.getElement('span').addClass('underline');
    }).addEvent('mouseout', function() {
      this.getElement('span').removeClass('underline');
    });
  },
    
  "#navi": function() {
    this.getElement('.' + this.get('data-active')).addClass('current');
    this.getElements('.navi_item').addEvent('click', function() {
      window.location.href = this.get('data-url');
    });
  },
    
  ".navi_item": function() {
    var img = this.getElement('img');
      
    this.addEvent('mouseover', function() {
      img.setStyle('bottom', '3px');
    });
    $$(this, this.getParent('li')).addEvent('mouseout', function(e) {
      if(e.target != img) img.setStyle('bottom', '0');
    });
  },
    
  ".png_hoverize": function() {
    new Hoverizor(this, {
      fileType: 'png'
    });
  },

  "#name_step_in_form:submit": function() {
    var input = this.getElement('#name');
    if(input.get('value') == '') {
      input.addClass('wrong');
      return false;
    }
  },

  "#printshops_count": function() {
    printshops_tween(this);
  },

  ".close:click": function() {
    this.getParent('.wrapper').retrieve('whitebox').hide();
    return false;
  },

  "#blackboard > div": function() {
    this.set('data-tip_offset', -30);
    tipify(this, {
      showDelay: 0
    });
  },

  ".password_form": function() {
    new PasswordFormObserver(this);
  },

  ".scrollcase": function() {
    var scrollcase = new Scrollcase(this, {
      onArrowClick: function(moveRight) {
        var current = this.handleFx.step;
        var moveTo;
        if(current == 50) {
          if(moveRight) {
            moveTo = 100;
          } else {
            moveTo = 0;
          }
        }
        else if(current < 50) {
          if(moveRight) {
            moveTo = 50;
          } else {
            moveTo = 0;
          }
        } else {
          if(moveRight) {
            moveTo = 100;
          } else {
            moveTo = 50;
          }
        }
        this.handleFx.set(moveTo);
      }
    });

    var atScrollcaseLevel = function() {
      return (window.getScrollTop() + window.getHeight()) > 1100;
    };

    if(!atScrollcaseLevel()) {
      scrollcase.handleFx.set(50); // last

      var spinScroll = function() {
        if(atScrollcaseLevel()) {
          scrollcase.handleFx.set(0);
          window.removeEvent('scroll', spinScroll);
        }
      }

      window.addEvent('scroll', spinScroll);
    }
  }
    
});

/**
*   Creates a hover effect on image button.
*   Returns parameter.
*/
function buttonWrapper(element) {
  if(element.get('tag') != 'span') new Element('span').wraps(element);
  element.addEvent( 'mouseover', function() {
    this.get( 'tween' ).set( 'opacity', .9 );
  } ).addEvent( 'mouseout', function() {
    this.get( 'tween' ).set( 'opacity', 1 );
  } );
  return element;
}