/**
 * javwillwock.js
 *  
 * Øystein Riiser Gundersen (http://www.upstruct.com)
 **/

// good ol'fashioned image preloading, baby
$A([
	'/images/socialnetwork/facebook-active-trans.png',
	'/images/socialnetwork/twitter-active-trans.png',
	'/images/socialnetwork/xing-active-trans.png',
]).each(function(path) {
	(new Image()).src = path;
})

// simple image slideshow with a morphing transitions
var ImageMorpher = Class.create({
	initialize : function(container) {
		this.container = container;
		this.active = container.childElements().last();
		if (container.childElements().size() > 1 && 
			container.childElements().all(function(e) { return e.tagName.toLowerCase() == 'img' }))
			this.timer = new PeriodicalExecuter(this.morph.bind(this), 7);
	},
	
	morph : function() {
		var old = this.active; this.active = this.nextImage();
		new S2.FX.Morph(this.active, { style : 'opacity:1;', duration: 1.0 }).play();
		new S2.FX.Morph(old, { style : 'opacity:0;', duration: 2.0 }).play();
	},
	
	nextImage : function() {
		return this.active.next() || this.container.firstDescendant();
	}
})


Event.observe(document, 'dom:loaded', function() {
	window.morpher = new ImageMorpher($('header-images'));
});
