/*
 * Superrounded v0.2b - jQuery plugin
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * This plugin automatically detects menu items on the first
 * level and replaces them with items having rounded corners
 *
 */

;(function($){ // $ will refer to jQuery within this closure

	$.fn.superrounded = function(op){
		// return original object to support chaining
		return this.each(function() {
			var menu = this;
			var leftBox  = $('<div class="item-left-side"></div>');
			var rightBox = $('<div class="item-right-side"></div>');
			var itemContainer = $('<div style="position: relative;">&nbsp;</div>');
			var height;

			$('> li',this).each(function() {
				var link = $('> a',this);
				var newlink = link.clone().css({
					'position':'absolute',
					'left':'10px',
					'top':'0px',
					'padding':'0px 11px'
					});

				height = link.height();
				var width  = link.outerWidth();

				var container = itemContainer.clone().width(width);

				container.append(leftBox.clone().height(height).css({
					'left':'0px',
					'top':'0px',
					'width':'10px',
					'position':'absolute'}));

				container.append(newlink);
				container.append(rightBox.clone().height(height).css({
					'right':'0px',
					'top':'0px',
					'width':'10px',
					'position':'absolute'}));

				link.replaceWith(container);
			});

			$(this).height(height);
		});
	};
})(jQuery); // plugin code ends


