$(document).ready(function(){
	
	var prevCounter = 0;
	$("a[href$='jpg.html'][href*='core/gallery']").map(function () {
		prevCounter ++;
		var popupId = 'blogImagePreview-' + prevCounter;

		href = $(this).get(0).href.replace("core/gallery", "core/img/popup-thumbnail").replace(".html","");
		if (href.indexOf('panoramy') >= 0) {
			return;
		}

		$(this).after("<div class='blogImagePreview' id='" + popupId + "'><table class='blogImagePreviewTable' cellpadding=0 cellspacing=0 border=0><tr><td><img src='"+href+"'></td></tr></table></div>");


		$(this).hover(function(e){
			var offset = 0;

			if (($(this).parent("p.pictureLeft").length > 0) || ($(this).parent("li.pictureLeft").length > 0)) {
				offset = 20 + parseInt($("#pageBody").css("width").replace("px", ""));
			}
			if (($(this).parent("p.pictureRight").length > 0) || ($(this).parent("li.pictureRight").length > 0)) {
				offset = -260;
			}
			$("#"+popupId)
				.css("left", -5 + offset + $("#pageBody").get(0).offsetLeft + "px")
				.animate({"left": "+=5px", "opacity": "toggle"}, 200);
		}, function(){
			$("#"+popupId).animate({"left": "+=5px", "opacity": "toggle"}, 200);
		});


	});
});