// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

(function() {
	window.keithws = {
		next_quote: function() {
			var current_quote = $('quotes').down();
			var next_quote = current_quote.next();
			// hide first child
			new Effect.Fade(current_quote, {queue: 'end', afterFinish: function() {
				$('quotes').insert(current_quote.remove());
			}});
			// reveal next child
			new Effect.Appear(next_quote, {queue: 'end'});
		},
		adjust_height: function() {
			var wrapper_height = $('wrapper').getHeight();
			var doc_height = document.viewport.getHeight();
			console.log("wrapper: "+wrapper_height);
			console.log("doc: "+doc_height);
			if (wrapper_height < doc_height) {
				new Effect.Morph('wrapper', {
				  style: 'height: '+(doc_height-16)+'px;', // CSS Properties
				  duration: 0.8 // Core Effect properties
				});
			}
		}
	};
	
	Event.observe(document, 'dom:loaded', function() {
		$('quotes').childElements().invoke('hide');
		new Effect.Appear($('quotes').down(), {queue: 'end'});
		new PeriodicalExecuter(keithws.next_quote, 12);
	});
	
	Event.observe(window, 'load', keithws.adjust_height);
})();

