function load_soundmanager() {
	//placed in the page to show the loading message earlier
	//$('mp3_player').mp3_controls = $('mp3_player').innerHTML;
	//$('mp3_player').innerHTML = 'Loading...';
	
	soundManager.url = '/includes/js/soundmanager2/soundmanager2.swf'; // override default SWF url
	soundManager.debugMode = false;
	soundManager.consoleOnly = false;
	soundManager.onload = function() { init_mp3_player(); }
}

////////////////////////////////////////////////////////////////////
//////////////////// General News/Tour Functions ///////////////////
////////////////////////////////////////////////////////////////////
function route(post_num) {
	if ($('post_'+ post_num).shown == 1) {
		hide_post(post_num);
	} else {
		show_post(post_num);
	}
}

function show_post(post_num) {
	if ($('post_'+ post_num).executing != 1) {
		$('post_'+ post_num).executing = 1;
		
		$('more_'+ post_num).innerHTML = 'LESS &rsaquo;&rsaquo;';
		if ($('map_'+ post_num)) { $('map_'+ post_num).innerHTML = 'Loading...'; }
		
		new Effect.BlindDown('postplus_'+ post_num, { scaleMode: { originalHeight: $('postplus_'+ post_num).height }, afterFinish: function() { done_showing(post_num) } });
	}
}

function done_showing(post_num) {
	$('post_'+ post_num).executing = 0;
	$('post_'+ post_num).shown = 1;
	
	if ($('map_'+ post_num)) {
		new Effect.Opacity('map_'+ post_num, { from: 1, to: 1 });
		
		var map = new google.maps.Map2($('map_'+ post_num));
		var geocoder = new GClientGeocoder();
		var address = $('address_'+ post_num).innerHTML;
		
		geocoder.getLatLng(
			address,
			function(point) {
			  if (!point) {
				$('map_'+ post_num).innerHTML = '<br /><br /><br /><br /><br /><br /><br /><p align="center">Map unable to locate '+ address + '.</p>';
			  } else {
				map.setCenter(point, 13);
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml('<p>'+ address +'</p>');
			  }
			}
		);
		
	}
}

function hide_post(post_num) {
	if ($('post_'+ post_num).executing != 1) {
		$('post_'+ post_num).executing = 1;
		
		$('more_'+ post_num).innerHTML = 'MORE &rsaquo;&rsaquo;';
		
		if($('map_'+ post_num)) {
			new Effect.Opacity('map_'+ post_num, { from: 0, to: 0 });
		}
		
		new Effect.BlindUp('postplus_'+ post_num, { afterFinish: function() { done_hiding(post_num) } });
	}
}

function done_hiding(post_num) {
	$('post_'+ post_num).executing = 0;
	$('post_'+ post_num).shown = 0;
}

function init_news() {
	//grab the height since BlindDown doesn't get the correct heights if they're hidden at first
	for (var x = 1; x <= $('post_num').innerHTML; x++) {
		$('postplus_'+ x).height = $('postplus_'+ x).offsetHeight;
		
		Element.hide($('postplus_'+ x));
	}
	
	load_soundmanager();
}

////////////////////////////////////////////////////////////////////
//////////////////// General Timeline Functions ////////////////////
////////////////////////////////////////////////////////////////////
//extend the show div
function show(year, thumb, page) {
	if ($('wrapper_'+ year).executing != 1) {
		$('wrapper_'+ year).executing = 1;
		
		if ($('wrapper_'+ year).shown == 1) {
			close_content(year);
		} /*else {
			if (page == '2007_band2') {
				$('show_fourth').style.height = '400px';
			} else {
				$('show_fourth').style.height = '256px';
			}
		}*/
		
		new Effect.SlideDown('show_'+ year, { duration: 1, beforeUpdate: function() { $('wrapper_'+ year).executing = 1 }, afterFinish: function() { load_content(year, page) }, queue: { position: 'end', scope: 'content_scope' } });
		if (page == '2008_these_hard_times') {
			//new Effect.Opacity($('thumb_1_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_2_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_5_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_6_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_9_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_10_first').childNodes[0], { duration: 1, from: .2, to: 1 });
		}
		if (page == '2007_how_far_weve_come') {
			new Effect.Opacity($('thumb_3_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_4_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_7_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_8_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_11_first').childNodes[0], { duration: 1, from: .2, to: 1 });
			new Effect.Opacity($('thumb_12_first').childNodes[0], { duration: 1, from: .2, to: 1 });
		} else {
			new Effect.Opacity($(thumb).childNodes[0], { duration: .7, from: .2, to: 1 });
		}
	}
}

//load an external file into the content div
function load_content(year, page) {
	$('wrapper_'+ year).shown = 1;
	$('wrapper_'+ year).executing = 0;
	
	page = '/timeline/pages/'+ page +'.php';
	
	$('content_'+ year).innerHTML = '<p class="loading">Loading...</p>';
	new Ajax.Updater('content_'+ year, page, { onComplete: function() { load_players(year) } });
	new Effect.ScrollVertical('500', { duration: 1 });
}

//close the show div
function close_content(year) {
	$('wrapper_'+ year).executing = 1;
	$('wrapper_'+ year).shown = 0;
	$('content_'+ year).innerHTML = '';
	new Effect.SlideUp('show_'+ year, { duration: 1, afterFinish: function() { $('wrapper_'+ year).executing = 0; }, queue: { scope: 'content_scope' } });
}


//scroll to a specific year
function move_to(year) {
	if ($('wrapper_fourth').executing != 1 && $('wrapper_third').executing != 1 && $('wrapper_second').executing != 1 && $('wrapper_first').executing != 1) {
		$('nav').click_scroll = 1;
		
		//close all and move
		if ($('wrapper_first').shown == 1) { close_content('first'); }
		if ($('wrapper_second').shown == 1) { close_content('second'); }
		if ($('wrapper_third').shown == 1) { close_content('third'); }
		if ($('wrapper_fourth').shown == 1) { close_content('fourth'); }
		
		new Effect.ScrollToHorizontal('wrapper_'+ year, { offset: -45, afterFinish: function() { $('nav').click_scroll = 0 }, queue: { position: 'end', scope: 'content_scope' } });
	}
}

//initialize the scrolling nav bar
function nav_scroll() {
	if($('nav').click_scroll == 0) {
		//go through all the posibilites to find the window x-scroll position
		typeof window.pageXOffset != 'undefined' ? window_x = window.pageXOffset :
			document.documentElement.scrollLeft ? window_x = document.documentElement.scrollLeft :
			document.body.scrollLeft ? window_x = document.body.scrollLeft :
			window_x = 0;
		
		var nav_x = $('nav').offsetLeft;
		var x_move = window_x - nav_x + 459;
		new Effect.Move('nav', { x: x_move, duration: 1, queue: { position: 'end', scope: 'nav_scope', limit: 1 } });
	}
	setTimeout('nav_scroll()', 30);
}

////////////////////////////////////////////////////////////////////
//////////////////// Video /////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//load video and music players if the divs video_*year* or music_*year* are first
function load_players(year) {
	if ($('video_'+ year)) {
		this.year = year;
		this.flv = $('video_'+ year).title;
		
		new Ajax.Updater('video_'+ year, '/timeline/video.php', { evalScripts: true });
	}
}

////////////////////////////////////////////////////////////////////
//////////////////// FC Video //////////////////////////////////////
////////////////////////////////////////////////////////////////////
//load video and music players if the divs video_*year* or music_*year* are first
function fc_video(title) {
	if ($('gallery').executing != 1) {
		if ($('gallery').shown == 1) {
			close_video();
		}
		$('gallery').executing = 1;
		$('gallery').shown = 1;
		
		$('gallery').flv = title;
		
		typeof window.pageYOffset != 'undefined' ? window_y = window.pageYOffset :
			document.documentElement.scrollTop ? window_y = document.documentElement.scrollTop :
			document.body.scrollTop ? window_y = document.body.scrollTop :
			window_y = 0;
		
		var video_loader = Builder.node('img', { id: 'video_loader', src: '/membersonly/images/video_loader.gif' });
		$('video').appendChild(video_loader);
		
		if (window_y > 0) {
			new Effect.ScrollVertical(-1000, { duration: .7, afterFinish: function() { show_video() } });
		} else {
			show_video();
		}
	}
}

function show_video() {
	$('cover').style.width = document.body.clientWidth +'px';
	$('cover').style.height = document.body.clientHeight + 100 +'px';
	
	new Effect.Appear('video', { duration: .2 });
	new Effect.Scale('video', 20, { scaleContent: false, scaleFrom: 20, duration: 0, queue: { position: 'end', scope: 'video_scope' } });
	new Effect.Scale('video', 500, { scaleContent: false, scaleY: false, scaleFrom: 100, duration: .4, queue: { position: 'end', scope: 'video_scope' } });
	new Effect.Scale('video', 500, { scaleContent: false, scaleX: false, scaleFrom: 100, duration: .4, queue: { position: 'end', scope: 'video_scope' } });
	new Effect.Move('video_loader', { y: 200, duration: .4, delay: -.2, queue: { position: 'end', scope: 'video_scope' }, afterFinish: function() { new Ajax.Updater('video_holder', '/membersonly/media/video.php', { evalScripts: true }); $('gallery').executing = 0; } });
	
	new Effect.Appear('video_close_fc', { duration: .2 });
}
	
function close_video() {
	$('gallery').shown = 0;
	$('gallery').executing = 1;
	
	$('cover').style.width = 0;
	$('cover').style.height = 0;
	
	$('video').innerHTML = '';
	new Effect.Fade('video_close_fc', { duration: .4 });
	new Effect.Fade('video', { duration: .4, afterFinish: function() { $('gallery').executing = 0 } });
}

////////////////////////////////////////////////////////////////////
//////////////////// Audio /////////////////////////////////////////
////////////////////////////////////////////////////////////////////

function button_play() {
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=play', evalScripts: true });
}

function button_stop() {
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=stop', evalScripts: true });
}

function button_previous() {
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=previous_song', evalScripts: true });
}

function button_next() {
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=next_song', evalScripts: true });
}

function button_playlist() {
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=show_playlist', evalScripts: true });
}

function button_select_song(new_num) {
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=select_song&new_num='+ new_num, evalScripts: true });
}

function init_mp3_player() {
	$('mp3_player').innerHTML = $('mp3_player').mp3_controls;
	
	new Ajax.Updater('mp3_loader', '/includes/js/mp3_player.php', { method: 'post', postBody: 'action=create_playlist', evalScripts: true });
}

function close_playlist() {
	new Effect.Fade('playlist', { duration: .3, afterFinish: function() { $('playlist').parentNode.removeChild($('playlist')); $('nav').playlist_shown = 0; $('nav').playlist_executing = 0; } });
}

////////////////////////////////////////////////////////////////////
//////////////////// Horizontal Scroll /////////////////////////////
////////////////////////////////////////////////////////////////////
Effect.ScrollToHorizontal = Class.create();
Object.extend(Object.extend(Effect.ScrollToHorizontal.prototype, Effect.Base.prototype), {
	initialize: function(element) {
		this.element = $(element);
		this.start(arguments[1] || {});
	},
	setup: function() {
		Position.prepare();
		offsets = Position.cumulativeOffset(this.element);
		if(this.options.offset) { offsets[0] += this.options.offset; }
		this.scrollStart = Position.deltaX;
		this.delta = offsets[0] - this.scrollStart;
	},
	update: function(position) {
		Position.prepare();
		window.scrollTo(this.scrollStart + (position*this.delta), Position.deltaY);
	}
});

////////////////////////////////////////////////////////////////////
//////////////// Scroll Vertical without Element ///////////////////
////////////////////////////////////////////////////////////////////
Effect.ScrollVertical = Class.create();
Object.extend(Object.extend(Effect.ScrollVertical.prototype, Effect.Base.prototype), {
	initialize: function(offset) {
		this.offset = offset;
		this.start(arguments[1] || {});
	},
	setup: function() {
		Position.prepare();
		this.scrollStart = Position.deltaY;
		this.delta = this.offset - this.scrollStart;
	},
	update: function(position) {
		Position.prepare();
		window.scrollTo(Position.deltaX, this.scrollStart + (position*this.delta));
	}
});

////////////////////////////////////////////////////////////////////
//////////////// Onload ////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
function init_timeline() {
	$('nav').click_scroll = 0;
	nav_scroll();
	//alert($('mp3_player').mp3_controls);
	load_soundmanager();
	
	//adjust the padding on the right dependent upon the monitor resolution
	if(screen.width) { $('righter').style.width = screen.width - 909 +'px'; }
}
