(function($) {
	$(document).ready(function() {
		/* AJAX Window */
		$('a[rel="ajax"]').click(function() {
			_window = $("<div></div>");
			_window
				.click(function() {
					$("#ajax_popup").remove();
					$(this).remove();
				
				})
				.css({
					position: "fixed",
					zIndex: 100,
					top: 0,
					left: 0,
					width: "100%",
					height: "100%",
					background: "black",
					opacity: .75
				
				});
			
			$("body").append(_window);

			_popup = $("<div></div>");
			_popup.attr("id", "ajax_popup");
			
			$("body").append(_popup);
		
			
			$("#ajax_popup").load(
				$(this).attr("href") + " .ajax_body",
				{},
				function() {
					$(".ajax_body", $("#ajax_popup"))
						.attr("id", "ajax_inside")
						.attr("class", "content");
					
					
					_height = $("#ajax_popup").height() + 20;
					if(_height > $(window).height() - 100) _height = $(window).height() - 100;
				
					_width = 600;
					if(_width > $(window).width() - 100) _width = $(window).width() - 100;
				
					_top = ($(window).height() - _height) / 2;
					_left = ($(window).width() - _width) / 2;
						
						
					$("#ajax_popup").attr("id", "ajax_popup")
						.css({
							position: "fixed",
							zIndex: 150,
							top: _top,
							left: _left,
							width: _width - 20,
							height: _height - 20,
							background: "white",
							padding: "10px",
							"-moz-border-radius": "1em",
							"-webkit-border-radius": "1em",
							"border-radius": "1em"
						});
					
					$("#ajax_inside").css({
						overflow: "auto",
						width: _width - 30,
						height: _height - 20,
						paddingRight: "10px"
					});
					
				}
			);
			
			
			return false;		
		});

	});
})(jQuery);