/**
 * 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() {
        // Always return each...
        return this.each(function() {
                var t = jQuery(this);

                // Set position to other than 'static' so element shrink-wraps and width/height is calculated properly
                t.css({position: 'fixed'});

                // Why are there no jQuery.fn.outerWidth/Height:s?
                var w = t.width(), 
                        h = t.height(), 
                        lrPadding = parseInt(t.css('paddingLeft'), 10) + parseInt(t.css('paddingRight'), 10), 
                        lrBorder = parseInt(t.css('borderLeftWidth'), 10) + parseInt(t.css('borderRightWidth'), 10), 
                        tbPadding = parseInt(t.css('paddingTop'), 10) + parseInt(t.css('paddingBottom'), 10), 
                        tbBorder = parseInt(t.css('borderTopWidth'), 10) + parseInt(t.css('borderBottomWidth'), 10), 
                        leftMargin = (w + lrPadding + lrBorder) / 2;
                        topMargin = (h + tbPadding + tbBorder) / 2;
						
				 
				if ( jQuery.browser.msie ) jQuery.browser.version = (window.navigator.userAgent.match( /ie ([\d.]+)/ig ) || []) .sort().pop().replace( /[^\d.]/g, '' ); 
				
				if(jQuery.browser.version == 6) {
					 
					  t.css({
							position: 'absolute', 
							left: '50%', 
							top: '0', 
							marginLeft: '-' +leftMargin +'px', 
							marginTop:  jQuery(window).scrollTop() + 200 +'px', 
							zIndex: '99'
					});
				}else{
				
					t.css({
							position: 'fixed', 
							left: '50%', 
							top: '50%', 
							marginLeft: '-' +leftMargin +'px', 
							marginTop: '-' +topMargin +'px', 
							zIndex: '99'
					});
				}
				//t.css({left: '500px', top: topPos +'500px', zIndex: '1000', 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();

                // 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'});
                */
        });
};


jQuery.fn.centerV = function () {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            //position:    absolute ? 'absolute' : 'fixed', 
            //left:        '50%', 
           //top:         '50%', 
           //zIndex:        '99'
        }).css({
            marginLeft:    ((t.parent().width() / 2) - (t.width() / 2))  + 'px'
           
        });
    });
};