$(document).ready(function () {
	// Page Formatting (to be executed first)
	deadLinks();
	highlightIncorrectLangLink();
	
	// Other functions not immediately visible (can be executed later on slower connections)
	tabMouseover();
	navMouseover();
	bannerGoHome();
});

function deadLinks() {
	$('a').each(function () {
		var urlPath = $(this).attr('href');
		if (urlPath == "") {
			$(this).css('color', '#990000');
		}
	});
}


// For reviewing only; delete on final publication
function highlightIncorrectLangLink () {
	var curPage = window.location.href;
	curPage = curPage.substr(curPage.length - 10);
	var targetPage = $('#languages a').attr('href');
	targetPage = targetPage.substr(targetPage.length - 10);
	if (curPage != targetPage) {
		$('#languages a').css('color', 'red');
	}
}

function tabMouseover() {
	$('#topNav img[id^=navtab]').each(function () {
		$(this)
			.bind('mouseover', function () {
				var curSource = $(this).attr('src');
				var start = curSource.lastIndexOf('-') + 1;
				var end = curSource.lastIndexOf('.');
				var newSource = '../images/tabh-' + curSource.substring(start, end) + '.png';
				$(this).attr('src', newSource);
			})
			.bind('mouseout', function () {
				var curSource = $(this).attr('src');
				var start = curSource.lastIndexOf('-') + 1;
				var end = curSource.lastIndexOf('.');
				if($(this).is('.navButtonSelected')) {
					var newSource = '../images/tabx-' + curSource.substring(start, end) + '.png';
				} else {
					var newSource = '../images/tab-' + curSource.substring(start, end) + '.png';
				}
				$(this).attr('src', newSource);
			});
		});
}

function navMouseover() {
	$('#leftNavBody li').each(function () {
			$(this)
			.bind('mouseover', function () {
				$(this).css('background', 'url("../images/navbg.png") no-repeat left');
			})
			.bind('mouseout', function () {
				$(this).css('background', 'none');
			});
	});
}

function bannerGoHome() {
	$('#bannerLeft')
		.bind('click', function () {
			window.location = 'index.html';					 
		})
		.bind('mouseover', function () {
			$(this).css('cursor', 'pointer');						 
		});
}