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

		var opts = $.extend({}, $.fn.stTabs.defaults, options);

		return this.each(function() {
		  /**
		   * Initialise
		   */
		  var $self = $(this);
	      var maxHeight;					// Tab maximum height
	      var maxHeightAry = [];			// Tab heights array
	      var curBtnWidth = 0;				// Absolute left position of currently placed button
		  
	      /**
	       * Set height of content to maximum tab height - button height
	       */
		  $self.find(opts.tab).each(function(){
	        maxHeightAry.push($(this).height());
	      });
	      maxHeight = Math.max.apply(Math, maxHeightAry);
	      $self.height(maxHeight).find(opts.content).height(maxHeight - $($self.find(opts.btn)[0]).height());
	      
		  /**
		   * Set first tab to active tab
		   */
	      $($self.find(opts.tab)[0]).addClass('selected').css({ zIndex: maxHeightAry.length });
	  
	      /**
	       * Absolutely position tabs and assign click function
	       */
		  $self.find(opts.btn)
		  .css({ cursor: 'pointer' })
		  .each(function(){
	        if (curBtnWidth === 0 ) {
	          $(this).css({ left : opts.tabFirstMarginLeft + 'px' });
	          curBtnWidth = opts.tabFirstMarginLeft;
	        } else {
	          $(this).css({ left : curBtnWidth + 'px' });
	        }			
			curBtnWidth = curBtnWidth + $(this).outerWidth() + opts.tabMarginRight;
	      })             
	      .click(function(){
	        $self.find(opts.tab).removeClass('selected').css({ zIndex: 1 });
	        $(this).parents(opts.tab).addClass('selected').css({ zIndex: maxHeightAry.length });
	        return false;
	      });
		  $self.css({visibility:'visible'});
		});
	};

	$.fn.stTabs.defaults = {
		tab: '.community-item',
		btn: 'h2',
		content: 'ul',
		tabFirstMarginLeft: 0,
		tabMarginRight: 0
	};
})(jQuery);

