$(document).ready(function() {
  var current_page = 1;
  var total_images = $('.enthu-images img').size();
  
  $('.enthu-images .paginate span').text(current_page + ' of ' + total_images);
  
  $('.enthu-images img').each(function(i){
    j = i+1;
    $(this).addClass('img-' + j);
  });
  
  if(current_page == 1)
    $('.enthu-images .paginate .prev').addClass('inactive');
  else
    $('.enthu-images .paginate .prev').removeClass('inactive');

  if(current_page == total_images)
    $('.enthu-images .paginate .next').addClass('inactive');
  else
    $('.enthu-images .paginate .next').removeClass('inactive');

  $('.enthu-images .paginate span').text(current_page + ' of ' + total_images);
  
  
  $('.enthu-images .paginate .prev').live("click", function(){
    if(! $(this).hasClass('inactive')) {
      $('.enthu-images .img-' + current_page).hide();
      current_page -= 1;
      $('.enthu-images .img-' + current_page).show();

      if(current_page == 1)
        $('.enthu-images .paginate .prev').addClass('inactive');
      else
        $('.enthu-images .paginate .prev').removeClass('inactive');

      if(current_page == total_images)
        $('.enthu-images .paginate .next').addClass('inactive');
      else
        $('.enthu-images .paginate .next').removeClass('inactive');

      $('.enthu-images .paginate span').text(current_page + ' of ' + total_images);
    }
    
    return false;
  });
  
  $('.enthu-images .paginate .next').live("click", function(){
    if(! $(this).hasClass('inactive')) {
      $('.enthu-images .img-' + current_page).hide();
      current_page += 1;
      $('.enthu-images .img-' + current_page).show();
    
      if(current_page == 1)
        $('.enthu-images .paginate .prev').addClass('inactive');
      else
        $('.enthu-images .paginate .prev').removeClass('inactive');
    
      if(current_page == total_images)
        $('.enthu-images .paginate .next').addClass('inactive');
      else
        $('.enthu-images .paginate .next').removeClass('inactive');
    
      $('.enthu-images .paginate span').text(current_page + ' of ' + total_images);
    }
    
    return false;
  });
});