/*
 * Lewers sideways scrolling
 * JavaScript coding by Fountain Internet Marketing
 *  http://www.fountaininternet.co.uk/
 *
 * Using the jQuery library and the following plugins:
 * jQuery.LocalScroll
 * Metadata
 * jQuery.ScrollTo
 * swapImage
 * jQuery Easing
 */

/* Check for IE 6 */
var msie6 = ($.browser.msie && $.browser.version < 7);

/* Preload images */
var preloadImages = ['images/nav0b.png', 'images/nav1b.png', 'images/nav2b.png', 'images/nav3b.png', 'images/nav4b.png', 'images/nav5b.png'];
$.each(preloadImages, function(e) {
	$('<img />').attr('src', this);
});

$(document).ready(function () {
	/* Set styles based on current window size */
	resizeWindow();
	$(window).bind('resize', resizeWindow);
	
	/* Set style for initial navigation item (home page) */
	if (!window.location.hash) {
		var homeNavImg = $('#nav0').find('img');
		homeNavImg.attr('src', homeNavImg.attr('src').replace(/.png/, 'b.png'));
		$('#nav0').addClass('nav-current');
	}
	
	/* Sideways scrolling */
	var easingMethod = 'easeInOutExpo';
	var period = 4400;
	
	/* Image swapping */
	$('.nav-link').hover(
		function () {
			var navImage = $(this).find('img');
			if (!$(this).hasClass('nav-current')) {
				navImage.attr('src', navImage.attr('src').replace(/.png/, 'b.png'));
			}
		},
		function () {
			var navImage = $(this).find('img');
			if (!$(this).hasClass('nav-current')) {
				navImage.attr('src', navImage.attr('src').replace(/b.png/, '.png'));
			}
		}
	);
	$('.nav-link').click(
		function () {
			$('.nav-link')
			currentNav = $('.nav-current');
			if (currentNav.length) {
				currentNavImg = currentNav.find('img');
				currentNavImg.attr('src', currentNavImg.attr('src').replace(/b.png/, '.png'));
				currentNav.removeClass('nav-current');
			}
			$(this).addClass('nav-current');
		}
	);
	
	if (msie6) {
		/* For IE 6, hide footer prior to scroll, and display it again when scroll has completed (avoids juddering) */
		$('#footer').localScroll({
			duration: period,
			easing: easingMethod,
			hash: true,
			axis: 'xy',
			onBefore:function( e, anchor, $target ){
				if (msie6) {
					$('#footer').css('display', 'none');
				}
			},
			onAfter:function( anchor, settings ){
				if (msie6) {
					$('#footer').css('display', 'block');
				}
			}
		});
	} else {
		$('#footer').localScroll({
			target: '#content-outer',
			duration: period,
			easing: easingMethod,
			hash: true,
			axis: 'xy'
		});
	}
	
	function resizeWindow(e) {
		var windowWidth = $(window).width();
		var topRightDivMarginLeft = windowWidth - $('.topleft').width() - $('.topright').width() - 40;
		if (msie6) { topRightDivMarginLeft -= 30; } // Fudge factor for IE 6
		$('.topright').css('margin-left', topRightDivMarginLeft);
		
		var windowHeight = $(window).height();
		contentOuterBgHeight = windowHeight - 80;
		$('#content-outer-bg').css('height', contentOuterBgHeight + 'px');
	}
});