window.objTimeoutFuncs  = [];
window.objTimeoutIds =  [];
function objTimeout(obj,func,time,id)
{
	window.objTimeoutFuncs[id] = function()
                {
		   func.call(obj);
		}
	window.objTimeoutIds[id] =  setTimeout('objTimeoutFuncs[\''+ id +'\']()',time);
}
function clearObjTimeout(id)
{
	clearTimeout(window.objTimeoutIds[id]);
}
function Snow(scale){
	//容器的大小
	this.containerWidth=960;
	this.containerHeight=500;
	//雪花图片的宽度
	this.width=20;
	//雪花图片的高度
	this.height=20;
	//生成当前对象的ID
	this.name="DKSnow"+Math.random()*1000;
	//雪花对象的坐标值
	this.x=Math.random()*this.containerWidth;
	this.y=Math.random()*this.containerHeight;
	//雪花越大透明度越大
	this.alpha=1-scale;
	//雪花透明度
	this.scale=scale;
	//调用图片地址
	this.url="/ttpod/snow/snow2.gif";
	//雪花飘动的时间间隔
	this.speed=100;
	//雪花的飘动步长
	this.xStep=3;
	this.yStep=this.scale*20-8;
	//创建雪花的图片对象
	this.imgObj=document.createElement("img");
	document.getElementById("container").appendChild(this.imgObj);
	this.imgObj.name="snow";
	//设置雪花大小
	this.imgObj.width = this.width*this.scale;
	this.imgObj.height = this.height*this.scale;
	//对支持css3的浏览器根据远近改变透明度
	this.imgObj.style.opacity=this.alpha;
	//给图片对象设置css样式类名
	this.imgObj.className="snow";
	this.show();
	}
//显示雪花的函数
Snow.prototype.show=function(){	
	this.imgObj.style.left=this.x+"px";
	this.imgObj.style.top=this.y+"px";
	this.imgObj.src=this.url;	
	objTimeout(this,this.slideDown,this.speed,this.name);
	}
//雪花飘动函数
Snow.prototype.slideDown=function(){
	this.imgObj.style.left = parseInt(this.imgObj.style.left)+this.xStep*Math.random()+"px";
	this.imgObj.style.top = parseInt(this.imgObj.style.top)+this.yStep+"px";
	if(parseInt(this.imgObj.style.top)>this.containerHeight||parseInt(this.imgObj.style.left)>this.containerWidth)
	{
		this.y=0;
		this.show();
	}
	else
		objTimeout(this,this.slideDown,this.speed,this.name);
	}
function snowStart(){
	var displayStatus=true;
	for(var i = 0; i<15; i++){
		var snow = new Snow((Math.random()+1)/2);
		}
	var snowHandler=document.getElementById("snowHandler");
	snowHandler.onclick=function(){
		var container=document.getElementById("container");
		var snows=document.getElementsByName("snow");
		var elementNumber=snows.length;
		//alert(elementNumber);
		if(displayStatus)
		{
			displayStatus=false;
			for(var i=0;i<elementNumber;i++)
			{
				snows[i].style.display="none";
			}
		}
		else
		{
			displayStatus=true;
			for(var i=0;i<elementNumber;i++)
			{
				snows[i].style.display="block";
			}
		}
	}
}
window.onload=function()
{
	snowStart();
}
