(function ($) {
	
	$.fn.addCorners = function (options) {
		options = $.extend({
			topRight: 'tr',
			bottomRight: 'br',
			bottomLeft: 'bl',
			topLeft: 'tl'
		}, options || {});
		return this.each(function () {
			var $this = $(this), 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) == 6) {
				// For IE6 to get the correct containing element
				$this.css('zoom', 1);
				// 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>');
			}
		});
	};
	
})(jQuery);
