AnimatedMenuItem = jQuery.klass({
  initialize: function() {
    this.options = {duration: 300};
  },
  
  onmouseenter: function() {
    var element = this.element;

    jQuery('.home ul.animated li a').removeClass('selected-bg').removeClass('active');
    
    element.addClass('selected-bg');
    var next_element = element.parent().next();
    var n = 0;
    element.addClass('active');
    element.animate({
        'height': 140,
        'width': 530, 
        'fontSize': 32, 
        'paddingLeft': 106, 
        //'paddingTop': 10,
        'marginLeft': '-37'
      }, {
        'duration': this.options.duration,
        'step': function() {
          var h = Number(element.css('height').replace(/px/, ''));
          h = h >= 128-35 ? (128-35-h) + 'px' : 0;
          next_element.css({'margin-top': h});
          n++;
        },
        'complete': function() {
            element.find('img,span').css({opacity: 0, display: 'block'}).animate({opacity: 1}, {duration: 100, 'complete': element.removeClass('active')});
        }
      });
    
  },
  
  onmouseleave: function () {

    jQuery(".home ul.animated a.active").stop();
    
    var element = this.element;
    var next_element = element.parent().next();
    
    element.stop().find('img,span').animate({opacity: 0}, {
        'duration': 100,
        'complete': function() {
            jQuery(this).css('display', 'none');
        }
    });

    element.animate({
        'height': 28,
        'width': 343,
        'fontSize': 28, 
        'paddingLeft': 69,
        //'paddingTop': 8,
        'marginLeft': 0
      }, {
        'duration': this.options.duration,
        'step': function() {
          var h = Number(element.css('height').replace(/px/, ''));
          h = h >= 128-35 ? (128-35-h) + 'px' : 0;
          next_element.css({'margin-top': h });
        },
        'complete': function(){
//            console.log('leave complete');
            element
                .removeClass('selected-bg')
                .removeClass('active');
        }
    });
  }
  
});

