// CREDITS:
// Snowmaker Copyright (c) 2003 Peter Gehrig. All rights reserved.
// Distributed by http://www.hypergurl.com
// Permission given to use the script provided that this notice remains as is.

// Modified by George Khromchenko to use prototype.js framework

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

// 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");

// 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=0.6;

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

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

// Set the snowing-zone
// Set 1 for all-over-snowing, set 2 for left-side-snowing 
// Set 3 for center-snowing, set 4 for right-side-snowing

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


// Do not edit below this line
var snowProperties = new Array();
var marginbottom
var marginright
var timer
var i_snow=0
var x_mv=new Array();
var crds=new Array();
var lftrght=new Array();

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

function initsnow() {
  if (typeof window.innerWidth != 'undefined')
   {
      marginright = window.innerWidth,
      marginbottom = window.innerHeight
   }
  // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

   else if (typeof document.documentElement != 'undefined'
       && typeof document.documentElement.clientWidth !=
       'undefined' && document.documentElement.clientWidth != 0)
   {
         marginright = document.documentElement.clientWidth,
         marginbottom = document.documentElement.clientHeight
   }
   // older versions of IE
   else
   {
         marginright = document.getElementsByTagName('body')[0].clientWidth,
         marginbottom = document.getElementsByTagName('body')[0].clientHeight
   }
  
  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;
    size = randommaker(snowsizerange)+snowminsize;
 
    snowProperties[i] = {
      sink : sinkspeed*size/5,
      size : size,
      top  : randommaker(6*marginbottom-marginbottom-6*size),
      left : randommaker(marginright-size)
    };
     
    $('s'+i). setStyle({
      color      : snowcolor[randommaker(snowcolor.length)],
      fontSize   : randommaker(snowsizerange)+snowminsize + 'px',
      fontFamily : "'Trebuchet MS',Arial,sans-serif", 
      left       : snowProperties[i].left + 'px',
      top        : snowProperties[i].top  + 'px',
    });
  }
  movesnow();
}

function movesnow() {
  for (i=0;i<=snowmax;i++) {
    crds[i] += x_mv[i];
    

    snowProperties[i].left += lftrght[i]*Math.sin(crds[i]);
    snowProperties[i].top  += snowProperties[i].sink;

    $('s' + i ).setStyle({
      left : snowProperties[i].left + 'px',
      top  : snowProperties[i].top + 'px'
    });

    if (snowProperties[i].top >= marginbottom-6*snowProperties[i].size || parseInt(snowProperties[i].left)>(marginright-3*lftrght[i])){
      snowProperties[i].left = randommaker(marginright-snowProperties[i].size);
      snowProperties[i].top  = 0;
    }

  }  
  var timer=setTimeout("movesnow()",70)
}
for (i=0;i<=snowmax;i++) {
  document.write("<span id='s"+i+"' style='position:absolute;z-index:100;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
}

document.observe("dom:loaded", function() {
  initsnow();
});
