(function ($) {
		   
$.fn.autosize = function (duration, min_w, min_h) {
	if (!duration) {
		this.css ({
			'width'  : 0 + 'px',
			'height' : 0 + 'px'
		});
	}
	
	return this.each (function () {
		var target = {
			'width'  : Math.max ($.gui.dimentions.width (),  typeof (min_w) == 'number' ? min_w : 0) + 'px',
			'height' : Math.max ($.gui.dimentions.height (), typeof (min_h) == 'number' ? min_h : 0) + 'px'
		};
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};

$.fn.screenResize = function (duration, min_w, min_h) {
	if (!duration) {
		this.css ({
			'width'  : 0 + 'px',
			'height' : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'width'  : Math.max ($.gui.dimentions.screenWidth (),  typeof (min_w) == 'number' ? min_w : 0) + 'px',
			'height' : Math.max ($.gui.dimentions.screenHeight (), typeof (min_h) == 'number' ? min_h : 0) + 'px'
		}
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};
		   
$.fn.center = function (duration, width, height) {
	if (!duration) {
		this.css ({
			'left' : 0 + 'px',
			'top'  : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'left' : Math.round (((typeof (width)  == 'number' ? width  : $.gui.dimentions.width  ()) - $(this).outerWidth  (true)) / 2) + 'px',
			'top'  : Math.round (((typeof (height) == 'number' ? height : $.gui.dimentions.height ()) - $(this).outerHeight (true)) / 2) + 'px'
		};
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};
		   
$.fn.hCenter = function (duration) {
	if (!duration) {
		this.css ({
			'left' : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'left' : Math.round (($.gui.dimentions.width () - $(this).outerWidth  (true)) / 2) + 'px'
		};
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};
		   
$.fn.vCenter = function (duration) {
	if (!duration) {
		this.css ({
			'top' : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'top' : Math.round (($.gui.dimentions.height () - $(this).outerHeight (true)) / 2) + 'px'
		};
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};
		   
$.fn.screenCenter = function (duration, withscroll) {
	if (typeof (withscroll) == 'undefined') withscroll = true;

	if (!duration) {
		this.css ({
			'left' : 0 + 'px',
			'top'  : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'left' : Math.round (($.gui.dimentions.screenWidth ()  - $(this).outerWidth  (true)) / 2) + (withscroll ? $.gui.dimentions.scrollX () : 0) + 'px',
			'top'  : Math.round (($.gui.dimentions.screenHeight () - $(this).outerHeight (true)) / 2) + (withscroll ? $.gui.dimentions.scrollY () : 0) + 'px'
		};

		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};
		   
$.fn.screenHCenter = function (duration, withscroll) {
	if (typeof (withscroll) == 'undefined') withscroll = true;

	if (!duration) {
		this.css ({
			'left' : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'left' : Math.round (($.gui.dimentions.screenWidth () - $(this).outerWidth  (true)) / 2) + (withscroll ? $.gui.dimentions.scrollX () : 0) + 'px'
		};
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};
		   
$.fn.screenVCenter = function (duration, withscroll) {
	if (typeof (withscroll) == 'undefined') withscroll = true;

	if (!duration) {
		this.css ({
			'top' : 0 + 'px'
		});
	}

	return this.each (function () {
		var target = {
			'top' : Math.round (($.gui.dimentions.screenHeight () - $(this).outerHeight (true)) / 2) + (withscroll ? $.gui.dimentions.scrollY () : 0)+ 'px'
		};
		if (duration) $(this).animate (target, {'duration' : duration, 'easing' : 'linear'});
		else $(this).css (target);
	});
};

$.gui = {
	dimentions : {
		height : function () {
			var scrollHeight, offsetHeight;
	
			if ($.browser.msie && $.browser.version < 7) {
				scrollHeight = Math.max (document.documentElement.scrollHeight, document.body.scrollHeight);
				offsetHeight = Math.max (document.documentElement.offsetHeight, document.body.offsetHeight);
	
				if (scrollHeight < offsetHeight) return $(window).height ();
				else return scrollHeight;
			}
			else return $(document).height ();
		},
		width : function () {
			var scrollWidth, offsetWidth;
	
			if ($.browser.msie && $.browser.version < 7) {
				scrollWidth = Math.max (document.documentElement.scrollWidth, document.body.scrollWidth);
				offsetWidth = Math.max (document.documentElement.offsetWidth, document.body.offsetWidth);
	
				if (scrollWidth < offsetWidth) return $(window).width ();
				else return scrollWidth;
			}
			else return $(document).width ();
		},
		scrollY : function () {
			if (typeof (window.scrollY) == 'undefined') {
				return document.body.scrollTop;
			}
			else return window.scrollY;
		},
		scrollX : function () {
			if (typeof (window.scrollX) == 'undefined') {
				return document.body.scrollLeft;
			}
			else return window.scrollX;
		},
		screenHeight : function () {
			if (typeof (window.innerHeight) == 'undefined') {
				return document.documentElement.clientHeight;
			}
			else return window.innerHeight;
		},
		screenWidth : function () {
			if (typeof (window.innerWidth) == 'undefined') {
				return document.documentElement.clientWidth;
			}
			else return window.innerWidth;
		}
	}
};

})(jQuery);
