/**
 * @author dannyreed
 * @email dannyreed@google.com
 * @param {thumbs} String containing jQuery selector of thumbnails
 * @param {images} String containing jQuery selector of images to show/hide
 */
var showHideImages = function(thumbs, images) {
  var __instance__ = this;
  this.clicked;
  this.thumbs;
  
  /**
   * Get ID of clicked elt, for FF compatibility
   * @param {jQuery.object} jQuery object of clicked elment
   * @return {string}
   */
  this.getId = function(clicked) {
    return clicked.attr('id').split('-')[1];
  };
  
  /**
   * Reset all descriptions/images on click event to prepare for showHide()
   */
  this.reset = function() {
    $('.img, .description').css({'display': 'none'});
    $(thumbs + ' > div').css({opacity:1});
  };
  
  this.showPage = function(clicked) {
    clicked.css({opacity:.5});
    $('#img-' + this.getId(clicked)).fadeIn(350);
    $('#description-' + this.getId(clicked)).fadeIn(350);
  };
  
  this.uploadPanel = function(clicked) {
    //change value to the clicked thumb's ID
    $('input[name=location]').attr('value',this.getId(clicked));
    $('#upload_panel').show();
    $('input.description_admin').hide().eq( clicked.index() ).fadeIn(350);
  };
  
  this.showHide = function(clicked, admin) {
    this.reset();
    this.showPage(clicked);
    if(admin == true ) {
      this.uploadPanel(clicked);
    };
  };

  /** Initialize */
  $('#img-1, #description-1').show();
  $('div' + thumbs + ' > div' ).click(function() { __instance__.showHide($(this), true); });
   
};

$(document).ready(function() {
  showhideimages = new showHideImages('#thumbs','#main');
  showhideimagesAdmin = new showHideImages('#thumbs_admin','#main');
  showhideimages = null;
  showhideimagesAdmin = null;
});
