
var $j = jQuery.noConflict();

var HDSnowflakes = 10; // bei full HD, ansonsten proportional weniger
var numSnoflakes = 1; // wird berechnet
var delay = 20;	// milis for setTimeout for movement
var minSize = 40; // in px;
var maxSize = 40; // in px;
var minSpeed = 1.0; // in px;
var maxSpeed = 4.0; // in px;
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function Flake(size,top,left,imgtag,speed)
{
	this.speed = speed;
	this.size=size;
	this.top=top;
	this.left=left;
	this.imgtag=imgtag;
	
	this.setCSSleft = function setCSSleft() {
		imgtag.css('left',left);
	};
	this.setCSStop = function setCSStop() {
		imgtag.css('top',top);
	};
	this.setCSSsize = function setCSSsize() {
		//imgtag.css('width',size);
		//imgtag.css('height',size);
	};
	this.setCSStopLeftSize = function setCSStopLeftSize() {
		this.setCSSleft();
		this.setCSStop();
		this.setCSSsize();
	};
	this.startMoving = function startMoving() {
		setTimeout(function(){this.move()},delay);
	}
	this.move = function move() {
		setTimeout(function(){this.move()},delay);
		this.top = this.top + this.size/100.0;
		this.setCSStop();
	}
}

function moveSnow() {	
   	for (i=0;i<numSnowflakes;i++) {
   		snowFlakes[i].top = snowFlakes[i].top + snowFlakes[i].speed;
   		if (snowFlakes[i].top>(winHeight-snowFlakes[i].size)) {
   			snowFlakes[i].top=0;
   		}
   		snowFlakes[i].imgtag.css('top',snowFlakes[i].top);
   	}
   	window.setTimeout("moveSnow()", delay);
}

var snowFlakes = new Array();

$j(document).ready(function() {
   numSnowflakes=window.innerWidth/1920*HDSnowflakes;
   numSnowflakes=0;
   for (i=0;i<numSnowflakes;i++) {
   	$j('#center').before('<img src="wp-content/themes/adventure/images/isnow40.gif" class="isnow" id="isnow'+i+'"></img>');
   	snowFlakes[i]=new Flake(Math.random()*(maxSize-minSize)+minSize, 0,Math.random()*(winWidth-maxSize),$j('#isnow'+i),Math.random()*(maxSpeed-minSpeed)+minSpeed);
	snowFlakes[i].setCSStopLeftSize();
    // snowFlakes[i].startMoving();
   }
   $j('.isnow').css('position','absolute');
   window.setTimeout("moveSnow()", delay);
   winHeight=getDocHeight();
});  
