// snow flake code by hostyle - hostyle@csn.ul.ie - Dec 2005
// feel free to use but please leave accreditation intact

// Update: 2006-11-28 
// added non-clobbering onload

// Update: 2005-12-07 
// Appended 'px' to the width and height values because they weren't being accepted with certain doctypes

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, true);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

addEvent(window, 'load', function() {
	if (document.body && document.createElement) {
		var b = document.body;

		var w = document.body.offsetWidth;
		var h = document.body.offsetHeight;
		
		var flake_w = 70;
		var flake_h = 70;
		
//		var number_of_flakes = 25;
		var number_of_flakes = h/100;
		
		for (var i=0; i<number_of_flakes; i++) {
			// get a random top position and a random left position inside the window boundaries
			var rnd_l = Math.round(Math.random() * (w - flake_w - 25));
			var rnd_t = Math.round(Math.random() * (h - flake_h - 25));
			
			// display an image there
			var newFlake = document.createElement('img');
			newFlake.setAttribute('src', 'flake.gif');
			newFlake.className = 'flake';
			newFlake.style.position = 'absolute';
			newFlake.style.top = rnd_t + 'px';
			newFlake.style.left = rnd_l + 'px';
			b.appendChild(newFlake);

			// add an onclick event to the image
			newFlake.onclick = function() {
				this.style.display = 'none';
			}
		}
	}
});

