var ThumbnailControl = {
  init: function() {
    this.images = $("a", $("#e_p_large"));
    $("#e_p_large").after('<ul id="thumbs"></ul>');
    this.images.each(
      function (i) {
        $(this)[0].id = "img" + parseInt(i + 1);
        var imgWidth = 0, imgHeight = 0;
        if ($(this).find("img:eq(0)").width() > $(this).find("img:eq(0)").height()) {
          imgWidth  = 100;
          imgHeight = 56;
        }
        else if ($(this).find("img:eq(0)").width() < $(this).find("img:eq(0)").height()) {
          imgWidth  = 70;
          imgHeight = 100;
        }
        else {
          imgWidth  = 70;
          imgHeight = 100;
        }
        var source = $(this).find("img:eq(0)").src().replace(/(h\.[0-9]+)/i, "h." + imgHeight).replace(/(w\.[0-9]+)/i, "w." + imgWidth)
        var str = '<li><a href="#" onclick="return ThumbnailControl.show(this, ' + parseInt(eval(i) + 1) + ');" ';
        str += 'style="background-image: url(' + source + ');">';
        str += '<img src="' + source + '" alt="" /></a></li>';
        $("#thumbs").append(str);
        $(this).hide();
      }
    );
    $("#e_p_large a").hide();
    this.show($("#thumbs li a:first")[0], 1);
  },
  show: function(node, number) {
    $("#thumbs li a").removeClass("active");
    $(node).addClass("active");
    $(this.images).not(":hidden").hide();
    $("#img" + number).show();
    return false;
  }
}