/*
 * File: zoom.js
 * Created: 11/07/2008
 * Description:
 *
 * Creates jQuery behaviors for zooming in on a modal dialog box.
 * Requires jQuery and SimpleModal.
 *
 * References:
 * jQuery         http://jquery.com/
 * SimpleModal    http://www.ericmmartin.com/projects/simplemodal/
 */
 
// Global var to save the modal dialog boxes in an indexed array.
var modals = [];

$(document).ready(function() {
  // Save the modal dialog boxes (matching class "figurezoom") and their heights in our global var.
  $('.figurezoom').each(function(i) {
    modals[i] = { dialog: this, height: $(this).outerHeight() }; 
  });
    
  // Find all the figures (matching class "figure") and attach click behaviors to all links in the figure.
  // Assumes figures and their corresponding dialogs are in the document in corresponding order.
  $('.figure').each(function(i) {
    $(this).find('a').click(function(e) {
      // Disable default link behavior.
      e.preventDefault();
      
      // Display the dialog by index if one is found.
      if (modals.length > i) {
        var modal = modals[i];
        // Open the dialog with the appropriate height.
        $(modal.dialog).modal({ containerCss: { height: modal.height } });
      }
    });
  });
});
