//Requires cookies.js
// Season: must be last thing on page.
//Configure below to change URL path to the snow image
var imgsrc="http://img.photobucket.com/albums/v188/ralahinn1/snow.gif";

/******************************************
* 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
******************************************
* Mutated by Lucius L. Hilley III - http://www.unkmar.com/ - 2006-11-30
******************************************/

// Configure below to change number of snow to render
var no = 10;
// Configure whether snow should disappear after x seconds (0=never):
var hideSeasontime = 0;
// Configure how much snow should drop down before fading ("windowheight" or "pageheight")
var seasonDistance = "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 = 1024;

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();

function sway() {
  return (0.002*no) + Math.random()/no;
}

function fall() {
  return (0.5 + Math.random())/1;
}

function seasonIE_NS6() { // IE and NS6 main animation function
  doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
  doc_height=(window.innerHeight && seasonDistance=="windowheight")? window.innerHeight : (ie4up && seasonDistance=="windowheight")? iecompattest().clientHeight : (ie4up && !window.opera && seasonDistance=="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] = sway();
      sty[i] = fall();
    }
    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";
  }
  seasonTimer=setTimeout("seasonIE_NS6()", 10);
}

function stopSeason() {
  SetCookie("Season", "", -1);
  if (window.seasonTimer) clearTimeout(seasonTimer)
  for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
}

function startSeason() {
  SetCookie("Season", "TRUE", 366);
  for (i = 0; i < no; ++ i) { document.getElementById("dot"+i).style.visibility="visible"; }
  if (ie4up||ns6up){
	seasonIE_NS6();
	if (hideSeasontime>0)
	  SetTimeout("stopSeason()", hideSeasontime*1000)
	sf();
  }
}

function toggleSeason() {
  if (document.getElementById("dot1").style.visibility == "hidden") {
    startSeason();
  }
  else {
	stopSeason();
  }
}

//imgsrc=(imgsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : imgsrc
for (i = 0; i < no; ++ i) {
  dx[i] = 0; // set coordinate variables
  xp[i] = Math.random()*(doc_width-50-24); // set position variables
  yp[i] = Math.random()*doc_height;
  am[i] = 30 //Math.random()*30; // set amplitude variables
  stx[i] = sway(); // set step variables
  sty[i] = fall(); // 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;\"><img id='img"+ i +"' src='"+imgsrc+"' border=\"0\" onclick=\"stopSeason();\"><\/div>");
    } else {
      document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img id='img"+ i +"' src='"+imgsrc+"' border=\"0\" onclick=\"stopSeason();\"><\/div>");
    }
  }
}

function setupSeason() {
  for (i=0; i<no; i++) document.getElementById("img"+i).src = imgsrc;
}

function Season() {
  setupSeason();
  for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden";
  if (ReadCookie("Season")=="TRUE") {
    startSeason();
  }
}
//Season: must be last thing on page.
