/*
 Sets ability to centerize window

 Dependencies: 
 	jQuery Lib - http://jquery.com/
*/
(function($) {
	$.fn.extend({
		show_center : function(){
			// default values
			var s = this;
			s.setPosition();
			s.bindEvents();
		},
		/* setPosition */
		setPosition: function () {
			var s = this, block = $(s);

			w = s.getDimensions();

			var top = (w[0]/2) - (block.outerHeight(true)/2),
				left = (w[1]/2) - (block.outerWidth(true)/2);

			block.css({ left: left, top: top });
		},
		/* getDimensions */
		getDimensions: function () {
			var el = $(window);

			// fix a jQuery/Opera bug with determining the window height
			var h = $.browser.opera && $.browser.version > '9.5' && $.fn.jquery <= '1.2.6' ? document.documentElement['clientHeight'] :
				$.browser.opera && $.browser.version < '9.5' && $.fn.jquery > '1.2.6' ? window.innerHeight :
				el.height();

			return [h, el.width()];
		},
		/*
		 * Bind events
		 */
		bindEvents: function () {
			var s = this;
			
			// update window size
			$(window).bind('resize.simplemodal', function () {
				// redetermine the window width/height
				//w = s.getDimensions();
				// reposition the dialog
				s.setPosition();
			});
		},
		/*
		 * Unbind events
		 */
		unbindEvents: function () {
			$(window).unbind('resize.simplemodal');
		}
	})
})(jQuery);
