jQuery.fn.checkAll = function(status){
	var allChecked = false;
	$('input:checkbox', this).each(
		function(i, item){
			if(item.name != 'ids[]') return;
			item.checked = status;
		}
	);
	if (deleteBtnDriver != undefined ) deleteBtnDriver();
	else{
		if (status) $('button:#delete').fadeIn(); else $('button:#delete').fadeOut();
	}
	return this;
}

function stopEvent(event){
	event.cancelBubble = true;
	if (event.stopPropagation)
		event.stopPropagation();
}

var Overlay = {
	on: function(onshow){
		Overlay.position();
		$(window).bind('scroll', Overlay.position).bind('resize', Overlay.position);
		if(jQuery.support.opacity){
			$('#overlay').fadeIn('normal', onshow);
		}else{
			$('#overlay').show();
			if (onshow != null) onshow();
		}
	},
	off: function(){
		if(jQuery.support.opacity){
			$('#overlay').fadeOut();
		}else{
			$('#overlay').hide();
		}
		$(window).unbind('scroll', Overlay.position).unbind('resize', Overlay.position);
	},
	position: function(){
		$('#overlay').css({
			width:  $(document).width(),
			height: $(document).height(),
			top: 0,
			left: 0
		});
	}
}
jQuery.fn.isVisible = function(){
	return this.is(':visible');
}
jQuery.fn.keepInCenter = function(){
		this.moveToWindowCenter(false);
		var obj = this;
		obj.moveToWindowCenterHandler = function(){ obj.moveToWindowCenter(true);}
		$(window).bind('scroll', obj.moveToWindowCenterHandler)
				.bind('resize', obj.moveToWindowCenterHandler);
		return this;
};
jQuery.fn.stopKeepingInCenter = function(){
		var obj = this;
		$(window).unbind('scroll', obj.moveToWindowCenterHandler)
				.unbind('resize', obj.moveToWindowCenterHandler);
		return this;
};
jQuery.fn.moveToWindowCenter = function(animate){
	var x = ($(window).width() - this.width())/2 + $(window).scrollLeft();
	var y = ($(window).height() - this.height())/2 + $(window).scrollTop();
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	if (animate == undefined) animate = false;
	if (animate){
		this.stop().animate({left: x, top: y}, 300);
	}else{
		this.css({left: x, top: y});
	}
	return this;
};

var PopupHide = {
	timer: null,
	show: function(obj){
		if (PopupHide[obj.id] != null) clearInterval(PopupHide[obj.id]);
		else $(obj).show();
	},
	hide: function(obj){
		PopupHide[obj.id] = setTimeout("PopupHide['" + obj.id + "'] = null; $('#" + obj.id + "').hide()", 300);
	}
}
function ajaxFormSubmitOverlayed(form, onSuccess, options){
	var overlay = $("<div>loading...</div>").addClass("overlay").hide();
	overlay.css({
		position: "absolute", 
		top: $(form).position().top, 
		left: $(form).position().left,
		width: $(form).width(),
		height: $(form).height()
	});
	$(form).after(overlay);
	overlay.fadeIn();
	if (options == undefined) options = {};
	var oc1 = null;
	if (options.onComplete  != undefined){
		oc1 = options.onComplete;
	}else{
		oc1 = function(){}
	}
	options.onComplete = function(){
		$('div.overlay').stop().fadeOut('fast', function(){ $('div.overlay').remove(); } );
		oc1();
	};
	options.postBody = $(form).serialize();
	options.onSuccess = onSuccess;
	ajaxRequest(form.action, options);	
	return false;
}
