var ironboxendx = 0;
var ironboxendy = 0;

(function($) {
	$.fn.ironbox = function(){
		if($("#ironbox").length == 0){
			$("body").append("<div id='ironbox' style='padding: 20px; opacity: 0; " +
					"background-color: #DFDECB;" +
					"-webkit-border-radius: 10px;" +
					"-moz-border-radius: 10px;" +
					"border-radius: 10px; -moz-box-shadow: 0 0 15px 5px #525252; -webkit-box-shadow: 0 0 15px 5px #525252; box-shadow: 0 0 15px 5px #525252;" +
					"'><img class='img' style='position: relative; width: 100%; height: 100%;'/><img class='close' src='"+baseUrl+"images/close.png' style='position: absolute; cursor: pointer; top: -10px; right: -10px;'/></div>");
			$("#ironbox").css({'position' : 'fixed', 'z-index' : 10000});
			$("#ironbox").hide();
			$("#ironbox img.close").click(function(){
				$("#ironbox img.img, #ironbox img.close").fadeOut(400, function(){
					$("#ironbox").animate({
						width: 0,
						height: 0,
						top: ironboxendy-document.body.scrollTop+'px',
					    left: ironboxendx+'px',
					    opacity: 0
					}, 1000, function(){
						$("#ironbox").hide();
					});
				});
			});
		}
		$(this).click(function(e){
			paddingv = 20;
			paddingh = 20;
			vwysokosc = ($(window).height()-$(this).attr('realheight'))/2-paddingv;
			vszerokosc = ($(window).width()-$(this).attr('realwidth'))/2-paddingh;
			ironboxendx = e.pageX;
			ironboxendy = e.pageY;
			$("#ironbox").stop(true, true);
			$("#ironbox").css({'top' : e.pageY-document.body.scrollTop, 'left' : e.pageX, 'width' : "0px", "height" : "0px"});
			$("#ironbox img.img").attr('src', $(this).attr('href'));
			$("#ironbox img.img, #ironbox img.close").hide();
			$("#ironbox").animate({
				width: $(this).attr('realwidth'),
				height: $(this).attr('realheight'),
				top: vwysokosc+'px',
			    left: vszerokosc+'px',
			    opacity: 1
			}, 1000, function(){
				$("#ironbox img.img, #ironbox img.close").fadeIn(400);
			});
			return false;
		});
	}
})(jQuery);
