/*
 * This is for switching between the thumbnail sizes when viewing a job
 * 
 */
$(document).ready(function() {
  selectAllPhotos = function() {
    $('.job-photos input').each(function() {
      $(this).attr('checked', 'checked');
    });
    $('#bulk_selection').val('none');
  };

  selectNonePhotos = function () {
    $('.job-photos input').each(function() {
      $(this).attr('checked', '');
    });
    $('#bulk_selection').val('none');
  };
  
  selectAllPhotosInJob = function() {
    $('.job-photos input').each(function() {
      $(this).attr('checked', 'checked');
    });
    $('#bulk_selection').val('all');
  };
  
  selectBatchPhotos = function () {
    var selectedBatch = $('.upload-selector')[1].value
    selectNonePhotos();
    $('.job-photos li.batch_' + selectedBatch).each(function() {
      $(this).find('input').attr('checked', 'checked');
    });
    $('#bulk_selection').val(selectedBatch);
    jAlert("Upload Batch #" + selectedBatch + " selected")
    hideOverlay();
  }
})

CURRENT_THUMBNAIL_SIZE = 'small';
function setThumbnailSize(bIncrease) {
  sizes = ['tiny', 'small', 'medium'];

  //What is our current size?
  current_idx = 0
  for (i = 0; i < sizes.length; i++) {
    if (sizes[i] == CURRENT_THUMBNAIL_SIZE)
      current_idx = i;
  }

  //We might not have to do anything
  if (bIncrease && current_idx >= sizes.length - 1)
    return;
  if (!bIncrease && current_idx == 0)
    return;

  //Set the new size
  current_idx = bIncrease ? (current_idx + 1) : (current_idx - 1); 
  CURRENT_THUMBNAIL_SIZE = sizes[current_idx];
  for (i = 0; i < sizes.length; i++) {
    if (i == current_idx)  
      $('.job-photos li.' + sizes[i]).each(function() { $(this).attr('style', 'display:inline-block'); });
    else
      $('.job-photos li.' + sizes[i]).each(function() { $(this).hide(); });
  }
}
