window.addEvents({
	'domready': function() {
		//console.log('DOM ready!');
		
		Site.buildbottomnav();
		Site.buildaccordionnav();
		Site.buildtooltips();
		Site.buildmainmoviecontrol();
		
		Site.buildgustoarchive();
		
		//console.log('done in domready, waiting for page to fully load...');
	},
	
	'load': function(){
		//console.log('page is fully loaded, in load function');

		//console.log('As far as I know, all Javascript is loaded baby');
	}
	
});

var Site = {
	// Make the scroll system for the bottom navigation
	buildbottomnav: function() {
		var scroll = new Fx.Scroll('videoThumbs', {
			wait: false,
			duration: 1000,
			transition: Fx.Transitions.Bounce.easeOut
		});
		
		$('right').addEvent('click', function(event) {
			event = new Event(event).stop();
			scroll.toElement($('august'));
		});
		
		$('left').addEvent('click', function(event) {
			event = new Event(event).stop();
			scroll.toElement($('september'));
		});
	},
	
	// Builds the accordion for the left side navigation
	buildaccordionnav: function() {
		var myaccordion = new Accordion('img.atStart', 'div.atStart', {
			// sets the default accordion panel, which is the 3rd one, zero index
			display: 3,
			fixedHeight: 260,
			onActive: function(toggler, element) {
				
			},
			onBackground: function(toggler, element) {
			
			}
		}, $('navigation'));
	},
	
	// Tooltips for the thumbnails across the movies in the bottom navigation
	buildtooltips: function() {
		var mytooltips = new Tips($$('.thumbnail'), {
			initialize: function() {
				this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
			},
			onShow: function() {
				this.fx.start(1);
			},
			onHide: function() {
				this.fx.start(0);
			}
		});
	},
	
	// Sets the main button in the middle to play the movie
	// Every week we must update the movie in the embed tag below to link to the proper .swf
	buildmainmoviecontrol: function() {
		$('startbutton').addEvent('click', function(event) {
			(function(){$('content').setHTML("<embed src='videos/7spot58.swf' quality='high' width='567' height='359' name='test' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />")}).delay(1000);
		});
	},
	
	buildgustoarchive: function() {
		$('gusto2008archive').set('tween', {
			duration: 'long',
			onComplete: function() {
				//$('gusto2008archive').setStyle('display', 'none');
			}
		});
			
		$('viewgustoarchive').addEvent('click', function() {
			//console.log('clicked');
			$('content').setHTML("<img id='startbutton' src='images/starty.gif' alt='Click to Start' width='567' height='356' />");
			Site.buildmainmoviecontrol();
			$('gusto2008archive').setStyle('display', 'block');
			$('gusto2008archive').tween('opacity', '.95');
		});
		
		$('closearchive').addEvent('click', function() {
			$('gusto2008archive').tween('opacity', '0');
		});
		
		$$('div#gagustos a').addEvents({
			'mouseenter': function(){
				this.tween('color', '#2090cd');
			},
			'mouseleave': function(){
				this.tween('color', '#ffffff');
			}
		});
	}
}