(function(a){a.snowfall=function(c,b){function m(e,i,n,o,p){this.id=p;this.x=e;this.y=i;this.size=n;this.speed=o;this.step=0;this.stepSize=d(1,10)/100;e=a(document.createElement("div")).attr({"class":"snowfall-flakes",id:"flake-"+this.id}).css({width:this.size,height:this.size,background:b.flakeColor,position:"absolute",top:this.y,left:this.x,fontSize:0,zIndex:b.flakeIndex});a(c).get(0).tagName===a(document).get(0).tagName?a("body").append(e):a(c).append(e);this.element=document.getElementById("flake-"+
this.id);this.update=function(){this.y+=this.speed;this.y>j-6&&this.reset();this.element.style.top=this.y+"px";this.element.style.left=this.x+"px";this.step+=this.stepSize;this.x+=Math.cos(this.step);if(this.x>h-6||this.x<6)this.reset()};this.reset=function(){this.y=0;this.x=d(0,h);this.stepSize=d(1,10)/100;this.size=d(b.minSize*100,b.maxSize*100)/100;this.speed=d(b.minSpeed,b.maxSpeed)}}function k(){for(f=0;f<g.length;f+=1)g[f].update();setTimeout(function(){k()},30)}b=a.extend({flakeCount:35,flakeColor:"#ffffff",
flakeIndex:999999,minSize:1,maxSize:3,minSpeed:2,maxSpeed:3},b);var d=function(e,i){return Math.round(e+Math.random()*(i-e))};a(c).data("snowfall",this);var g=[],l=0,f=0,j=a(c).height(),h=a(c).width();a(window).bind("resize",function(){j=a(c).height();h=a(c).width()});for(f=0;f<b.flakeCount;f+=1){l=g.length;g.push(new m(d(0,h),d(0,j),d(b.minSize*100,b.maxSize*100)/100,d(b.minSpeed,b.maxSpeed),l))}k();this.clear=function(){a(c).children(".snowfall-flakes").remove();g=[]}};a.fn.snowfall=function(c){if(typeof c==
"object")return this.each(function(){new a.snowfall(this,c)});else if(typeof c=="string")return this.each(function(){var b=a(this).data("snowfall");b&&b.clear()})}})(jQuery);
