window.addEvent('domready', function() {

	// ROTATE services
	new Rotation('service', '.rotate');

	// ROTATE REFERENCES
	new Rotation('references', '.rotate', {
		rotate: 15000
	});

	// FLASH
    if(CURRENTPAGE == 'home') swfobject.embedSWF(MEDIA+'/drvinylintro.swf', "intromovie", "465", "200", "9", MEDIA+'/expressinstall.swf');

});

var Rotation = new Class({

	Implements: [Options],
	
	elements: 	null,
	current: 	0,
	
	options:	{
		fade:	1000,	// transition duration
		rotate:	5000	// rotation delay
	},

	initialize: function(container, objectID, options) {
	
		this.setOptions(options);
		
		if ( ! $(container)) return;
		
		// get elements
		this.elements = $(container).getElements(objectID);
		
		// setup elements
		this.elements.each(function(element) {
			
			element.setStyles({
				'display':	'block',
				'opacity':	0
			});
		});
		
		// show first element
		this.elements[this.current].setStyle('opacity', 1);
		
		// and start rotation
		this.shownext.bind(this).delay(this.options.rotate);		
	},
	
	shownext: function() {
	
		// fade out current
		new Fx.Tween(this.elements[this.current], {
			property:	'opacity',
			duration:	this.options.fade
			
		}).start(1, 0);
					
		this.current++;
		if (this.current >= this.elements.length) this.current = 0;
		
		// fade in next
		new Fx.Tween(this.elements[this.current], {
			property:	'opacity',
			duration:	this.options.fade
			
		}).start(0, 1);
		
		// delay next slide
		this.shownext.bind(this).delay(this.options.rotate);
	}	
});
