function $(element) {
	if (arguments.length > 1) {
		for (var i = 0, elements = [], length = arguments.length; i < length; i++)
			elements.push($(arguments[i]));
		return elements;
	} else {
		element = document.getElementById(element);
	}
	return element;
}

function openwindow(page, dialogwidth, dialogheight) {
	dialogheight = parseInt(dialogheight);
	if (dialogheight == NaN)
		dialogheight = 200;

	dialeft = ((screen.width-dialogwidth)/2);
	diatop = ((screen.height-dialogheight)/2);
	
	window.open(page, '', "toolbar=no,scrollbars=yes,location=no,resizable=no,status=no,width="+dialogwidth+",height="+dialogheight+",left="+dialeft+",top="+diatop);
}

function disableElements(elements, disable) {
	disable = (disable == null) ? true : disable;

	if (elements.length > 0) {
		for(i=0; i<elements.length; i++) {
			if (disable == true)
				elements[i].disabled = true;
			else
				elements[i].disabled = false;
		}
	}
}

function checkCloseNotify() {
	if (jQuery('div#notify > div#inner > div.item').get().length == 0)
		jQuery('div#notify').hide('slow');
}

function minimizeNotify(mod) {
	jQuery.get('content/ajax/notify?a=minimize&mod=' + escape(mod), function(data){
		jQuery('div#notify').slideUp('slow', function(){
			jQuery('div#notify').replaceWith(data);
			jQuery('div#notify_minimized').hide();
			jQuery('div#notify_minimized div#maximize').hide();
			jQuery('div#notify_minimized').slideDown('slow', function(){
				jQuery('div#notify_minimized div#maximize').show('slow');
			});
		});
	});
}

function maximizeNotify(mod) {
	jQuery.get('content/ajax/notify?a=maximize&mod=' + escape(mod), function(data){
		jQuery('div#notify_minimized').slideUp('slow', function(){
			jQuery('div#notify_minimized').replaceWith(data);
			jQuery('div#notify').hide();
			jQuery('div#notify').slideDown('slow');
		});
	});
}

function removeNotifyItem(obj, mod) {
	row = jQuery(obj).parent();
	jQuery.get('content/ajax/notify?a=remove&ID=' + row.children('input').attr('value') + '&mod=' + escape(mod),
		function() {
			row.slideUp('fast', function() {row.remove(); checkCloseNotify()});
		});
}

function toggleNotifyItemRemove(obj) {
	obj = jQuery(obj).children('.close').get(0);
	obj.style.display = (obj.style.display == 'block' ? 'none' : 'block');
}

function submenuShow(id) {
	var node = jQuery('div#MenuFloat' + id);
	if (node.length == 0)
		return;

	if (node.get(0).timeout)
		clearTimeout(node.get(0).timeout);

	node.get(0).timeout = setTimeout(function() { node.slideDown('fast') }, 100);
}

function submenuHide(id) {
	var node = jQuery('div#MenuFloat' + id);
	if (node.length > 0) {
		if (node.get(0).timeout)
			clearTimeout(node.get(0).timeout);
		node.get(0).timeout = setTimeout(function() { node.slideUp('fast') }, 100);
	}
}
