Add lightbox to img with variable sources

Add lightbox to img with variable sources

Hello,
I have a simple image swap function. You hove over thumbnails and a larger img is displayed in #main-img. However, how would I make it where when the #main-image is clicked, the variating src is selected and then linked to the actual image file.

Pseudo:
If  #main-img' clicked, THEN select current src and link to images/src.jpg

I hope that makes sense and thanks in advance to whoever can help!

  1. $(document).ready(function() {
  2.     // Image swap on hover
  3.     $(".imgBank ul li a img").hover(function(){
  4.         $('#main-img').attr('src',$(this).attr('src').replace('images/large/', ''));
  5.     });
  6.     // Image preload
  7.     var imgSwap = [];
  8.      $(".imgBank ul li a img").each(function(){
  9.         imgUrl = this.src.replace('large/', '');
  10.         imgSwap.push(imgUrl);
  11.     });
  12.     $(imgSwap).preload();
  13. });
  14. $.fn.preload = function() {
  15.     this.each(function(){
  16.         $('<img/>')[0].src = this;
  17.     });
  18. }