(function( $ ){
	$.fn.tabber = function( options ) {

		var config = {
			'options'	: []
		}

		if ( options ) {
			$.extend( config, options );
		}

		var $this = $(this);

		var $options = $this;
		var $nav = $('<ul class="content_opportunityBucket_navTabs"/>')
						.attr('role', 'tablist');

		var margin = '20em';
		var i = 0;

		$this
			.find('> :header')
			.each( function(){
				i++;
				var $option = $(this);
				var $panel = $option.next();
				var idRoot = 'body-tab';
				var j = 0;
				while (document.getElementById(idRoot+j)) {
					j++;
				}
				var id = idRoot+j;
				var $button = $("<button type=\"button\">")
					.data('panel', $panel)
					.text( $option.text() )
					.attr('role', 'tab')
					.attr('aria-selected', 'false')
					.attr('id', id)
					.click(function(e){
						var $this = $(this);
						e.stopPropagation();
						$this
							.parents('ul')
								.find('button[role="tab"]')
								.not($this)
								.each( function(){
									$(this)
										.attr('aria-selected', 'false')
										.data('panel')
										.hide()
										.attr('aria-hidden', 'true');
									$(this)
										.parent()
										.removeClass('active');
								});
						$this
							.attr('aria-selected', 'true')
							.data('panel')
							.fadeIn(250)
							.attr('aria-hidden', 'false');
						$this
							.parent()
							.addClass('active')
					});

				$panel
					.attr('role', 'tabpanel')
					.attr('aria-hidden', 'true')
					.attr('aria-labelledby', id)
					.hide();

				$option.hide();
				$nav.append($('<li/>').append($button));
				if(i == 1) {
					$button
						.attr('aria-selected', 'true')
						.parent()
						.addClass('active');
				}

			});

			$('div.content_opportunityBucketHeader')
				.append($nav);
			$nav
				.find('button[role=tab]:first')
				.click();
		return this;
	}
})( jQuery );

