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 = 5000,
		_intervalId = 0,
		_autoplayIndex = 0,
		_tabs = $('li', '#' + tabId);
		
	if (hash && cTabId && cTabId) {		
		if (first) {
			$(first).removeClass('selected');
			$('#' + tourId + ' div.active').removeClass('active');
		}
		cTabId.addClass('selected');
		cTourId.addClass('active');
	}
	var handleTabClick = 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).hover(handleTabClick));
	//added empty function arg for 'hover-out' to prevent errors in IE
	$.ready($('li','#'+tabId).hover(handleTabClick, function(){}));
	
	
	var targetTabFromHash = function() {
		var nhash = window.location.hash.replace(/#/, '') || (first && first.id.replace(/.*-/, ''));
		if (hash && nhash && hash !== nhash) {
			handleTabClick.call($('#tab-' + nhash));
		}
	};
};


function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 

var newsletterDefault = 'Your Email';
$(document).ready(function(){
    $('#newsletter-field').val("Your Email");
    $('#newsletter-field').focus(function(){
        if($(this).val() == newsletterDefault) {
            $(this).val('');
        }
    });
    
    $('#newsletter-field').blur(function(){
        if($(this).val() == '') {
            $(this).val(newsletterDefault);
        }
    });
    
    $('#newsletter-form').submit(function(){
        if( !validateEmail($('#newsletter-field').val() ) ) {
            alert("Please enter a valid email address");
            return false;
        }
        return true;
    });
    
});
