/**
 * @depends jquery, jquery.fancybox
 * @name jquery.hoprod
 * @package jquery-hoprod {@link http://www.h-o.nl/}
 */
(function($){
$.fn.hoTigerGallery = function(options) {

	var defaults = {};
	
	var options = $.extend(defaults, options);

	return this.each(function() {
		/* Variables */
		var self       = $(this),
			thumbnails = $('.thumbnails a', self),
			introImg   = $('.intro-img', self),
			introOverlay = $('.intro-overlay', self);
			animationCallback = function(){
				$(this).prev().remove();
			}
		
		thumbnails.live('click',function(){
			var thumb = $(this),
				imgWidth = thumb.data('imgWidth');
			
			//show the loader
			$.fancybox.showActivity();
			
			var overlay = $('<div />',{
					'class' : 'overlay',
					'html'  : thumb.data('overlayDescription'),
					'css'   : {
						'background-color' : thumb.data('overlayBgcolor'),
						'width'            : thumb.data('overlayWidth'),
						'left'             : thumb.data('overlayLeft'),
						'top'              : thumb.data('overlayTop'),
						'font-size'		   : thumb.data('overlayFontSize'),
						'opacity'          : 0
					},
				});
				
			var image = $('<img />',{
				'width'    : imgWidth,
				'height'   : thumb.data('imgHeight'),
				'src'      : thumb.data('imgSrc'),
				'css'      : {
					'opacity'     : 0,
					'margin-left' : '-' + (parseInt(imgWidth, 10) / 2) + 'px',
				},
				'load'    : function(){
					//the image is loaded, so we can hide the activity
					$.fancybox.hideActivity();
					
					//set thumbnail active
					thumbnails.removeClass('active');
					thumb.addClass('active');
					
					//the intro image
					introImg.append(image);
					image.animate({'opacity': 1}, 1000, animationCallback);
					
					//the overlay
					introOverlay.append(overlay);
					overlay.animate({'opacity': 1}, 1000, animationCallback);
					
					
					//animate the other overlay away
					var overlayChildren = introOverlay.children();
					
					//make sure there is more than one overlay
					if (overlayChildren.size() > 1)
					{
						overlayChildren.last().prev().animate({'opacity': 0}, 1000);
					}
				}
			});
			
			
		});
		
		thumbnails.first().trigger('click');

		return this;
	});
};
})(jQuery);
