  var gadget = new function() {
   var last = null;
   var scroller = null;
   this.jump = function(e) {
    var anc = wu.target(e);
    if (!anc) return wu.stop(e);
    last.removeClass('current');
    $(last.id.substr(2)).setStyle('display', 'none');
    last = anc;
    last.addClass('current');
    $(last.id.substr(2)).setStyle('display', '');
    scroller.setStyle('margin-left', 0);
    return wu.stop(e);
   }
   this.init = function(pcurrent, pimg, pdatasource) {
    scroller = $('gadget').getElements('.scroll')[0];
    $('buttons')
     .adopt(new Element('a').setProperties({'href': '#', 'tabindex': 0, 'id': 'a_latest'}).appendText('friss').addClass('current').addEvent('click', gadget.jump))
     .adopt(new Element('a').setProperties({'href': '#', 'tabindex': 0, 'id': 'a_popular'}).appendText('népszerű').addEvent('click', gadget.jump))
     .adopt(new Element('a').setProperties({'href': '#', 'tabindex': 0, 'id': 'a_toprated'}).appendText('legjobb').addEvent('click', gadget.jump))
     .adopt(new Element('a').setProperties({'href': '#', 'tabindex': 0, 'id': 'a_mostdiscussed'}).appendText('vitatott').addClass('last').addEvent('click', gadget.jump));
    last = $('a_latest');
   }
  }
  
  var wcs_scroller = new Class({
   moveleft: function(e) {
    var marginleft = this.container.getStyle('margin-left').toInt();
    if (marginleft > (0 - this.container.getStyle('width').toInt())) {
     var len = (0 - this.container.getStyle('width').toInt() + this.mainwidth + this.step);
     if ((len - marginleft) * - 1 < this.step) this.eff.start(marginleft, parseInt(len - this.step)); else this.eff.start(marginleft, parseInt(marginleft - this.step));
    };
    return wu.stop(e);
   },
   moveright: function(e) {
    var marginleft = this.container.getStyle('margin-left').toInt();
    if (marginleft < 0) this.eff.start(marginleft, Math.min(0, parseInt(marginleft + this.step)));
    return wu.stop(e);
   },
   initialize: function(mainobj) {
    this.ul = mainobj.getElements('.videolist')[0];
    this.container = mainobj.getElements('.scroll')[0];
    this.mainwidth = mainobj.getStyle('width').toInt();
    this.step = this.mainwidth / 2;
    var width = parseInt(parseInt(this.ul.getElementsByTagName('li').length) * 114);
    this.container.setStyle('width', width + 'px');
    if (width > this.mainwidth) {
     this.eff = new Fx.Style(this.container, 'margin-left', {duration: 100});
     mainobj
      .adopt(new Element('a').addClass('fleft').setProperties({'href': '#', 'tabindex': '0'}).appendText('jobbra').addEvent('click', this.moveright.bind(this)))
      .adopt(new Element('a').addClass('fright').setProperties({'href': '#', 'tabindex': '0'}).appendText('balra').addEvent('click', this.moveleft.bind(this)))
     ;
    };
   }
  });
