// :todo: modularise, remove dup code and optimise image caching

$(document).ready(function() {

   //
   var int_index = -1;

   // needed this on the off chance they're over an image without a hover
   // :todo: duplicate code
   $('.image_group img').click(function(){
      var str_source = $(this).attr('src');
      var int_image_id = str_source.match( /media\.php\/([\d]+)\// )[1];

      int_index = $('.image_group img').index(this);
      //var str_caption = $('.images .image h3').eq(int_index).html(); // replace closest
      var str_caption = '';
      tb_show(str_caption, '/media.php/' + int_image_id + '/1000/0');

      return false;
   });

});

/*
$(window).load(function() {
   var int_index = -1;

   // pre load hover images
   var arr_hover_preloads = [];
   $('#hoverer_source img').each(function() {
      obj_image_hover = new Image();
      obj_image_hover.src = $(this).attr('src');
      arr_hover_preloads.push(obj_image_hover);
   });


   $('.image img').hover(function(){
      int_index = $('.images img').index(this);

      $('#hoverer').empty().append("<img src='" + arr_hover_preloads[int_index].src + "' />");

      var int_hoverer_left = $(this).offset().left - ((arr_hover_preloads[int_index].width- $(this).width()) / 2);
      var int_hoverer_top = $(this).offset().top - ((arr_hover_preloads[int_index].height - $(this).height()) / 2);

      $('#hoverer').css('left', int_hoverer_left).css('top', int_hoverer_top).show();
   });


   $('#hoverer').hover(function(){}, function() {
       $('#hoverer').hide();
   });


   $('#hoverer').click(function() {
      $('#hoverer').hide();

      var str_source = $('img', this).attr('src');
      var int_image_id = str_source.match( /media\.php\/([\d]+)\// )[1];

      var str_caption = $('.images .image h3').eq(int_index).html();

      tb_show(str_caption, '/media.php/' + int_image_id + '/1000/0');
      return false;
   });
});
*/
