// ********************************************************************************************
//* 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, 2005 by DD.  This notice must stay intact for use.                   *
//*  -- many modifications made by Roy J. Karlson (rjk862@verizon.net)                         *
// ********************************************************************************************

//++++++++++++++++++++++++++++++++++++++++//
// Build a couple of other date variables //
//++++++++++++++++++++++++++++++++++++++++//

var adate       = new Date();
var dows        = new Array ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months      = new Array ('January','February','March','April','May','June','July','August',
                             'September','October','November','December');
var theday      = adate.getDay();
var thedayte    = adate.getDate();
var themonth    = adate.getMonth();
var theyear     = adate.getFullYear();

var sun = 0; var mon = 1; var tue = 2; var wed = 3;  var thu = 4; var fri = 5; var sat = 6;

var jan = 0; var feb = 1; var mar = 2; var apr = 3;  var may = 4; var jun = 5; var jul = 6;
var aug = 7; var sep = 8; var oct = 9; var nov = 10; var dec = 11;

var light  = 0;
var medium = 1;
var heavy  = 2;
var deluge = 3;
var clear  = 99;

var freq   = light;

// Set default image before calendar dates are considered.

// var imagesrc = "../MiscImages/SnowFlake.gif";

// Configure below to change URL path to the image

if (themonth == sep) {
      if ((thedayte <= 6) && (theday == mon)) {
         imagesrc = "../MiscImages/laborday.gif";	// labor day!  america relaxes!
        }
      else {
         imagesrc = "../MiscImages/baseball.gif";	// not quite football season ... yet!
        }
     }
else if ((themonth >= oct) && (themonth <= nov)) {	// football season (fall) //
   if ((themonth == oct) && (thedayte >= 24)) {
      imagesrc = "../MiscImages/pumpkin.gif";		// halloween
     }
   else if ((themonth == nov) && (thedayte >= 23)) {	// thanksgiving
      imagesrc = "../MiscImages/turkey.gif";
     }
   else if ((theday >= mon) && (theday <= fri)) {	// falling leaves - during the week //
      if ((theday == mon) || (theday == wed) | (theday == fri)) {
         imagesrc = "../MiscImages/Leaf.gif";
        }
      else {
         imagesrc = "../MiscImages/Leaf2.gif";		// mixing the leaves up a little!
        }
     }
   else {						// saturday & sunday -- football!!
      imagesrc = "../MiscImages/football.gif";
     }
  }
else if (themonth == dec) {				// still football, not fall (winter)
   if ((thedayte >= 20) && (thedayte <= 28) && (thedayte != 25)) {	// christmas is coming
      imagesrc = "../MiscImages/santa.gif";
     }
   else if (thedayte == 25) {				// christmas day
      imagesrc = "../MiscImages/santa.gif";
     }
   else if ((thedayte >= 29) && (thedayte <= 31)) {	// new years
      imagesrc = "../MiscImages/hny.gif";
     }
   else if ((theday >= mon) && (theday <= fri)) {	// snow-flakes
      imagesrc = "../MiscImages/SnowFlake.gif";
     }
   else {						// footballs
      imagesrc = "../MiscImages/football.gif";
     }
  }
else if (themonth == jan) {
   if ((thedayte >= 1) && (thedayte <= 5)) {
      imagesrc = "../MiscImages/hny.gif";		// new years
     }
   else if (thedayte == 1) {
      imagesrc = "../MiscImages/football.gif";		// college bowl games
     }
   else if ((theday >= mon) && (theday <= sat)) {	// snow-flakes
      imagesrc = "../MiscImages/SnowFlake.gif";
     }
   else {						// footballs
      imagesrc = "../MiscImages/football.gif";
     }
  }

// figure out the super bowl date for falling footballs

else if (themonth == feb) {
   imagesrc = "../MiscImages/SnowFlake.gif";
   if (thedayte == 14) {
      imagesrc = "../MiscImages/valentinesday.gif";
     }
  }
else if (themonth == mar) {
   imagesrc = "../MiscImages/SnowFlake.gif";
  }
else if (themonth == apr) {
   if (thedayte == 15) {
      imagesrc = "../MiscImages/unclesam.gif";		// tax day!  uncle-sam wants you!
     }
// else if (theday == fri) {				// testing on fridays!
//    imagesrc = "../MiscImages/testimage.gif";		// flowers ... it's spring!
//   }
   else {
      imagesrc = "../MiscImages/flower.gif";		// flowers ... it's spring!
     }
  }
else if (themonth == may) {
   if ((thedayte >= 25) && (theday == mon)) {
      imagesrc = "../MiscImages/memorialday.gif";	// memorial day!
     }
   else {
      imagesrc = "../MiscImages/flower.gif";		// flowers ... it's spring!
     }
  }
else if (themonth == jun) {
      imagesrc = "../MiscImages/baseball.gif";		// summertime == baseball
  }
else if (themonth == jul) {
   if (thedayte == 4) {
      imagesrc = "../MiscImages/fireworks.gif";		// fourth o' july
     }
   else {
      imagesrc = "../MiscImages/baseball.gif";		// summertime == baseball
     }
  }
else if (themonth == aug) {
      imagesrc = "../MiscImages/baseball.gif";		// summertime == baseball
  }

// Configure below to change number of images to render

if (freq == clear) {
   var no = (randnum(3) + 2);		// at least 2, no more than 5
  }
else if (freq == light) {
   var no = (randnum(5) + 5);		// at least 5, no more than 10
  }
else if (freq == medium){
   var no = (randnum(20) + 20);		// at least 10, no more than 20
  }
else if (freq == heavy) {
   var no = (randnum(40) + 40);		// at least 20, no more than 40
  }
else if (freq == deluge) {
   var no = (randnum(80) + 80);		// at least 40, no more than 80
  }
else {
   var no = (randnum(2) + 5);		// default safety valve
  }  

// Configure whether image should disappear after x seconds (0=never)

var hideimagetime = 0;

// Configure how much image should drop down before fading ("windowheight" or "pageheight")

var imagedistance = "pageheight";

// Stop Config

var ie4up = (document.all) ? 1 : 0;
var ns6up = (document.getElementById&&!document.all) ? 1 : 0;

function iecompattest(){
   return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
  }

var dx, xp, yp;					// coordinate and position variables
var am, stx, sty;				// amplitude and step variables
var i, doc_width = 800, doc_height = 600; 

if (ns6up) {
   doc_width = self.innerWidth;
   doc_height = self.innerHeight;
  }
else if (ie4up) {
   doc_width = iecompattest().clientWidth;
   doc_height = iecompattest().clientHeight;
  }

dx  = new Array();
xp  = new Array();
yp  = new Array();
am  = new Array();
stx = new Array();
sty = new Array();

imagesrc = (imagesrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : imagesrc;

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()*20;			// set amplitude variables
   stx[i] = 0.02 + Math.random()/10;		// set step variables
   sty[i] = 0.7 + Math.random();		// set step variables

   if (ie4up||ns6up) {
      if (i == 0) {
         document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://www.henrysautoparts.com\"><img src='"+imagesrc+"' border=\"0\"><\/a><\/div>");
        }
      else {
         document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+imagesrc+"' border=\"0\"><\/div>");
        }
     }
  }

function snowIE_NS6() {				// IE and NS6 main animation function

   doc_width  = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
   doc_height = (window.innerHeight && imagedistance=="windowheight")? window.innerHeight : (ie4up && imagedistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && imagedistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;

   for (i = 0; i < no; ++ i) {			// iterate for every dot
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
         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();
        }
      dx[i] += stx[i];
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
     }
   snowtimer=setTimeout("snowIE_NS6()", 10);
  }

function hidesnow(){
   if (window.snowtimer) {
      clearTimeout(snowtimer);
     }
     {
      for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
     }
  }

if (ie4up||ns6up){
   snowIE_NS6();
   if (hideimagetime>0) {
      setTimeout("hidesnow()", hideimagetime*1000);
     }
  }
