// Create the tooltips only on document load
$(document).ready(function($) 
{
   // Notice the use of the each method to gain access to each element individually   
   $('.hoverpreview a').each(function()
   {
		// we want a static position for the large image, so find out the middle thumb
		//var num_of_img = $('.hoverpreview img').length;
		var num_of_img = $(this).parent().siblings().length;
		//num_of_img++;
	
		var middleimg=0;	
		if ((num_of_img%2)<1){	
			middleimg = (num_of_img/2); //even number
			
		} else {
			middleimg = (Math.floor(num_of_img/2))+1;
			
		}
			
      var content = '<img src="';
      content += $(this).attr('href');
      content += '" alt="Loading image..." />';
      
      // Setup the tooltip with the content
      $(this).qtip(
      {
         content: content,
         position: {
         	//target: $('.hoverpreview img:eq('+(middleimg-1)+')'),
         	target: $(this).closest(".hoverpreview"),
         	adjust: { y: -4 },
            corner: {
               tooltip: 'bottomLeft',
               target: 'topLeft'
            }
         },         
         style: {
            tip: false, // Give it a speech bubble tip with automatic corner detection
            name: 'blue',
            width: 520            
         }
      });
   });
    $('.hoverpreview a').click(function(event){
    	return false;
		event.preventDefault;
	});   
});

