function resizeContent() {
	var windowOffset = parseInt($('#footer').outerHeight()) + 40;
	var localOffset = parseInt($('#content h2').outerHeight()) + parseInt($('#content .inner').css('padding-top')) + parseInt($('#content .inner').css('padding-bottom'));
	var availableHeight = parseInt($(window).height()) - windowOffset - localOffset;
	var requiredHeight = 0;

	$('#content .scroll-child').each(function() {
	 	requiredHeight += parseInt($(this).outerHeight());
	});
	
	if (requiredHeight > availableHeight) {
		$('#content .scroll-pane').height(availableHeight);
	}
}

var scrollOpts = {
	showArrows: true,
	horizontalGutter: 30
};

$(document).ready(function() {
	//handle the additional
	$('#additional').hide().fadeIn('slow');
	
	var preloads = [];
			
	//handle the hover thumbs including preloading
	if ($('ul.gallery').length > 0) {
		$('ul.gallery li a').each(function() {
			var path = $(this).attr('rev');
			
			if (path != '') {
				preloads.push(path);
			}
		}).hover(function() {
			var path = $(this).attr('rev');
			
			$('#content').append('<div class="thumb"><img src="' + path + '" /></div>');
		}, function() {
			$('#content .thumb').hide().remove();
		});
	}

	//load the background image and configure the gallery
	$('#background').loader({
		verticalCentreImage: true,
		verticalCentreContainer: $(window),
		thumbList: $('#content .gallery'),
		additionalPreLoads: preloads,
		additionalPreLoadsFirst: true,
		captionContainer: $('#caption'),
		prevNextControlsAppendee: $('#page'),
		slideShowControlsAppendee: $('#content .inner'),
		scanControlsAppendee: $('#page')
	});
	
	//handle the left/right gallery controls
	$('#page').append('<div id="float"></div>');
	
	$('.loader-nav').live('mouseenter', function(event) {
		$('#float').addClass('visible');
		
		if ($(this).hasClass('prev')) {
			$('#float').addClass('previous').removeClass('next');
		} else {
			$('#float').addClass('next').removeClass('previous');
		}
	});
	
	$('.loader-nav').live('mousemove', function(event) {
		offset = $('#page').offset();
		
		$('#float').css({
			left: event.pageX - 22 - offset.left,
			top: event.pageY - 10
		});
	});
	
	$('.loader-nav').live('mouseout', function(event) {
		$('#float').removeClass('visible');
	});
	
	//resize the content div if its longer than the page
	resizeContent();
	
	//instansiate the scroll bars
	$('.scroll-pane').jScrollPane(scrollOpts);
	
	//textures roll overs
	$('ul.textures li a img').hover(function() {
		$(this).fadeTo('fast', 0.7);
	}, function() {
		$(this).fadeTo('slow', 1);
	});
	
	//select first input on contact page
	
});

$(window).resize(function() {
	//check resize the content div
	resizeContent();
	
	//reset the scrollbars
	$('.scroll-pane').jScrollPane(scrollOpts);
});
