/** Tabs **/

$(document).ready(function() {
	var contact = $('#contactForm');

	$('ul.tabs li').click(function(e) {
		var pageName = $(this).attr('class'); 
		$('ul.tabs li.active').removeClass('active');
		$('div.formError').hide();

		if (pageName == 'contact') {
			$(this).addClass('active');
			$('#contactForm').show();
			$('#mainContent').hide();
			$('div.formError').show();
		}
		
		else {
			$(this).addClass('active');
			$('#contactForm').hide();
			$('#mainContent').show();
				$.ajax({
				  url: pageName + '.html',
				  cache: false,
				  success: function(html){
					$("#mainContent").html(html);
				  }
				});
			e.preventDefault();
		}
	});
});

$(function() {
	if ($('#intro').hasClass('events')) {
		$('#slideshow img').slice(0, 5).remove();
		$('#slideshow img:eq(6)').addClass('active');	
	}
	
	else {
		$('#slideshow img').slice(5, 10).remove();
	}		   
});

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

$(function() {
	var hash = window.location.hash.replace('#', '');

	if (window.location.hash) {
		$('ul.tabs li.active').removeClass('active');
		$('div.formError').hide();
		$('.'+hash).addClass('active');
		$('#contactForm').hide();
		$('#mainContent').show();
		$.ajax({
		  url: hash + '.html',
		  cache: false,
		  success: function(html){
			$("#mainContent").html(html);
		  }
		});
	}
});