// JavaScript Document
window.object_mes_hashTab = 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,
		_initialdelay = 4000,
		_tabs = $('li', '#' + tabId);
		
//	if (hash && cTabId && cTabId) {
	if (hash && cTabId && cTourId) {
		// 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) {
			hash = newHash;
			$('.selected','#'+tabId).removeClass('selected');
			$('div.active','#'+tourId).fadeOut(250);
			$('#' + cId + '-' + hash).css('visibility','visible').fadeIn(250).addClass('active');
			$(this).addClass('selected');
		}
	};
	
	$.ready($('#'+tabId + ' li').hover(handleTabClick));
	
//	/* No Autoplay
	if (cTabId) {_autoplayIndex = _tabs.index(cTabId);}
	if (0 > _autoplayIndex) {_autoplayIndex = 0;}
	
		autoplay = function() {
			if (_autoplayIndex < _tabs.length - 1) {
				_autoplayIndex += 1;
			}
			else {
				_autoplayIndex = 0;
			}
			var tab = _tabs[_autoplayIndex];
			handleTabClick.call(tab);
		};
	
	startautoplay = function(){_intervalId = setInterval(autoplay,_autoplayTimeout);}
	
	t = setTimeout(startautoplay,_initialdelay);
	$('#'+tabId + ' li').hover(function(){clearInterval(_intervalId);},function(){_intervalId = setInterval(autoplay,_autoplayTimeout);});
// /*
};
