/**
* videoScrollerClass class
*/
function videoScrollerClass() {

  this.busy = false;
  this.channel = '';
  this.skip = 0;
  this.ts1 = 0;
  this.ts2 = 0;
  this.dir = '';

  this.init = function(channel, skip, ts1, ts2) {
    this.channel = channel;
    if(!this.channel)
      this.channel = 'all';
    this.skip = skip;
    this.ts1 = ts1;
    this.ts2 = ts2;
    this.dir = '';
    this.updateButtons();
  }

  this.prev = function() {
    if(this.ts1)
      this.scroll('prev');
  }

  this.next = function(channel, skip) {
    if(this.ts2)
      this.scroll('next');
  }

  this.updateButtons = function() {
    $('#video_scroller_prev')[0].src = (videoScroller.ts1) ? '/images/nav_left_blue.gif' : '/images/nav_left.gif';
    $('#video_scroller_next')[0].src = (videoScroller.ts2) ? '/images/nav_right_blue.gif' : '/images/nav_right.gif';
  }

  // update comment block
  this.scroll = function(dir) {
    if(this.busy)
      return;

    this.dir = dir;
    this.busy = true;

    $('#ajax_loader').show();

    jQuery.get("/ajax/video_channel/" + this.channel + "/" + this.skip, { ts1: this.ts1, ts2: this.ts2, dir: this.dir },
      function(data){
        videoScroller.busy = false;
        $('#ajax_loader').hide();

        if(data.length) {
          var matches;
          if(matches = data.match(/^(\d+)\|(\d+)\|/)) {
            videoScroller.ts1 = parseInt(matches[1], 10);
            videoScroller.ts2 = parseInt(matches[2], 10);
            data = data.substr(matches[0].length);
          }
          $('#video_scroller_container').html(data);
        }
        else {
          if(videoScroller.dir == 'prev')
            videoScroller.ts1 = 0;
          if(videoScroller.dir == 'next')
            videoScroller.ts2 = 0;
        }

        videoScroller.updateButtons();
      }, "html");
  }

}

var videoScroller = new videoScrollerClass();


/* End videoScrollerClass */
