// wrap plugin in a closure
(
	function($)
	{
		// glueontop plugin definition
		$.fn.tabmenu =
			function(options)
			{
				// extend default options with those provided
				var
					opts = $.extend({}, $.fn.tabmenu.defaults, options)

				return this.each(
					function()
					{
						var
							$this = $(this),

							// build element specific options
							o = $.metadata ? $.extend({}, opts, $this.metadata()) : opts,
							$menu = $(o.menuSelector, $this),
							$tab = $(o.tabSelector, $this);

						$tab.each(
							function(e)
							{
								$(this).hide();
								$(this).attr('id', 'tab-'+e);
							}
						);

						$menu.each(
							function(e)
							{
								$(this).addClass('tab-'+e);
								$(this).bind(
									'click',
									function()
									{
										$menu.parent().removeClass(o.activeClass);
										$tab.hide();
										$(this).parent().addClass(o.activeClass);
										$('#tab-'+e).fadeIn();
										return false;
									}
								)
							}
						).eq(0).trigger('click');
					}
				);
			};

		// glueontop plugin default options
		$.fn.tabmenu.defaults =
			{
				activeClass: 'active',
				menuSelector: '>ul:first li',
				tabSelector: '>div'
			};
	}
)(jQuery);
