/**
 * This handles the initial loading of a specific tab on the page load.
 * @method object_mes_hashTab
 * @param tabId {String} Required. The id of the pages tabs.
 * @param tourId {String} Required. The id of the pages tabs.
 * @static
 */
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;
		
	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 onClick = function(){
		hash = $(this).attr('id').replace(/.*?-/,'');
		$('.selected','#'+tabId).removeClass('selected');
		$('div.active','#'+tourId).fadeOut(250);
		$('#' + cId + '-' + hash).css('visibility','visible').fadeIn().addClass('active');
		$(this).addClass('selected');
	};
	
	$.ready($('li','#'+tabId).click(onClick));
	
	// polls the hash 4x a second to see if it has changed. if it has, then update the DOM
	tId = setInterval(function() {
		var nhash = window.location.hash.replace(/#/, '') || (first && first.id.replace(/.*-/, ''));
		if (hash && nhash && hash !== nhash) {
			onClick.call($('#tab-' + nhash));
		}
	}, 250);
};