

(function ($, undefined) {
	
	$.fn.panes = function() {
		var $collection = this;
		var $panes = $('object');
		
		this.each(function(){
			var $this = $(this);
			var target = $this.find('a').attr('href');
			var $target = $(target);
			
			$target.addClass('pane');
			
			$this.click(function(e){
				// Take away all the open classes and add it only to this tab
				$collection.removeClass('open');
				$(this).addClass('open');
				// Hide all the panes and show only this one
				$('.pane').hide();
				$target.show();
				e.preventDefault();
			});
		});
		
		this.first().trigger('click');
		return this;
	}
	
	$(function(){
		$('.tab').panes();
	});

}(jQuery));
