

window.initContent = function(tabId, tourId) {
	var hash = window.location.hash.replace(/#/, ''),
		cId = tourId.replace(/-.*/, ''),
		cTabId = $('#tab-' + hash),
		cTourId = $('#' + cId + '-' + hash),
		first = $('#' + tabId + ' li.selected')[0],
		tId = 0,
		_autoplayTimeout = 8000,
		_intervalId = 0,
		_autoplayIndex = 0,
		_tabs = $('li', '#' + tabId);
		firstload=true;
		
	if (hash && cTabId && cTabId) {		
		// clears the existing select/active styles
		if (first) {
			$(first).removeClass('selected');
			$('#' + tourId + ' div.active').removeClass('active');
		}
	
		// add the classes to appropriate element
		cTabId.addClass('selected');
		cTourId.addClass('active');
	}
	
	var handleTabClick = function(){
		var newHash = $(this).attr('id').replace(/.*?-/,'');
		
		if (newHash !== hash || firstload) {
			hash = newHash;
			if (!firstload)
			{
				$('.selected','#'+tabId).removeClass('selected');
			
				if	($.browser.msie)		
					$('div.active','#'+tourId).css('display','none');
				else
					$('div.active','#'+tourId).fadeOut(300);
				
			}

			if	($.browser.msie)		
				$('#' + cId + '-' + hash).css('visibility','visible').css('display','block').addClass('active');
			else
				$('#' + cId + '-' + hash).css('visibility','visible').fadeIn().addClass('active');
			$(this).addClass('selected');
			firstload=false;
		}
	};
	
	
	//not necessary while using the hover behavior
	$.ready($('li','#'+tabId).click(function() {
		handleTabClick.call(this);
		clearInterval(_intervalId);
	}));
	
	
	$.ready($('#'+tabId + ' li').hover(function() {
		handleTabClick.call(this);
		clearInterval(_intervalId);
	}));
	
	var targetTabFromHash = function() {
		var nhash = hash || (first && first.id.replace(/.*-/, ''));
		if (nhash && hash !== nhash || firstload) {
			handleTabClick.call($('#tab-' + nhash));
		}
		
	};
	
	// polls the hash 4x a second to see if it has changed. if it has, then update the DOM
	// tId = setInterval(targetTabFromHash, 250);
	targetTabFromHash(); // turned off auto polling of the hash, so that hover can work, however, we still check on page load to allow tab targeting from other pages
	
	
	if (cTabId) {
		_autoplayIndex = _tabs.index(cTabId);
	}
	
	if (0 > _autoplayIndex) {
		_autoplayIndex = 0;
	}
		
	_intervalId = setInterval(function() {
		if (_autoplayIndex < _tabs.length - 1) {
			_autoplayIndex += 1;
		}
		else {
			_autoplayIndex = 0;
		}
		
		var tab = _tabs[_autoplayIndex];
		//window.location.hash = tab.id.replace(/.*-/, '');
		handleTabClick.call(tab);
	}, _autoplayTimeout);
	
};
