/*!
 * jRoulette
 * Copyright 2010, evrone.ru
 * All rights reserved.
 **/

function roulette(selector, duration_per_pixel) {
  var _this = this;
  _this.dpp = duration_per_pixel;
  var _line = $(selector + ' .line');

  var _width = _line.children(':first').width();

  this.next_box = function () {
    _line.children(':first').appendTo(_line);
    _line.css('left', 0);
    _width = _line.children(':first').width();
    _line.animate({ 'left': '-' + _width }, _width * _this.dpp, 'linear', _this.next_box);
  };

  this.new_box = function (params) {
    var _new = _line.children(':first').clone();
    _new.find('img').attr('src', params.url);
    _new.find('a').attr('href', params.href);
    _new.find('.name').html(params.name);
    _new.appendTo(_line);
  };

  this.load_images = function (arr) {
    for (var i = 0; i < arr.length; i++) _this.new_box(arr[i]);
  };

  _line.animate({ 'left': '-' + _width }, _width * _this.dpp, 'linear', _this.next_box);

}
