$(document).ready(function() {
	// Selects the appropriate selected tab in the navigation
	var fullPageAddress = window.location.href.length;
	var linkAddress = window.location.pathname.length;
	var substrLength = fullPageAddress-linkAddress+1;
	
	var pageAddress = window.location.pathname.substr(1);
	$navLinks = $('#navigation a');
	$bottomNavLinks = $('#bottomNavigation a');
	$bottomNavLinks2 = $('.bottomNavigation2 a');
	$navLinks.removeClass('selected');
	$navLinks.each(function() {
		var link = this.href.substr(substrLength);
		if(link == pageAddress) {
			$(this).addClass('selected');
		}
	});
	$bottomNavLinks.removeClass('selected');
	$bottomNavLinks.each(function() {
		var link = this.href.substr(substrLength);
		if(link == pageAddress) {
			$(this).addClass('selected');
		}
	});
	$bottomNavLinks2.removeClass('selected');
	$bottomNavLinks2.each(function() {
		var link = this.href.substr(substrLength);
		if(link == pageAddress) {
			$(this).addClass('selected');
		}
	});
	
	// Set home to selected if the index.php is not in the address
	if(window.location.pathname == '/')
	{
		$('#navigation a:first').addClass('selected');
		$('#bottomNavigation a:first').addClass('selected');
	}
	
	// Script for banner transitions
	// Home Transitions
	$('#homeGroup1').innerfade({animationtype: 'fade', speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '230px'});
	setTimeout("$('#homeGroup2').innerfade({animationtype: 'fade', speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '230px'})", 2000);
	setTimeout("$('#homeGroup3').innerfade({animationtype: 'fade', speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '230px'})", 4000);
	setTimeout("$('#homeGroup4').innerfade({animationtype: 'fade', speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '230px'})", 6000);
	
	// Other page transitions
	$('#group1').innerfade({animationtype: 'fade', speed: 'slow', timeout: 7500, type: 'sequence', containerheight: '140px'});
	setTimeout("$('#group2').innerfade({animationtype: 'fade', speed: 'slow', timeout: 7500, type: 'sequence', containerheight: '140px'})", 1500);
	setTimeout("$('#group3').innerfade({animationtype: 'fade', speed: 'slow', timeout: 7500, type: 'sequence', containerheight: '140px'})", 3000);
	setTimeout("$('#group4').innerfade({animationtype: 'fade', speed: 'slow', timeout: 7500, type: 'sequence', containerheight: '140px'})", 4500);
	setTimeout("$('#group5').innerfade({animationtype: 'fade', speed: 'slow', timeout: 7500, type: 'sequence', containerheight: '140px'})", 6000);
	
	// Script for timeline image shifts
	$('div.projectTimeLine').hover(function() {
		// hover in
		var div = $('> div', this);
		
		if (div.is(':animated')) {
			div.stop().fadeTo(500, 1);
		} else {
			div.fadeIn(500);
		}
	}, function () {
		var div = $('> div', this);
		
		if (div.is(':animated')) {
			div.stop().fadeTo(1000, 0);
		} else {
			div.fadeOut(1000);
		}
	});
	
});