moreFromThisShow = { page: 1, id: 0 };
whosWatchingWithYou = { page: 1, id: 0, entryID: 0 };
youMightAlsoLike = { page: 1, id: 0 };

$(document).ready(function(){
  whosWatchingWithYou.id = $('#whosWatchingWithYou .id').text();
  $('#whosWatchingWithYou .prev').click(function(){ whosWatchingWithYouPaginate( -1 ); });
  $('#whosWatchingWithYou .next').click(function(){ whosWatchingWithYouPaginate( 1 ); });
  $('#whosWatchingWithYou .refresh').click(function(){ whosWatchingWithYouPaginate( 0 ); });
  
  watchingActionIconsInit();
  
  youMightAlsoLike.id = $('#youMightAlsoLike .id').text();
  $('#youMightAlsoLike .prev').click(function(){ youMightAlsoLikePaginate( -1 ); });
  $('#youMightAlsoLike .next').click(function(){ youMightAlsoLikePaginate( 1 ); });
  
  moreFromThisShow.id = $('#moreFromThisShow .id').text();
  moreFromThisShow.entryID = $('.TVViewer .id').text();
  $('#moreFromThisShow .prev').click(function(){ moreFromThisShowPaginate( -1 ); });
  $('#moreFromThisShow .next').click(function(){ moreFromThisShowPaginate( 1 ); });
  $('#moreFromThisShow select').change(function(){ moreFromThisShowPaginate(); });
});

function watchingActionIconsInit()
{
  // Do Action Icons
  $('#whosWatchingWithYou .actionIcons').each(function(){
    $(this).mybActionIcons({
      userid: $(this).children('span.userid').text(),
      firstName: $(this).find('span.name').text(),
      vipLevel: $(this).find('span.vipLevel').text()
    }, { token: stok, doIconPopUp: true });
  });
}

function whosWatchingWithYouPaginate( direction )
{
  $('#whosWatchingWithYou .loading').show();
  if ( ! direction )
  {
    var direction = 0;
  }
  
  whosWatchingWithYou.page += direction;
  
  $.ajax({
    url: '/json/view/whosWatchingWithYou',
    dataType: 'json',
    type: 'post',
    data: whosWatchingWithYou,
    success: function ( data ) {
      $('#whosWatchingWithYou .contents').html( data.content );
      $('#whosWatchingWithYou .count').text( data.count );
      watchingActionIconsInit();
      $('#whosWatchingWithYou .loading').hide();
    }
  });
}

function youMightAlsoLikePaginate( direction )
{
  if ( ! direction )
  {
    var direction = 0;
  }
  
  youMightAlsoLike.page += direction;
  
  $.ajax({
    url: '/json/view/youMightAlsoLike',
    dataType: 'json',
    type: 'post',
    data: youMightAlsoLike,
    success: function ( data ) {
      $('#youMightAlsoLike .contents').html( data.content );
    }
  });
}

function moreFromThisShowPaginate( direction )
{
  if ( ! direction )
  {
    var direction = 0;
  }
  
  moreFromThisShow.type = $('#moreFromThisShow select').val();
  moreFromThisShow.page += direction;
  
  $.ajax({
    url: '/json/view/moreFromThisShow',
    dataType: 'json',
    type: 'post',
    data: moreFromThisShow,
    success: function ( data ) {
      $('#moreFromThisShow .contents').html( data.content );
    }
  });
}
