/******************************************
* Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
* Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
* Last updated Nov 9th, 05' by DD. This notice must stay intact for use
******************************************/
  //Configure below to change URL path to the snow image
  // Configure below to change number of snow to render
  var no;
  // Configure whether snow should disappear after x seconds (0=never):
  var hidesnowtime = 0;
  // Configure how much snow should drop down before fading ("windowheight" or "pageheight")
  var snowdistance = "pageheight";
  var wind = 20;
  var windsmooth = 0;
  var winddirection = 0; // 0 - jobb, 1 - bal

///////////Stop Config//////////////////////////////////

  var ie4up = (document.all) ? 1 : 0;
  var ns6up = (document.getElementById&&!document.all) ? 1 : 0;

  var dx, xp, yp;    // coordinate and position variables
  var am, stx, sty;  // amplitude and step variables
  var i;
  var doc_width = 0;
  var doc_height = 0; 

  function snowIE_NS6() {  // IE and NS6 main animation function
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
    //doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
    for (i = 0; i < no; ++ i) {  // iterate for every dot
      switch (stk[i])
      {
       case 1 : yp[i] += sty[i]; break;
       case 2 : yp[i] += (sty[i] / 2); break;
      }
      if (yp[i] > doc_height-100) {
        xp[i] = Math.random()*(doc_width-am[i]-30);
        yp[i] = 0;
        stx[i] = 0.02 + Math.random()/10;
        sty[i] = 0.7 + Math.random();
      }
      switch (stk[i])
      {
       case 1 : dx[i] += stx[i]; break;
       case 2 : dx[i] += (stx[i] / 2); break;
      }
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";
      var dotimg = document.getElementById("dotIMG"+i);
      if (dotimg)
          {
           switch (stk[i])
           {
            case 1 : dotimg.src = 'design/snow_small.gif'; break; 
            case 2 : dotimg.src = 'design/snow_small2.gif'; break; 
           }
          }
    }
    snowtimer=setTimeout("snowIE_NS6()", 10);
  }

  function leaveIE_NS6() {  // IE and NS6 main animation function
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
  //doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
    for (var i = 0; i < no; ++ i) // iterate for every dot
    {
      xp[i] += stx[i] - 0;
      yp[i] += sty[i];
      if (xp[i] > doc_width-80) xp[i] = 0;
      if (yp[i] > doc_height-100) yp[i] = 1;
      if (xp[i] < 0) xp[i] = doc_width-80;
      if (yp[i] < 0) yp[i] = doc_height-80;
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i]+"px";
    }
    wind = wind - 0.1;
    if (wind <= 0)
        {
         wind = Math.round(Math.random()*40);
         windsmooth = Math.random()*10;
         winddirection = Math.round(Math.random());
        }
    if (windsmooth > 0)
        {
         windsmooth = windsmooth - 0.1;
         for (i = 0; i < no; ++ i) // iterate for every dot
         {
          if (winddirection == 0) { stx[i] = stx[i] + 0.1; } else { stx[i] = stx[i] - 0.1; }
          if (stx[i] > 10) { stx[i] = 10; }
          if (stx[i] < -10) { stx[i] = -10; }
         }
        }
        else
        {
         windsmooth = 0;
        }
    snowtimer=setTimeout("leaveIE_NS6()", 10);
  }

    function hidesnow(){
        if (window.snowtimer) clearTimeout(snowtimer)
        for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
    }

    function hideleaves(){
        if (window.snowtimer) clearTimeout(snowtimer)
        for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
    }

    function iecompattest(){
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
    }

function fallings_start (effekt, numberofobjects, heightOfCanvas)
{
 no = numberofobjects;
 doc_height = heightOfCanvas;
 switch (effekt)
 {
  case 0 : var snowsrc="design/snow_small.gif"; break;
  case 1 : var snowsrc="design/debris.gif"; break;
  case 2 : var snowsrc="design/debris2.gif"; break;
  case 3 : var snowsrc="design/debris3.gif"; break;
  case 4 : var snowsrc="design/debris4.gif"; break;
  case 5 : var snowsrc="design/debris5.gif"; break;
  case 6 : var snowsrc="design/debris6.gif"; break;
  case 7 : var snowsrc="design/debris7.gif"; break;
  case 8 : var snowsrc="design/debris8.gif"; break;
  case 9 : var snowsrc="design/debris9.gif"; break;
  case 10: var snowsrc="design/debris10.gif"; break;
 }

  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    doc_width = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    doc_width = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    doc_width = document.body.clientWidth;
  }
  if (doc_width == 0) doc_width = document.documentElement.offsetWidth;
  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();
  stx = new Array();
  sty = new Array();
  stk = new Array();
  //snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : snowsrc
  for (i = 0; i < no; ++ i) {
    dx[i] = 0;                        // set coordinate variables
    xp[i] = Math.random()*(doc_width-50);  // set position variables
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*40;         // set amplitude variables
    document.getElementById("dotIMG"+i).src = snowsrc;
    switch (effekt)
    {
     case 0 : stx[i] = 0.02 + Math.random()/10; // set step variables
              sty[i] = 0.7 + Math.random();     // set step variables
              stk[i] = Math.round(Math.random()*1+1);
              break;
     case 2 :
     case 3 :
     case 4 :
     case 5 :
     case 6 :
     case 7 :
     case 8 :
     case 9 :
     case 10:
     case 1 : stx[i] = Math.random()*4;//4 + (Math.random()*4); //1 + Math.random()*10;
              sty[i] = 1 + Math.random()*2;
              stk[i] = 0;
              break;
    }
  }

 switch (effekt)
 {
  case 0 : snowIE_NS6(); break;
  case 1 :
  case 2 :
  case 3 :
  case 4 :
  case 5 :
  case 6 :
  case 7 :
  case 8 :
  case 9 :
  case 10:leaveIE_NS6(); break;
 }
}