$(document).ready(function() {
	overlayMouseMove ();
});


//AJAX request für die weiteren Strecken incl. Pager
function getAdditionalGalleryData (url)
{
	$.ajax({
		url: url,
		success: function(data) {
			$('#overviewLineOnGalleryPage').html(data);
			overlayMouseMove ();
		}
	});
}

// Initialisiert das MouseMove / MouseOver
function overlayMouseMove ()
{
	var thumbHeight		= 99;
	var offsetX 		= -2;
	var offsetY 		= -68;
	var offsetLastPic 	= 39;
	var offsetRight		= 603;
	
	
	// Bei Mousebewegung über die Thumbnails
	$('.imageOverview, #teaserOverlayHref').hover(
		function(){
			
			// Positionen des this-Objektes
			if ($(this).attr('id') != 'teaserOverlayHref')
			{
				var thumbX = $(this).offset().left + offsetX;
				var thumbY = $(this).offset().top + offsetY;

				// Das ganz rechte Bild muss anders behandelt werden, damit es nicht über den rechten Rand läuft.
				if ( thumbX > offsetRight)
				{
					thumbX = thumbX - offsetLastPic;
				}
				
				$('#teaserOverlayHref').css('left', thumbX + 'px');
				$('#teaserOverlayHref').css('top', thumbY + 'px');
				$('#teaserOverlayHref').fadeIn('fast');
				
				var teaser_img = $(this).attr('src').replace('thumb_pixi_zgm/', 'teaser_pixi_zgm/');
				//var teaser_img = $(this).attr('src');
				$('#teaserImg').attr('src', teaser_img);
				$('#teaserImg').attr('alt', $(this).attr('alt'));
				$('#teaserImg').attr('title', $(this).attr('title'));
				
				// ID aus dem <a> um das thumbnail auslesen 
				var href_id = $(this).attr('id').replace('img', 'href');
				// und das href attribut zuweisen
				var gal_href = $('#' + href_id).attr('href');
			}
			
			if (gal_href)
			{
				// Nun dem Teaser Overlay das href zuweisen
				$('#teaserOverlayHref').css('display', 'block');
				$('#teaserOverlayHref').attr('href', gal_href);
				$('#teaserImg').click(function(){
					location.href = gal_href;
				});
			}
		},
		function (){
			if ($(this).attr('id') == 'teaserOverlayHref')
			{
				$('#teaserOverlayHref').hide();
			}
		}
	);
}

