$(function() {
  function Ticker() {
    this.count = 0;
    this.counter = 0;
    this.width = $(document).width();
    this.speed = 500;
  }
  Ticker.prototype = {
    _this : "",
    init : function() {
      var that = this;
      _this =  this;
      $('#ticker').css({width : this.width + 'px', overflow : 'hidden' });
      $.each($('#ticker li'), function(index, value) {
        $(this).attr('id', 'index_' + index);
        that.count++;
      });
      this.setTickerList();
      this.beginTicker();
    },
    
    setTickerList : function() {
      $('#ticker li').css({left : this.width + 'px'});
    },
    
    resetTickerList : function(currentCounter) {
      $('#ticker li#index_' + currentCounter).css({left : this.width + 'px', 'display' : 'block'});
    },
    
    beginTicker : function() {
      var that = this;
      var currentCounter = this.counter;
      this.resetTickerList(currentCounter);
      $('#ticker li#index_' + this.counter).animate({'left' : '-700px'}, 30000, "linear", function() {
        that.resetTickerList(currentCounter);
      });
      this.counter++;
      if (this.counter == this.count) {
        this.counter = 0;
      }
      $('#ticker').animate({opacity : 1}, 15000, function() {
        that.beginTicker();
      });
    }
  }
  var ticker = new Ticker();
  ticker.init();
});
