/**
 * ColourPicker 1.0
 *
 * Centers all matched elements using position: fixed (no IE)
 *
 * Usage: jQuery('div.img-overlay').center();
 *
 * @class center
 *
 * Copyright (c) 2008 Andreas Lagerkvist (andreaslagerkvist.com)
 * Released under a GNU General Public License v3 (http://creativecommons.org/licenses/by/3.0/)
 */
jQuery.fn.center = function( aNudge ) {
	// Always return each...
	return this.each(function() {
   
      // Different for IE6
      if ( navigator.userAgent.toLowerCase().indexOf('msie 6') != -1 ) {
         
         jQuery(this).css({position: 'absolute'});
   
   		/* Use this code if you care about IE<7, this requires the dimensions plug-in tho */
   		// Calculate left and top pos values
   		var leftPos = (jQuery(window).width() - jQuery(this).outerWidth()) / 2 + jQuery(window).scrollLeft(), 
   			topPos = (jQuery(window).height() - jQuery(this).outerHeight()) / 2 + jQuery(window).scrollTop();
   
         topPos = topPos * ( typeof( aNudge ) == "undefined" ? 1 : 0.9 );
   
   		// Make sure element is not out of bounds
   		leftPos = (leftPos < 0) ? 0 : leftPos;
   		topPos = (topPos < 0) ? 0 : topPos;
   
   		jQuery(this).css({left: leftPos +'px', top: topPos +'px', zIndex: '1000'});
      }
      // Else, good browsers
      else {
      
         var t = jQuery(this);

         // Use absolute positioning if the popup is larger than the screen
         if ( jQuery(window).height() < t.outerHeight() ) {
      
            // Set position to other than 'static' so element shrink-wraps and width/height is calculated properly
            t.css({position: 'absolute'});
      
            var lTop = Math.max( ( ( jQuery(window).height() - t.outerHeight() ) / 2 ), 0 ) + "px";
            
            t.css({
               position: 'absolute',
               left: '50%', 
               top: lTop,
               marginLeft: '-' + ( t.outerWidth() / 2 ) + 'px', 
               zIndex: '99'
            });
         }
         // Else, the screen is big enough
         else {
      
            // Set position to other than 'static' so element shrink-wraps and width/height is calculated properly
            t.css({position: 'fixed'});
      
            var lTop = ( typeof( aNudge ) == "undefined" ? "50%" : "40%" );
            
            t.css({
               position: 'fixed',
               left: '50%', 
               top: lTop,
               marginLeft: '-' + ( t.outerWidth() / 2 ) + 'px', 
               marginTop: '-' + ( t.outerHeight() / 2 ) + 'px', 
               zIndex: '99'
            });
         }
      }
	});
};
/*
// If dimensions plug-in isn't available
// Why is there no jQuery.fn.outerWidth bundled with jQuery?
if(!jQuery.fn.outerWidth) {
	jQuery.fn.outerWidth = function() {
		var t = jQuery(this[0]), 
			w = t.width(), 
			lrPadding = parseInt(t.css('paddingLeft'), 10) + parseInt(t.css('paddingRight'), 10), 
			lrBorder = parseInt(t.css('borderLeftWidth'), 10) + parseInt(t.css('borderRightWidth'), 10);

		return w + lrPadding + lrBorder;
	};
}
if(!jQuery.fn.outerHeight) {
	jQuery.fn.outerHeight = function() {
		return this.each(function() {
			var t = jQuery(this)[0], 
				h = t.height(), 
				tbPadding = parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10), 
				tbBorder = parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10);

			return h + tbPadding + tbBorder;
		});
	};
}
*/
