/**
@fileOverview Extensions to jQuery
*/

/**
* @namespace
* @name $
* @description jQuery
*/

/**
* @memberOf $
* @name fn
* @description Methods added to the jQuery object
*/



	var extensions = {
		/**
		Return or set the minimum height of an element
		@param {Number} [height] Set the minimum height to this value
		@memberOf $.fn
		*/
		minHeight: function(height) {
			// Explorer versions prior to IE7 needs to have height instead of min-height
			var type = ($.browser.msie && parseInt($.browser.version, 10) < 7)	? "height" : "min-height";
			if (height == undefined) {
				// Get min-height for the first element
				return this.css(type);
			} else {
				// Set the min-height on all elements (default to pixels if value is unitless)
				this.css(type, height.toString().match(/^\d+$/) ? height + "px" : height);
				return this;
			}
		},
		/**
		Justifies the heights of a bunch of elements to match the highest one
		@memberOf $.fn
		*/
		justify: function() {
			var maxHeight = 0;
			// Get the height of the highest element
			this.each(function() {
				var el = $(this), height;
				el.minHeight(0);
				height = el.outerHeight();
				if (height > maxHeight) {
					maxHeight = height;
				}
			});
			// Set min-height for all elements
			this.each(function () {
				var el = $(this);
				el.minHeight(el.height() + maxHeight - el.outerHeight());
			});
			return this;
		},

		/**
		Return the height of the tallets matched element
		@memberOf $.fn
		*/
		getHighestHeight: function () {
			var maxHeight = 0;
			// Get the height of the highest element
			this.each(function() {
				var el = $(this), height;
				el.minHeight(0);
				height = el.outerHeight();
				if (height > maxHeight) {
					maxHeight = height;
				}
			});
			return maxHeight;
		},

		/*
		Add corners to an element. Requires a bit of css.
		@memberOf $.fn
		 */
		addCorners: function (options) {
			options = $.extend({
				topRight: 'tr',
				bottomRight: 'br',
				bottomLeft: 'bl',
				topLeft: 'tl'
			}, options || {});
			return this.each(function () {
				var $this = $(this);
				var pos = $this.css('position');
				if (pos == 'static' || pos == 'auto' || pos === '') {
					$this.css('position', 'relative');
				}

				// Ugly, but needed, IE6 detection
				if ($.browser.msie && parseInt($.browser.version, 10) < 8) {
					// For IE6/7 to get the correct containing element
					$this.css('zoom', 1);
					if (parseInt($.browser.version, 10) < 7) {
						// IE6's rounding may position corners out of place, so we need the width and height to be odd
						if ($this.innerWidth() % 2) {
							// Width is even, set new odd width
							$this.width($this.width() - 1);
						}
						if ($this.innerHeight() % 2) {
							// Height is even, set new odd height
							$this.height($this.height() + 1);
						}
					}
				}

				// Create container
				var container = $('<div class="corners"></div>');
				$this.append(container);
				if (options.topRight) {
					container.append('<div class="' + options.topRight + '"></div>');
				}
				if (options.bottomRight) {
					container.append('<div class="' + options.bottomRight + '"></div>');
				}
				if (options.bottomLeft) {
					container.append('<div class="' + options.bottomLeft + '"></div>');
				}
				if (options.topLeft) {
					container.append('<div class="' + options.topLeft + '"></div>');
				}
			});
		},
		/*
		Refresh corners added with {@link $.fn.addCorners}
		@memberOf $.fn
		 */
		refreshCorners: function () {
			return this.each(function () {
				var $this = $(this);
				$this.height('');
				$this.height('auto');
			});
		}
	};

	$.extend($.fn, extensions);


