/*
 * 01.12.2009
 * Erzeugt Schneeflocken, die sanft 
 * über die Website runterfallen
 */

var maxWidth = null;
var maxHeight = null;
var zIndex;
var flakeNum = 0;		// ändern auf 50 und CSS boxes anpassen
window.addEvent('domready', function() {
	if(document.location.href.indexOf('index.php') > 0)
	{
		$('sky').setStyle('overflow', 'hidden');
		var flakes = new Array();
		for(var i=0; i<flakeNum; i++)
		{
			flakes[i] = new SnowFlake();
		}
	}
});

/*
 * Schneeflocken-Klasse
 */
var SnowFlake = new Class({
	'initialize': function() {
		var win = window.getSize();
		this.SpreadWidth = win.x;
		this.LimitY = win.y;
		this.Speed = Math.round(Math.random() * 4 + 3);
		this.Variation = 2;
		this.Interval = 50;
		this.Create();
	},
	
	'Create': function() {
		this.InitX = this.LocX = Math.round(Math.random() * this.SpreadWidth);
		this.InitY = this.LocY = -30;
		this.flake = new Element('div', { 'class': 'flake', 'styles': { 'z-index': zIndex++, 'top': this.InitY, 'left': this.InitX }});
		this.flake.inject($('sky'));
		this.Start = function() {
			this.Trickle();
		}.bind(this);
		this.Start.delay(Math.round(Math.random() * 20000));
	}, 
	
	'Trickle': function() {
		this.Move = function() {
			this.LocY += this.Speed;
			if(this.LocY > this.LimitY)
				this.Melt();
			this.LocX += Math.round(Math.random() * (this.Variation * 2) - this.Variation);
			this.flake.setStyles({
				'top': this.LocY, 
				'left': this.LocX
			});
		}.bind(this);
		this.IsFalling = this.Move.periodical(this.Interval);
	}, 
	
	'Melt': function() {
		this.flake.destroy();
		$clear(this.IsFalling);
		this.Create();
	}
})
