/* jQuery.ui.tabs history fix plugin
 *
 * This uses the jquery.history.js plugin to fix jquery.ui.tabs.
 *
 * Usage:
 *   var tabs = $('.selector').tabs(...);
 *   $.tab_history(tabs)
 * 
 * Copyright (c) 2010 Semiconductor Research Corporation (http://www.src.org)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 */
jQuery.extend({
	tab_history: function(tabs){
		// store hash of tab to prevent looping
		var selecting_hash = '';

		$.historyInit(function(hash){
			if (hash != selecting_hash) {
				if (hash == ''){
					// strip leading #
					hash = tabs.find('a').eq(0).attr('href').substring(1);
				}
				tabs.tabs("select", '#'+hash);
			}
		});
		
		tabs.bind('tabsselect', function(event,ui){
			selecting_hash = jQuery(ui.tab).attr('href').substr(1);
			jQuery.historyLoad(selecting_hash);			
		});
	}
})	
