jQuery(function ($) {
	var timer;
	var server_id;
	
	$("a.status").click(function (e) {
		e.preventDefault();
		$(this).each(function() {server_id = $(this).attr('id');});
		$("#status-content").modal({containerId: 'status-bar', closeClass: 'status-close', transient: true, position: ['0',], onOpen: status_bar.open, onClose: status_bar.close});
	});

	var status_bar = {
		container: null,
		open: function (e) {
			var self = this;
			
			if (!$('#status-bar').is(':hidden')) {
				$.modal.close();
			}
			
			self.container = e.container[0];
			$("#status-content", self.container).load('/status/' + server_id, function() {
				e.container.slideDown(100, function () {
					e.container.animate({height: 120}, 200, function() {
						$("#status-content", self.container).show();
						timer = setTimeout(function () {$.modal.close()}, 2000);
					});
				});
			});
		},
		close: function (e) {
			clearTimeout(timer);
			e.container.animate({top:"-" + (e.container.height() + 20)}, 500, function () {$.modal.close();}
			);
		}
	};
});