/*
**
** Package: Schneeflocken
** Objekt: flake
** Version: 1.1
** Autor: Andreas Peters
** modifiziert am: 11.12.01
**
*/

function flake(key, image) {
	
	// Variables
	this.key = key
	this.image = image
	this.xPos = 0;
	this.yPos = 0
	this.xMod = 0
	this.xAmp = 0
	this.yGrav = 0
	this.mod = 0
	this.layerName = ("flake"+key+"flake")
	
	this.show=show
	this.animate=animate
	this.reset=reset
	
	// Constructor
	this.reset(0)
	this.show()
		
	// Methods
	function show() {
		
		if (MS || DOM) {
			document.write("<div id='" + this.layerName + "' style='POSITION: absolute; Z-INDEX: " + this.key + "; VISIBILITY: visible; TOP: " + this.yPos + "px; LEFT: " + this.xPos + "px;'><img src='" + this.image + "' border='0'></div>");
		} else {
			document.write("<layer name='"+ this.layerName +"' left='" + this.xPos + "' top='" + this.yPos + "' visibility='show'><img src='" + this.image + "' border='0'></layer>");
		}
		
	}

	function animate(xSpeed, ySpeed) {
		this.mod += this.xMod;
		this.xPos += xSpeed;
		this.yPos -= (this.yGrav+ySpeed);
				
		if (MS) {
			document.all[this.layerName].style.pixelLeft = this.xPos + this.xAmp*Math.sin(this.mod);
			document.all[this.layerName].style.pixelTop = this.yPos;
			
		} else if (DOM) {
			document.getElementById(this.layerName).style.left = this.xPos + this.xAmp*Math.sin(this.mod);
			document.getElementById(this.layerName).style.top = this.yPos;

		} else {
			document.layers[this.layerName].left = this.xPos + this.xAmp*Math.sin(this.mod);
			document.layers[this.layerName].top = this.yPos;
		}
				
	}

	function reset(value) {
		
		if (MS) {
			doc_width = document.body.clientWidth;
			doc_height = document.body.clientHeight;
		} else if (DOM) {
			doc_width = self.innerWidth;
			doc_height = self.innerHeight;
		} else {
			doc_width = self.innerWidth;
			doc_height = self.innerHeight;
		}
		
		this.xPos = doc_width - Math.random() * doc_width
		if (!value)
			this.yPos = 0 + Math.random() * doc_height
		else
			this.yPos = doc_height - 25
				
		this.xMod = 0.02 + Math.random()/10;
		this.xAmp = Math.random()*20;
		this.yGrav = 0.7 + Math.random()
	}
			
}
