fans = { series: 0, page: 1, count: 4, type: 'everyone' };

function seriesInit() {
 
  fans.series = $('.fans .id').text();

  bindActionIcons();

  $('.ack .close').click(function(e){
    $(this).parent().hide();
    e.stopPropagation();
    e.cancelBubble = true;
  });

  $('.addToMyShows').click(function(){
		var id = $(this).siblings('.id').text();
		$.ajax({
			url: '/json/myShows/add',
			dataType: 'json',
			type: 'post',
			data: { id: id },
			success: function(data){
			  if ( data.result )
			  {
			    data.message = 'Successfully added to "My Shows"';
			  }
			  $('.ack .content').html( data.message ).parent().show();
			}
		});
  });

  $('.removeFromMyShows').click(function(){
		var id = $(this).siblings('.id').text();
		$.ajax({
			url: '/json/myShows/remove',
			dataType: 'json',
			type: 'post',
			data: { id: id },
			success: function(data){
			  if ( data.result )
			  {
			    data.message = 'Successfully removed from "My Shows"';
			  }
			  $('.ack .content').html( data.message ).parent().show();
			}
		});
  });

  $('.fans .next').click(function(){
    fansPaginate( 1 );
  });
  
  $('.fans .prev').click(function(){
    fansPaginate( -1 );
  });
  
  $('.fans .type span.everyone').click(function(){
    fans.type = 'everyone';
    $(this).addClass('selected');
    $(this).siblings().removeClass('selected');
    fansPaginate();
  });
  
  $('.fans .type span.friends').click(function(){
    fans.type = 'friends';
    $(this).addClass('selected');
    $(this).siblings().removeClass('selected');
    fansPaginate();
  });
}

function bindActionIcons()
{
  $('.fans li').each(function(){   
    $(this).find('.actionIcons').mybActionIcons({
     userid: $(this).children('span.userid').text(),
     firstName: $(this).find('span.firstName').text(),
     vipLevel: $(this).find('span.vipLevel').text()
    }, { token: stok, doMsg: true, doStar: true, doFlirt: true, doGift: true, doAdmire: true, doIconPopUp: true, order: [ 'doMsg', 'doFlirt', 'doStar', 'doGift', 'doAdmire', 'doIconPopUp' ] });
  });
}

function fansPaginate( direction )
{
  if ( ! direction ) { var direction = 0; }
  
  fans.page += direction;
  fans.type = $('.fans .type .selected').text();
  
  $.ajax({
    url: '/json/fans',
    dataType: 'json',
    type: 'post',
    data: fans,
    success: function (data){
      $('.fans .contents').html( data.content );
      bindActionIcons();
    }
  });
}
