///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// SCHNEEFALL SCRIPT FÜR IE
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

// CREDITS:
// Snowing Links
// By Peter Gehrig
// Copyright (c) 2004 Peter Gehrig. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.24fun.com
// info@24fun.com
// 10/27/2004

// IMPORTANT:
// If you add this script to a script-library or script-archive
// you have to add a highly visible link to
// http://www.24fun.com on the webpage
// where this script will be featured

///////////////////////////////////////////////////////////////////////////
// CONFIGURATION STARTS HERE
///////////////////////////////////////////////////////////////////////////

// Set the number of snowflakes (more than 30 - 40 not recommended)
var snowmax=40

// Set the colors for the snow. Add as many colors as you like
var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD")

// Set the fonts, that create the snowflakes. Add as many fonts as you like
var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS","symbol")

// Set the letter that creates your snowflake (recommended:*)
var snowletter="*"

// Set the speed of sinking (recommended values range from 0.3 to 2)
var sinkspeed=1.2

// Set the maximal-size of your snowflaxes
var snowmaxsize=22

// Set the minimal-size of your snowflaxes
var snowminsize=8

// Set the width of the snowing-zone (pixels)
var snowboxwidth



///////////////////////////////////////////////////////////////////////////
// CONFIGURATION ENDS HERE
///////////////////////////////////////////////////////////////////////////

// Do not edit below this line
var snow=new Array()
var marginbottom
var marginright
var marginleft
var margintop
var snowingzone=1
var posleft=0
var postop=0
var is_snowing=false
var timer
var i_snow=0
var x_mv=new Array();
var crds=new Array();
var lftrght=new Array();
var browserinfos=navigator.userAgent
var browserinfosff=navigator.userAgent
var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
var ns6=document.getElementById&&!document.all
var opera=browserinfos.match(/Opera/)
var ff=browserinfosff.match(/Firefox/)
var browserok=ie5||ns6||opera||ff

function randommaker(range) {
	rand=Math.floor(range*Math.random())
	return rand
}

function startsnow() {
	is_snowing=true
	if (ie5 || opera) {
		margintop = 0
		marginbottom = document.body.clientHeight
		marginleft = posleft
		marginright = posleft+snowboxwidth
		snowboxwidth = document.body.clientWidth
	}
	else if (ns6 || ff) {
		margintop = 0
		marginbottom = window.innerHeight
		marginleft = posleft
		marginright = posleft+snowboxwidth
		snowboxwidth = window.innerWidth
	}
	var snowsizerange=snowmaxsize-snowminsize
	for (i=0;i<=snowmax;i++) {
		crds[i] = 0;
    	lftrght[i] = Math.random()*15;
    	x_mv[i] = 0.03 + Math.random()/10;
		snow[i]=document.getElementById("s"+i)
		snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
		snow[i].size=randommaker(snowsizerange)+snowminsize
		snow[i].style.fontSize=snow[i].size
		snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
		snow[i].sink=sinkspeed*snow[i].size/5
		snow[i].posx=randommaker(snowboxwidth)+marginleft-2*snow[i].size
		if (ie5 || opera) {
			if (snow[i].posx>=document.body.clientWidth-2*snow[i].size) {
				snow[i].posx=snow[i].posx-snowboxwidth
			}
		}
		if (ns6 || ff) {
			if (snow[i].posx>=window.innerWidth-2*snow[i].size) {
				snow[i].posx=snow[i].posx-snowboxwidth
			}
		}
		snow[i].posy=randommaker(marginbottom-margintop)+margintop-2*snow[i].size
		snow[i].style.left=snow[i].posx
		snow[i].style.top=snow[i].posy
		snow[i].style.visibility="visible";

	}
	movesnow()
}

function stopsnow() {
	is_snowing=false
}

function movesnow() {
	if (is_snowing) {
		for (i=0;i<=snowmax;i++) {
			crds[i] += x_mv[i];
			snow[i].posy+=snow[i].sink
			snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
			snow[i].style.top=snow[i].posy

			if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
				snow[i].posx=randommaker(snowboxwidth)+marginleft-2*snow[i].size
				if (ie5 || opera) {
					if (snow[i].posx>=document.body.clientWidth-2*snow[i].size) {
						snow[i].posx=snow[i].posx-snowboxwidth
					}
				}
				if (ns6 || ff) {
					if (snow[i].posx>=window.innerWidth-2*snow[i].size) {
						snow[i].posx=snow[i].posx-snowboxwidth
					}
				}
				// Aenderung E.Egger pos auf 0 gesetzt
				//snow[i].posy=randommaker(marginbottom-margintop)+margintop-2*snow[i].size
				snow[i].posy=0
			}
		}
		var timer=setTimeout("movesnow()",40)
	}
	else {
		for (i=0;i<=snowmax;i++) {
			snow[i].style.visibility="hidden";
		}
	}
}

function getcoordinates(e) {
	if (ie5 || opera) {
		posleft=document.body.scrollLeft+window.event.x;
		postop=0;
	}
	if (ns6 || ff) {
		posleft=e.pageX
		postop=0
	}
}

for (i=0;i<=snowmax;i++) {
	document.write("<span id='s"+i+"' style='visibility:hidden;z-index:99;position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
}
if (browserok) {
	document.onload=getcoordinates
}


///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// SCHNEEFALL SCRIPT FÜR FIREFOX
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

/******************************************
* Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
* Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
* Last updated Nov 9th, 05' by DD. This notice must stay intact for use
******************************************/

//Configure below to change URL path to the snow image
var snowurl="http://www.bauernhof-stiefenhofer.de/fileadmin/templates/images/"

var snowsrc=new Array("flocke-01.gif","flocke-02.gif","flocke-03.gif","flocke-04.gif","flocke-05.gif","flocke-06.gif","flocke-07.gif","flocke-08.gif","flocke-09.gif")
var flocke

// Configure below to change number of snow to render
var no = 10;

// Configure whether snow should disappear after x seconds (0=never):
var hidesnowtime = 0;

// Configure how much snow should drop down before fading ("windowheight" or "pageheight")
var snowdistance = "pageheight";

///////////Stop Config//////////////////////////////////


var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById&&!document.all) ? 1 : 0;

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function randommaker(range) {
	rand=Math.floor(range*Math.random())
	return rand
}

var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var i, doc_width = 800, doc_height = 600;

if (ns6up) {
	doc_width = self.innerWidth;
	doc_height = self.innerHeight;
} else if (ie4up) {
	doc_width = iecompattest().clientWidth;
	doc_height = iecompattest().clientHeight;
}

dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();
//snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1) ? "snow.gif" : snowsrc;
snowsrc=snowsrc;
for (i = 0; i < no; ++ i) {
	dx[i] = 0; // set coordinate variables
	xp[i] = Math.random()*(doc_width-50);  // set position variables
	yp[i] = Math.random()*doc_height;
	am[i] = Math.random()*20;         // set amplitude variables
	stx[i] = 0.02 + Math.random()/10; // set step variables
	sty[i] = 0.7 + Math.random();     // set step variables
	flocke=snowsrc[randommaker(snowsrc.length)]
	if (ie4up||ns6up) {
		document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowurl+flocke+"' border=\"0\"><\/div>");
	}
}

function snowIE_NS6() {  // IE and NS6 main animation function
	doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
	doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
	for (i = 0; i < no; ++ i) {  // iterate for every dot
		yp[i] += sty[i];
		if (yp[i] > doc_height-50) {
			xp[i] = Math.random()*(doc_width-am[i]-30);
			yp[i] = 0;
			stx[i] = 0.02 + Math.random()/10;
			sty[i] = 0.7 + Math.random();
		}
		dx[i] += stx[i];
		document.getElementById("dot"+i).style.top=yp[i]+"px";
		document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";
	}
	snowtimer=setTimeout("snowIE_NS6()", 10);
}

function hidesnow(){
	if (window.snowtimer) clearTimeout(snowtimer)
	for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
}


if (ie4up||ns6up){
	snowIE_NS6();
	if (hidesnowtime>0)
	setTimeout("hidesnow()", hidesnowtime*1000)
}
