﻿$(document).ready(function() {

     //Photo gallery widget conversion to shadowbox
     var galID = 0;
     
     //add ul to each photogallery
     $(".widgetPhotoGallery").each(function(){      
               
          $(this).append("<ul style='padding: 0;'></ul>").addClass("shadowBoxGallery").attr({ id: "gallery" + galID});
     
          $(this).find(".galleryImgThumb").each(function(){
          
               //the background image of the thumbnail's "A" tag, contains the actual thumbnail image.
               //let's steal that source
               var thumbnailSrc = $(this).css('backgroundImage');
               var thumbnailSrc = thumbnailSrc.replace('url(', '').replace(')', '');
               
               //the href of the thumbnail's "A" tag contains the link to the larger image.
               var largeImg = $(this).attr("href");
               
               //oh, and grab some title stuff
               var imgDesc = $(this).attr("title")
               
               //append <li>'s to the shadowbox container
               //the li includes the thumbnail, and a link to the larger image
               $("#gallery" + galID + " ul").append("<li class='shadowBoxThumbs'><a title='" + imgDesc + "' href=" + largeImg + " rel='shadowbox[gallery" + galID + "]'><img src=" + thumbnailSrc + " /></a></li>");
               
     
          });
     
     galID += 1;
     
     });
     
     $(".shadowBoxThumbs").css({"list-style-type" : "none", "display" : "inline"});
     //ditch the old photogallery
     $(".galleryImgFullShell, .imgDescriptionShell, .imgPreviousNextShell, .imgThumbnailsOuterShell").remove();
     //reinitialize shadowbox
     Shadowbox.setup();
     
     //add email address
     $('#address').append('<a href="mailto:info@northwestpoint.com">info@northwestpoint.com</a>');

});
