$(document).ready(function () {

   // Attach lightbox (as gallery of images on the page)
   $("a[rel=lightbox]").lightBox();
   
   
   /* Dynamically add structural elements to image-based boxes to simplify WYSIWYG code
   ---------------------------------------------------------------------------------------- */
   // Blockquote
   $('blockquote')
      .wrapInner('<div class="blockquote-content"></div>')
      .append('<div class="blockquote-bottom"></div>');

   // Sketch-box
   $('div.sketch-box')
      .wrapInner('<div class="sketch-box-content"></div>')
      .append('<div class="sketch-box-bottom"></div>');

   // Paint-box
   $('div.paint-box').each(function () {
       var paintBox = $(this);
       paintBox.wrapInner('<div class="paint-box-content"></div>');
       
       var img = new Image();
       $(img).load(function () {
           var canvas = document.createElement('canvas');
           paintBox.append(canvas);
       
           if ($.browser.msie) {
               canvas = window.G_vmlCanvasManager.initElement(canvas);
           }
       
           canvas.width = paintBox.width();
           canvas.height = paintBox.height();
            
           var context = canvas.getContext("2d");
           context.drawImage(this, 0, 0, canvas.width, canvas.height);
       });

       setTimeout(function () {
           // IE8 excanvas seems to intermittently fail if this statment isn't delayed.
           img.src = '/images/front/paint-box.png';
       }, 100);
   });

   // Photo-frame in Course description correction
   $('body.course div.course-description div.photo-frame').each(function () {
      var descriptionHeight = $('div.course-description').height();
      var photoFrameHeight = $(this).height();
      
      if (descriptionHeight > photoFrameHeight) {
         $(this).css({ 'margin-bottom' : (descriptionHeight - photoFrameHeight) + 20 });  // Add back the -20 top margin.
      }
   });

});

