var Trailblazers	= {
	UI: {}
};

Trailblazers.UI.General = function() {
	
	var init	= function() {
		init_trips();
	};

	var init_trips = function() {
		var tab_area = $('div.tabs');
		
		if (tab_area.length) {
			
			var tabs = $('<ul id="tabs"></ul>');
			
			var sections = tab_area.find('.section');
			
			sections.each(function(i,o){
				var self = $(o);
				var tab = $('<li></li>');
				var heading = self.find('h2:first');
				tab.append('<a href="#'+self.attr('id')+'">'+heading.text()+'</a>');
				heading.remove();
				tabs.append(tab);
				
				tab.find('a').click(function(e){
					e.preventDefault();
					sections.hide();
					$($(this).attr('href')).show();
					tabs.find('li').removeClass('selected');
					$(this).parent('li').addClass('selected');
				});
			});
			
			tabs.insertBefore(sections.first());
			sections.hide();
			sections.first().show();
			
			if (window.location.hash) {
				sections.hide();
				$(window.location.hash).show();
				tabs.find('li').removeClass('selected');
				$('a[href='+window.location.hash+']').parent('li').addClass('selected');
			}
			
			$('#dates td a').click(function(e){
				e.preventDefault();
				sections.hide();
				$($(this).attr('href')).show();
				tabs.find('li').removeClass('selected');
				$('a[href='+$(this).attr('href')+']').parent('li').addClass('selected');
			});
			
		}
		
		
	};

	return {
		init: init
	};

}();

jQuery(function($) { Trailblazers.UI.General.init(); });

