// This file makes it possible to dynamically add various javascript
// to the page without crowding my html

// dynamically load a javascript file
function load_script(url) {
	var e = document.createElement("script");
	e.src = url;
	e.type = "text/javascript";
	document.getElementsByTagName("head")[0].appendChild(e);
}

// dynamically load a css file
function load_css(url) {
	var e = document.createElement("link");
	e.href = url;
	e.type = "text/css";
	e.rel = "stylesheet";
	e.media = "screen";
	document.getElementsByTagName("head")[0].appendChild(e);
}

// add some bling to the page on various dates
var prevLoad = window.onload;
window.onload = function( ) {
	if ("function" == typeof prevLoad) {
		prevLoad( );
	}

	var date = new Date;
	var month = date.getMonth( ) + 1; // +1 due to index 0
	var day = date.getDate( );

	var monthDay = month+':'+day;

	// we only want snow between october and march
	// and cancel the snow on new year's eve and day for fireworks
	if ((10 <= month || 3 >= month) && ! ("12:31" == monthDay || "1:1" == monthDay)) {
		load_script("scripts/snow/storm.js");
	}

	// we only want fireworks on new year's (and new year's eve), and the 4th and 24th of july
	if ("12:31" == monthDay || "1:1" == monthDay || "7:4" == monthDay || "7:24" == monthDay) {
		load_css("scripts/fireworks/fireworks.css");
		load_script("http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js");
		load_script("scripts/fireworks/build_html.js");
		load_script("scripts/fireworks/fireworks.js");

		var r = 4 + parseInt(Math.random( ) * 16);
		for (var i = r; i--;) {
//			setTimeout('createFirework(8,14,2,null,null,null,null,null,Math.random( ) > 0.5,true)', (i + 1) * (1 + parseInt(Math.random( ) * 1000)));
		}
	}
}