var firstItem = false;
var openBox = function() {
  Shadowbox.clearCache();
  Shadowbox.setup();
  Shadowbox.open({
    content: firstItem,
    gallery: 'gallery',
    player:  'img'
  });
}

$(function() {
  
  $('.nojs').removeClass('nojs');
  
  $('a[rel*=external], .external-link, .internal-link-new-window, .download').live('click', function() {
    window.open($(this).attr('href'));
    return false;
  });
  
  $('.lightboxImage').live('click', function() {
    Shadowbox.open({
      content: $(this).attr('href'),
      player: 'img',
      title: $(this).attr('title')
    });
    return false;
  });

  $('.lightboxFlash').live('click', function() {
    var url   = '/flashSize.php?f=' + $(this).attr('href')
    var swf   = $(this).attr('href');
    var title = $(this).attr('title');
    $.get(url, function(data) {
      size = data.split('x');
      Shadowbox.open({
        content: swf,
        player: 'swf',
        title: title,
        width: size[0],
        height: size[1]
      });
    });
    return false;
  });
  
  $('.ajaxGallery').live('click', function() {
    var url = $(this).attr('href') + '?ajax';
    $.get(url, function(data) {
      $('#hiddenGallery').remove();
      $('body').append('<div id="hiddenGallery" style="display:none;"></div>');
      eval(data);
      window.setTimeout('openBox();', 0);
    });
    return false;
  });
  
});
