function TabBrowser(options){
	var that = this;
	
	that.defaults = {
		tabsParentId: '#share-options',	// selector for the parent element of tabs
		divsParentId: '#see-options',	// selector for the parent element of panels which slide
		closeButton: '.close-button'	// selector for the close button
	};

	that.opts = $.extend(that.defaults,options);
	
	that.$tabs = $(that.opts.tabsParentId + ' a');
	
	// Detect if the parent div contains div children, and if not wrap a parent div around it
	if ($(that.opts.divsParentId + ' > div').length < 1){
		var container = that.opts.divsParentId + '-cont';
		$(that.opts.divsParentId).wrap('<div id="' + container.replace('#','') + '"></div>');
		that.opts.divsParentId = container;
	}
	that.$divs = $(that.opts.divsParentId + ' > div');
	
	that.$closeButton = $(that.opts.divsParentId + ' ' + that.opts.closeButton);
	
	that.$divs.addClass('js');	// in CSS set #your-page-only .js { display:none; }
	
	that.active = false; // current state of action
	
	that.checkTabs = function(){
		var $close = null;
		var $open = null;
		
		if (that.active) return false; // if action already occuring don't register click
		
		that.$divs.each(function(i){
				
			if ($(this).is(':visible') && $(this).is('.clicked')) {
				$close = $(this);
				
			} else if ($(this).is(':visible') && $(this).is(':not(.clicked)')) {
				$close = $(this);
				
			} else if ($(this).is(':not(:visible)') && $(this).is('.clicked')) {
				$open = $(this);
			}			
		});
		
		that.closeOpen($close,$open);
		
		return false;
	}
	
	that.closeOpen = function($close,$open){
		
		if (that.active) 
		    return;
		    
		that.active = true;
		that.$closeButton.css('visibility','hidden');
		if ($close){
			that.hideDiv($close,$open);
		} else if ($open){
			that.showDiv($open);
		} else {
			that.$divs.each(function(i){
				$(this).removeClass('clicked');
				that.$closeButton.css('visibility','visible');
			});
		}
		
		that.active = false;
	}
	
	that.hideDiv = function($close,$open) {
		$close.slideUp("slow", function(){
			that.closeOpen(null, $open);
		});
	}
	
	that.showDiv = function($open) {
		$open.slideDown("slow",function(){
			that.closeOpen(null, null);
		});
	}
	
	// Event triggers
	
	that.$tabs.click(function(){
		$($(this).attr('href')).addClass('clicked');
		return that.checkTabs();
	});
	
	that.$closeButton.click(function(){
		$(this).parents('div.js').addClass('clicked');
		return that.checkTabs();
	});
	
	// Expand a form panel if it contains error or confirm messages
	$('.error, .confirm').each(function(i) {
		$(this).parents('div.js').addClass('clicked');
		return that.checkTabs();
	});
	
	// YouTube style copy URL auto-highlight functionality
	$('input#embededCode').focus(function() {
		$(this).select();
	});
	
	$('input#embededCode').click(function() {
		$(this).select();
	});

}
