$(document).ready(function(){
		initTabs();
});

function initTabs() {
	$('ul.tabset').each(function(){
		var _list = $(this);
		var _links = _list.find('a.tab');

		_links.each(function() {
			_href = $(this).attr('href');
			var _tabId = '#' + _href.split('#')[1];
			var _all = $(this).attr('rel');
			var _all_link = $(_all);
			var _tab = $(_tabId);

			if($(this).hasClass('active')) _tab.show() && _all_link.show();
			else _tab.hide() && _all_link.hide();

			$(this).click(function(){
				_links.filter('.active').each(function(){
					// Hide all currently active items
					tabId = $(this).removeClass('active').attr('href').split('#');
					tabId = '#' + tabId[1];
					$(tabId).hide();
					$($(this).attr('rel')).hide();
				});

				// Set this link & its related items active
				$(this).addClass('active');
				_tab.fadeIn();
				_all_link.fadeIn();

				return false;
			});
		});
	});
}
