/*
 * Verify that jquery.js is loaded.
 */
if (typeof(includejs) == 'function')
{
	if (typeof(jQuery) == 'undefined') includejs('/javascripts/jquery.js');
}
else
{
	msg = typeof(jQuery) == 'undefined' ? '\tjquery.js\n' : '';
	if (msg != '')
	{
		alert
		(
			'jquery.center.js requires:\n\n' +
			msg +
			'\nLoad includejs.js to insure that all necessary jQuery libraries are automatically loaded.'
		);
	}
}

/**
 * jQuery method for centering an element within its container (parent) element.
 * 
 * @extends	jQuery
 * @returns	void
 * @author	Rory Glasgow <rory.glasgow@wsdtx.org>
 */
jQuery.fn.center = function()
{
	return this.each
	(
		function()
		{
			/*var parent_width = jQuery(this).parent().width();
			var parent_height = jQuery(this).parent().height();*/
			var parent_width = document.documentElement.clientWidth;
			var this_width = jQuery(this).width();
			var this_left = Math.floor((parent_width - this_width) / 2);
			var parent_height = document.documentElement.clientHeight;
			var this_height = jQuery(this).height();
			var this_top = Math.floor((parent_height - this_height) / 2);
			jQuery(this).css('left', this_left + 'px').css('top', this_top + 'px');
		}
	);
};
