nslides = new Object();
var maxWidth = 150;
var maxHeight = 100;
var imageScale = maxWidth / maxHeight;

function showThis(image) {
	selectedImgLI = jQuery('#numberedSlides .slides div ul li:eq('+image+')');
	selectedImgLI.fadeIn();
	selectedImgLI.siblings().fadeOut();
}

jQuery(document).ready(function() {
  var numberedSlides = $('#numberedSlides ul li');
  if (!numberedSlides) return;
  numPics = numberedSlides.size();
  jQuery('#numberedSlides ul li').each(function(i) {
    var eachLi = $(this);
    thisImg = new Array();
    thisImg['li'] = eachLi;
    thisImg['a'] = eachLi.children('a');
    thisImg['img'] = thisImg['a'].children('img');
    thisImg['thisWidth'] = thisImg['img'].width();
    thisImg['thisHeight'] = thisImg['img'].height();
    thisImg['thisScale'] = thisImg['thisWidth'] / thisImg['thisHeight'];
    if (thisImg['thisScale'] < imageScale) { //check for portrait or squarish images
      thisImg['newWidth'] = (thisImg['thisScale'] / imageScale) * maxWidth;
      thisImg['newHeight'] = maxHeight;
    } else { //check for landscaped images
      thisImg['newWidth'] = maxWidth;
      thisImg['newHeight'] = (thisImg['thisScale'] / imageScale) * maxHeight;
    }
    thisImg['text'] = eachLi.children('span');
    nslides[i] = thisImg;
    jQuery("#numberedSlides ul.navigation").append("<li><a href='javascript:showThis(" + i + ");'>" + (i + 1) + "</a></li>");
    nslides[i]['img'].animate({ width: nslides[i]['newWidth'], height: nslides[i]['newHeight'] }, 0);
  });
});
