/*
 * Tv schedule toggle
 */
/**
* videoReligionScrollerClass class
*/
function videoReligionScrollerClass() {

  this.busy = false;
  this.id = 0;
  this.ts1 = 0;
  this.ts2 = 0;
  this.dir = '';

  this.init = function(id, ts1, ts2) {
    this.id = id;
    this.ts1 = ts1;
    this.ts2 = ts2;
    this.dir = '';
    this.updateButtons();
  }

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

  this.next = function(id) {
    if(this.ts2)
      this.scroll('next');
  }

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

  this.scroll = function(dir) {
    if(this.busy)
      return;

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

    $('#ajax_loader').show();
    jQuery.get("/video/ajax/other/" + this.id, { ts1: this.ts1, ts2: this.ts2, dir: this.dir },
      function(data){
        videoReligionScroller.busy = false;
        $('#ajax_loader').hide();

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

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

var videoReligionScroller = new videoReligionScrollerClass();


/*
 * Tv schedule toggle
 */
/**
* newsReligionScrollerClass class
*/
function newsReligionScrollerClass() {

  this.busy = false;
  this.id = 0;
  this.ts1 = 0;
  this.ts2 = 0;
  this.dir = '';

  this.init = function(id, ts1, ts2) {
    this.id = id;
    this.ts1 = ts1;
    this.ts2 = ts2;
    this.dir = '';
    this.updateButtons();
  }

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

  this.next = function(id) {
    if(this.ts2)
      this.scroll('next');
  }

  this.updateButtons = function() {
    $('#news_scroller_prev')[0].src = (newsReligionScroller.ts1) ? '/images/nav_left.gif' : '/images/nav_left_ina.gif';
    $('#news_scroller_next')[0].src = (newsReligionScroller.ts2) ? '/images/nav_right.gif' : '/images/nav_right_ina.gif';
  }

  this.scroll = function(dir) {
    if(this.busy)
      return;

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

    $('#ajax_loader').show();
    jQuery.get("/news/ajax/other/" + this.id, { ts1: this.ts1, ts2: this.ts2, dir: this.dir },
      function(data){
        newsReligionScroller.busy = false;
        $('#ajax_loader').hide();

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

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

var newsReligionScroller = new newsReligionScrollerClass();

