 UNIWITS._JSSnow={ jssObjs: [] }; UNIWITS.JSSnow=function (opts) { this.opts={}; this.intervalID=-1; this.index=UNIWITS._JSSnow.jssObjs.length; this.newpointcountdown=0; this.freepoints=[]; this.activepoints=[]; this.windowWidth=UNIWITS.Toolbox.clientWidth(); this.windowHeight=UNIWITS.Toolbox.clientHeight(); UNIWITS._JSSnow.jssObjs.push(this); this.initialize=function (opts) { this.opts=opts; if (!opts.piecespersec) opts.piecespersec=5; if (!opts.zIndex) opts.zIndex=-9999; if (!opts.updatecycle) opts.updatecycle=60; if (!opts.maxpoints) opts.maxpoints=10; if (!opts.rightmargin) opts.rightmargin=5; if (!opts.bottommargin) opts.bottommargin=5; if (!opts.windfield) opts.windfield=function (x,y) { var c=Math.cos(x+y); return {dx:-c+Math.sin(y/40.0)*2,dy:c-1/(1+x*x)}; }; if (!opts.gravity) opts.gravity={dx: 3,dy: 4}; this.isupdating=false; }; this.initializepoint=function (p) { var posselidx=Math.floor(Math.random()*((this.opts.gravity.dy?this.windowWidth:0)+(this.opts.gravity.dx?this.windowHeight:0))); if (this.opts.gravity.dx>=0) { if (this.opts.gravity.dy>=0) if (posselidx<this.windowHeight) { p.x=0; p.y=posselidx; } else { p.x=posselidx-this.windowHeight; p.y=0; } } else if (this.opts.gravity.dx<0) { if (this.opts.gravity.dy>=0) if (posselidx<this.windowWidth) { p.x=posselidx; p.y=0; } else { p.x=this.windowWidth-1; p.y=posselidx-this.windowWidth; } } }; this.point_is_out=function (p) { return !(p.y>=0 && p.y<this.windowHeight-p.element.offsetHeight-this.opts.bottommargin && p.x>=0 && p.x<this.windowWidth-p.element.offsetWidth-this.opts.rightmargin); }; this.updatepoint=function (p) { var d=this.opts.windfield(p.x,p.y); p.x+=d.dx+this.opts.gravity.dx; p.y+=d.dy+this.opts.gravity.dy; }; this.activate=function () { if (this.intervalID>-1) clearInterval(this.intervalID); this.intervalID=setInterval('UNIWITS._JSSnow.jssObjs['+this.index+'].update_all_points();',this.opts.updatecycle); }; this.deactivate=function () { if (this.intervalID>-1) clearInterval(this.intervalID); this.intervalID=-1; }; this.update_all_points=function () { if (this.isupdating) return; if (this.activepoints.length>0) { if (this.opts.rightmargin<this.activepoints[0].element.offsetWidth) this.opts.rightmargin=this.activepoints[0].element.offsetWidth; if (this.opts.bottommargin<this.activepoints[0].element.offsetHeight) this.opts.bottommargin=this.activepoints[0].element.offsetHeight; } this.windowWidth=UNIWITS.Toolbox.clientWidth(); this.windowHeight=UNIWITS.Toolbox.clientHeight(); this.isupdating=true; var countdownthreshold=1000/this.opts.piecespersec; while (this.newpointcountdown>countdownthreshold) { if (this.activepoints.length<this.opts.maxpoints) { var thepoint; if (this.freepoints.length>0) { thepoint=this.freepoints.pop(); thepoint.element.style.display="block"; } else { thepoint={ element: UNIWITS.Toolbox.createElement('DIV',null,null,{position: 'absolute', display: 'inline-block', zIndex: this.opts.zIndex, MozBorderRadius: '60px', webkitBorderRadius: '60px', KhtmlBorderRadius: '60px', borderRadius: '60px'}) }; if (this.opts.snowpicurl) { thepoint.element.appendChild(UNIWITS.Toolbox.createElement('IMG',{src: this.opts.snowpicurl, border: 0})); } else { thepoint.element.style.backgroundColor='white'; thepoint.element.style.border='1px solid #c0c0c0'; thepoint.element.style.width='3px'; thepoint.element.style.height='3px'; thepoint.element.style.overflow='hidden'; } document.body.appendChild(thepoint.element); } this.activepoints.push(thepoint); this.initializepoint(thepoint); } this.newpointcountdown-=countdownthreshold; } for (var pi=0;pi<this.activepoints.length;) { var thepoint=this.activepoints[pi]; this.updatepoint(thepoint); if (this.point_is_out(thepoint)) { thepoint.element.style.display="none"; this.activepoints.splice(pi,1); this.freepoints.push(thepoint); } else { thepoint.element.style.left=thepoint.x+"px"; thepoint.element.style.top=Math.max(document.body.scrollTop,document.documentElement.scrollTop)+thepoint.y+"px"; pi++; } } this.newpointcountdown+=this.opts.updatecycle; this.isupdating=false; }; this.initialize(opts); }