function addAccordion(startIndex) {
	var accordion = new Accordion($$('.nav-item'), $$('.nav-menu'), {
		show: startIndex
	});
}
// The event for this needs to be added to each page, to select
// the page that will open

function startGallery(showPanel, galleryTime) {
	is_timed = (galleryTime <= 500) ? false : true;
	var myGallery = new gallery($('main_image'), {
		timed: is_timed,
		delay: galleryTime,
		embedLinks: false,
		showCarousel: false,
		showInfopane: showPanel
	});
}

function hideContent() {
	$('content_main').set('opacity', '0')
}
window.addEvent('domready', hideContent)

function fadeIn() {
	
	var fx = new Fx.Morph('content_main', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
	fx.start({
		opacity: 1
	})
}
window.addEvent('load', fadeIn)

function fadeOut(href) {
	var fx = new Fx.Morph('content_main', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
	fx.start({
		opacity: 0
	}).chain(function() {
		window.location = href
	});
}

function loadText() {
	var req = new Request.HTML({
		url: 'test_text.html',
		onSuccess: function(html) {
			$('main_text').set('text', '');
			$('main_text').adopt(html);
		},
		onFailure: function() {
			$('main_text').set('text', 'A part of this page failed to load');
		}
	});
	var fx = new Fx.Morph('main_text', {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	fx.start({
		opacity: 0
	}).chain(function() {
		req.send().chain(function() {
			fx.start({ opacity: 1 });
		});
	});
}

function loadImages() {
	var req = new Request.HTML({
		url: 'test_gallery.html',
		onSuccess: function(html) {
			$('main_image').set('text', '');
			$('main_image').adopt(html);
			startGallery();
		}
	});
	var fx = new Fx.Morph('main_image', {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	fx.start({
		opacity: 0
	}).chain(function() {
		req.send().chain(function() {
			fx.start({ opacity: 1 });
		});
	});
}

function switchIt() {
	loadImages();
	loadText();
}
