document.observe('dom:loaded', function() {
	if(pageTracker) {
		$$('a.track').each(function (anchor) {
			anchor.observe('click', function(e) { pageTracker._trackPageview(e.element().getAttribute('href')); });
		});
	}
});


var Showcase = Class.create({
	
	initialize: function(options) {
		var DEFAULT_OPTIONS = {
			shape: 'shape',
			images: '#showcase img',
			startPosition: { top: '-60px', left: '0px' },
			endPosition: { top: '330px', left: '-100px' },
			delay: 5.0
		}
		
		this.options = Object.extend(Object.clone(DEFAULT_OPTIONS), options || {});
		
		document.observe('dom:loaded', this.setup.bindAsEventListener(this));
	},
	
	setup: function() {
		$(this.options['shape']).setStyle(this.options['startPosition']).show();
		$$(this.options['images']).invoke('hide');
		Event.observe(window, 'load', this.start.bindAsEventListener(this));
	},
	
	start: function() {
		this.loop();
	},
	
	loop: function() {
		var shape = $(this.options['shape']);
		shape.morph(this.options['endPosition'], { beforeStart: this.setupNextImage.bind(this), queue: { position: 'end', scope: 'showcase' } });
		shape.morph(this.options['startPosition'], { afterFinish: this.loop.bind(this), queue: { position: 'end', scope: 'showcase' }, delay: this.options['delay'] });
	},
	
	setupNextImage: function() {
		if(this.current) this.current.hide();
		
		if(!this.current || !this.current.next('img')) {
			this.current = $$(this.options['images']).first();
		} else {
			this.current = this.current.next('img');
		}
		
		this.current.show();
	}
	
});

var showcase = new Showcase();
