// Setup up the gallery page
function initGallery(defaultGallery)
{
  $('a.gallery_image').fancybox({
    'zoomSpeedIn':  500,
    'zoomSpeedOut': 500,
    'zoomOpacity':  true,
    'overlayShow':  true,
    'imageScale':   true
  });

  showGallery(defaultGallery);
}

var currentGallery = null;
function showGallery(galleryName)
{
  if(currentGallery != null)
  {
    $('#gallery_images_' + currentGallery).hide();
    $('#gallery_nav_' + currentGallery).removeClass('current');
  }
  $('#gallery_images_' + galleryName).fadeIn();
  $('#gallery_nav_' + galleryName).addClass('current');
  currentGallery = galleryName;
  return false;
}

function initProductGallery()
{
  $('a.gallery_image').fancybox({
    'zoomSpeedIn':  500,
    'zoomSpeedOut': 500,
    'zoomOpacity':  true,
    'overlayShow':  true,
    'imageScale':   true
  });
}

function loadSwatchGallery(url)
{
  $('#swatch_viewer').attr('src', url);
}

function showLoader()
{
  $('#swatch_viewer').css('opacity', 0);
  $('#swatch_viewer').before('<img id="loader" src="/images/ajax-loader.gif"/>');
  setTimeout('hideLoader()', 1000);
}

function hideLoader()
{
  $('#loader').remove();
  $('#swatch_viewer').css('opacity', 1);
}

$(document).ready(function() {
  $('a.swatch-window').click(function(e) {
    e.preventDefault();
    loadSwatchGallery(e.currentTarget.href);
    $('#swatch_window').modal({
      onShow: function() {
        if($('#swatch_window').css('visibility') != 'visible')
          $('#swatch_window').css('visibility', 'visible');
      }
    });
    showLoader();
  });
});