/*
	snow.js
	Idea and programming (c) 1999-2006 by Alexey Zlatov
	Additions for DOM (c) 2003 by Andrew Belyakov
*/

var ns4, ie4, dom;
var doc_width = 800, doc_height = 600, doc_left = 0, doc_top = 0;
var nElemCount = 10;
var arrayTop = new Array(nElemCount), arrayLeft = new Array(nElemCount);

function InitializeScreenMeasurements()
{
	ie4 = (document.all) ? true : false;
	dom = (!ie4 && document.getElementById) ? true : false;
	ns4 = (!ie4 && !dom && document.layers) ? true : false;

	if (ie4)  
	{
		doc_width = document.body.scrollWidth;
		doc_height = document.body.scrollHeight;
		doc_left = document.body.scrollLeft;
		doc_top = document.body.scrollTop;
	}
	else if (ns4) 
	{
		doc_width = self.innerWidth;
		doc_height = self.innerHeight;
	} 
	else if (dom)  
	{
		doc_width = document.width;
		doc_height = document.height;
	}
}

function OnMoveSnow()
{
	var i, styleRef;
	for (i = 0; i < nElemCount; ++i)  
	{
		if (ie4)  
			styleRef = "document.all.Snow"+i.toString()+".style";
		else if (dom)  
			styleRef = document.getElementById('Snow'+i.toString()).style;
		else if (ns4)  
			styleRef = "document.layers.Snow"+i.toString();
		arrayTop[i] += Math.floor(8*Math.random());
		if ( arrayTop[i] > doc_height - 20 || Math.random() < 0.02 )  
		{
			arrayTop[i] = 0;
			arrayLeft[i] = doc_left + Math.floor(Math.random()*doc_width);
		}
		else  
		{
			arrayLeft[i] += Math.floor((0.5 - Math.random())*10);
			if ( arrayLeft[i] < doc_left )  
			{
	  			arrayLeft[i] = doc_left;
			}
			if ( arrayLeft[i] > (doc_left+doc_width)-50 )  
			{
				arrayLeft[i] = (doc_left+doc_width)-50;
			}
		}
		if (ie4)  
		{
			eval(styleRef+".pixelTop = " + (arrayTop[i]).toString());
			eval(styleRef+".pixelLeft = " + (arrayLeft[i]).toString());
		}
		else if (dom)  
		{
			styleRef.top = (arrayTop[i]).toString();
			styleRef.left = (arrayLeft[i]).toString();
		}
		else if (ns4)  
		{ 
			eval(styleRef+".top = " + (arrayTop[i]).toString());
			eval(styleRef+".left = " + (arrayLeft[i]).toString());
		}
	}
}

function RunSnow(sSnowImage)
{
	InitializeScreenMeasurements();
	var i;
	for (i = 0; i < nElemCount; ++i)  
	{
		arrayTop[i] = doc_top + Math.random()*doc_height;
		arrayLeft[i] = doc_left + Math.random()*(doc_width-50);
		if (ie4 || dom)  
		{
			document.write("<div id=\"Snow"+i.toString()+"\" style=\"visibility:visible;z-index:999;position:absolute;left:"+(arrayLeft[i]).toString()+"px;top:"+(arrayTop[i]).toString()+"px;\"><img border=0 src=\""+sSnowImage+"\"></div>");
		}
		else if (ns4)  
		{
			document.write("<layer name=\"Snow"+i.toString()+"\" left=\""+(arrayLeft[i]).toString()+"\" top=\""+(arrayTop[i]).toString()+"\" visibility=\"show\"><img border=0 src=\""+sSnowImage+"\"></layer>");
		}
	}
	setInterval("OnMoveSnow()", 200);
}

