(function($){
	$.fn.gallery = function(){
		return this.each(function(){
			var preview = $('.preview', this).get(0);
			$(preview).hover(function(e){
				e.stopPropagation();
			},function(){
				$(preview).hide();
			});
			var container = $(this).get(0);
			$('a', this).hover(function(){
				var top =  $(this).offset().top - $(container).offset().top - 9 - 23 + 80;
				var left =  $(this).offset().left - $(container).offset().left - 9 + 23 +20;
				var rel = jQuery.parseJSON($('img', this).attr('rel'));
				$('img', preview).attr('src', rel.photo);
				$('a', preview).attr('href', $(this).attr('href'));
				$(preview).css({'top': top, 'left': left});
				$(preview).show();
			},
			function(){
				//$(preview).hide();
			});



		});
	}
})(jQuery)

$(document).ready(function(){
	$('.main-div').gallery();
});
