$(document).ready(
function()
{	
	$("a").click(
	function () 
	{	
		if ($(this).attr("rel") == 'asticBox')
		{
			// Utworzenie głównych kontenerów
			$("#body").after('<div id="asticBoxBody"></div>');
			$("#asticBoxBody").animate({opacity: 0.4}, 1);
			$("#asticBoxBody").fadeIn("slow");
						
			var hS = $("#container").height();		
			$("#asticBoxBody").css("height",hS);			
			
			$("#body").after('<div id="asticBoxDiv"></div>');
			$("#asticBoxDiv").hide();
			$("#asticBoxDiv").fadeIn();
			
			/*
			// Pobranie atrybutu link oraz href
			var imgHref = $(this).attr("href");
			if (imgHref != 'javascript:none();')
				$(this).attr("link", imgHref);
			
			$(this).attr("href", "javascript:none();");
			*/
			
			var imgLink = $(this).attr("link");
			var imgTitle = $(this).attr("title");		

			$("#asticBoxDiv").append('<a href="javascript:closeVisualImg();" id="asticBox-close">[X] ZAMKNIJ OKNO</a><br />');
			$("#asticBoxDiv").append('<a href="javascript:closeVisualImg();"><img id="asticBoxImg" src="'+imgLink+'"></a><br /><br />');
			
			$("img#asticBoxImg").load(function () 
			{	
				$("img#asticBoxImg").css("background", "#fff");
				
				if (imgTitle != '')
					$("#asticBoxDiv").append("<b>Opis:</b><br />"+imgTitle);
				
				var w = $("img#asticBoxImg").width();		
				var h = $("img#asticBoxImg").height();	
				
				var pageTop = getPageTop();
				//$("#asticBoxDiv").css("top", "50%");			
				//$("#asticBoxDiv").css("margin-top", "-"+(h/1.8)+"px");	
				$("#asticBoxDiv").css("top", "50px");	
			
				$("#asticBoxDiv").css("margin-left", "-"+(w/2)-40+"px");
				$("#asticBoxDiv").css("width", (w+10)+"px");
				$("img#asticBoxImg").css("position", "static");
				
				
				$("img#asticBoxImg").css({display:"none"});
				$("img#asticBoxImg").fadeIn();
			});	
		}
	});
});


function closeVisualImg() {
	$("#asticBoxBody").fadeOut("fast",
	function() {
		$("#asticBoxDiv").fadeOut("fast", 
		function() {
			$("#asticBoxDiv").remove();
		});
	});
}

function getPageTop() 
{		
	var pageTop = 0

	if(typeof(window.pageYOffset) == 'number')
		pageTop = window.pageYOffset;
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) 
		pageTop = document.body.scrollTop;
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
		pageTop = document.documentElement.scrollTop;

	return pageTop;
}