$(document).ready(function() {
	
	workClick();
	
	$("a.delentry").click(function() {
	
		var url = $(this).attr("href");
		
		if(confirm("Czy na pewno chcesz usunąć wpis?")) {
		
			$(this).ajaxSubmit({
				dataType: 'json',
				url: url,
				type: 'post',
				success: function(re,st) {
					if(re.result == "ok") {
						window.location = re.value;
					} else if(re.result == "error") {
						alert(re.value);
					}
				},
				error: function() {
					alert("Wystąpiły problemy techniczne");
				}
			});
		
		}
		
		return false;
	
	});
	
});

	function workClick() {
		$("a.enlarge").click(function() {

			var src = $(this).attr("href");
			
			function close() {
				$("#enlarge").unbind();
				$("div.poltergeist").unbind();
				$("#imgclose").unbind();
				$("#imgclose").fadeOut(150, function() {
					$(this).remove();
				});
				$("#enlarge").fadeOut(500, function() {
					$(this).remove();
					removePoltergeist();
				});
			}
			
			$("body").append('<img id="tempimg" src="'+src+'"/ >');
			$("#tempimg").load(function() {
				createPoltergeist();
				$("div.poltergeist").css("opacity","0.6");
				$("div.poltergeist").click(function() {
					close();
				});
				var enw = $("#tempimg").outerWidth();
				var enh = $("#tempimg").outerHeight();
				genZdzivBox(enw,enh,5,"enlarge",true,false);
				var off = $("#enlarge").offset();
				$("#enlarge").hide();
				$("#tempimg").remove();
				$("#enlarge").append('<div id="enlargeimg"></div>');
				$("#enlargeimg").append('<img id="closeS" style="float: right; padding-left: 2px; padding-bottom: 2px; background: white; cursor: pointer;" alt="close" src="/global/images/close.gif"/>');
				$("#enlargeimg").css("width",enw+"px");
				$("#enlargeimg").css("height",enh+"px");
				$("#enlargeimg").css("background-image","url('"+src+"')");
				$("#enlarge").fadeIn(500);
				$("#imgclose").fadeIn(500);
				$("#enlarge").click(function() {
					close();
				});
				$("#imgclose").click(function() {
					close();
				});
			});
			
			return false;
	
		});
	}
