	var show_pos = 0;
	var show_total = 0;
	var show_locked = false;
	var show_paused = false;
	var show_timer;
	var rollover_event;
	
	Event.observe(document, 'dom:loaded', function() {
	
		// -- Load Social Feed
		if ($('social-feed').down('ul').down('li').innerHTML == 'Loading social feed...') new Ajax.Updater($('social-feed').down('ul'), '/inc/social.php');
	
		// -- Navigation
		$$('#nav li a').each(function(x) {
			x.onclick = function() {
				if ($(this).href.endsWith('#')) {
					if ($(this).up('li').hasClassName('selected')) {
						$('cascading').fade({ duration: .3 });
						$(this).up('li').removeClassName('selected');
					} else {
						var pos = $(this).up('li').previousSiblings().length;
						$('cascading').appear({ duration: .3 });
						$$('#cascading div').invoke('hide');
						$$('#cascading div')[pos].show();
						
						$$('#nav li').invoke('removeClassName', 'selected');
						x.up('li').addClassName('selected');
					}
					return false;
				}
			}
		});
		
		// -- Sub Navigation
		$$('#sub-nav li').each(function(x) {
			x.onmouseover = function() {
				$('cascading').hide();
				$$('#nav li').invoke('removeClassName', 'selected');
				$(this).addClassName('selected');
			}
			x.onmouseout = function() { $(this).removeClassName('selected'); }
		});
		
		// -- Special Callouts
		$$('#callouts .callout').each(function(x) {
			if (x.down('.popup')) {
				x.observe('mouseenter', function() { $(this).down('.popup').appear({ duration: .3 }); });
				x.observe('mouseleave', function() { $(this).down('.popup').fade({ duration: .3 }); });
			}
		});
				
		// -- Home Page Slideshow			
		if ($('home-feature')) {
			$$('#season-overview .show').each(function(x) { if (!$(x).down('.past')) show_total++; });
			$$('#season-overview .show').each(function(x) {
				x.observe('mouseenter', function() {
					$(this).down('.over').show();
					if ($(this).down('.past')) $(this).down('.past').hide();					
				});
				x.observe('mouseleave', function() {
					$(this).down('.over').hide();
					if ($(this).down('.past') && !$(this).down('.selected').visible()) $(this).down('.past').show();
				});
				x.onclick = function() {
					load_show($(this).previousSiblings().length, true);
					clearTimeout(show_timer);
					show_paused = true;
				}
			});
			show_timer = setTimeout('next_show()', 4500);
			
			// -- Rollover Details
			$('show-hotspot').observe('mouseenter', function() {
				clearTimeout(show_timer);
				rollover_event = new Effect.Appear($('show-hotspot').down('.popup'), { duration: .3 });
			});
			$('show-hotspot').observe('mouseleave', function() {
				rollover_event.cancel();
				new Effect.Fade($('show-hotspot').down('.popup'), { duration: .3 });
				if (!show_paused) show_timer = setTimeout('next_show()', 4500);
			});
		}
		
		// -- Page Navigation
		$$('ul.page-nav li a').each(function(x) {
			x.onclick = function() {
				var pos = $(this).up('li').previousSiblings().length;
				var pages = $(this).up('.page-nav').next('.page-content').select('.page');
				
				$$('ul.page-nav li').invoke('removeClassName', 'selected');
				$(this).up('li').addClassName('selected');
				
				pages.invoke('hide');
				pages[pos].show();
				
				return false;
			}
		});
		
		if (location.hash && $$('ul.page-nav')) {
			var section = location.hash.replace('#', '');
			if ($$('ul.page-nav li a[name=' + section + ']')) {
				$$('ul.page-nav li a[name=' + section + ']')[0].simulate('click');
			}
		}
				
		// -- Search Field
		$('search-text').onfocus = function() { if (this.value == 'search') this.value = ''; }
		$('search-text').onblur = function() { if (this.value == '') this.value = 'search'; }
	});
	
	function load_show(pos, clicked) {
		if (pos != show_pos && !show_locked) {
			show_locked = true;
			var duration1 = (clicked) ? 500 : 1000;
			var duration2 = (clicked) ? 1 : 2;
			
			setTimeout(function() {
				// selected states
				$$('#season-overview .show .selected').invoke('hide');
				$$('#season-overview .show .selected')[pos].show();
				// past show overlay
				$$('#season-overview .show .past').invoke('show');
				if ($$('#season-overview .show')[pos].down('.past')) $$('#season-overview .show')[pos].down('.past').hide();
				// show details (date/time/venue)
				$$('#show-details .show')[pos].show();
				$$('#show-details .show')[show_pos].hide();
				// popup text
				$$('#show-hotspot .popup .inner')[pos].show();
				$$('#show-hotspot .popup .inner')[show_pos].hide();
			}, duration1);
			
			new Effect.Parallel([
				new Effect.Appear($$('#featured-images img')[pos], { sync: true }),
				new Effect.Fade($$('#featured-images img')[show_pos], { sync: true })
			], {
				duration: duration2,
				afterFinish: function() {
					show_locked = false;
					show_pos = pos;
					if (!show_paused) show_timer = setTimeout('next_show()', 4500);
				}
			});
		}
	}
	
	function next_show() {
		var pos = (show_pos < show_total - 1) ? show_pos + 1 : 0;
		load_show(pos);
	}
