$(document).ready(function() {
   
   /* rotating banner */
   $('.header-slideshow').cycle({
		fx: 		'fade',
		timeout:	7000,
		speed: 		2500
	});
   
   /* push mug shot, name and job details down on the 'Our people page' */
   var containerHeight;
   var imgHeight;
   var contactInfoHeight;
   var topMargin;
   
	$('.staff-member').each(
		function(i)
		{
			containerHeight = $(this).height();
			imgHeight = $(this).find('.mug-shot').height();
			contactInfoHeight = $(this).find('.contact-info').height();
			
			topMargin = containerHeight - imgHeight;
			
			$(this).find('.mug-shot').attr({ style: 'margin-top: ' + topMargin + 'px;'});
			
			topMargin = containerHeight - contactInfoHeight - 10;
			$(this).find('.contact-info').attr({ style: 'margin-top: ' + topMargin + 'px;' });
		}
	);
	
	var activeNavItem = $('.menu li.on');
	
	turnBackOn = function() { activeNavItem.addClass('on'); } 
	
	$('.menu').hover(
		function()
		{
			activeNavItem.removeClass('on');
		},
		function()
		{
			activeNavItem.addClass('on');
		}
	);
	
	$('.menu li ul li').hover(
		function()
		{
			$(this).parent().parent().addClass('on');
		},
		function()
		{
			$(this).parent().parent().removeClass('on');
		}
	);
	
	/*
	$('.menu').mouseout(
		function()
		{
			setTimeout("turnBackOn();",500);			
		}
	);
	*/

});


/*  Attach footer to bottom */ 
function getWindowHeight()
{
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter()
{
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('centered-container').offsetHeight + 56;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}

window.onload = function() { setFooter(); }
window.onresize = function() { setFooter(); }