// Filename: halloween.js
// Function: Halloween Fun
// Author: Kurt Brunner
// Version: 1.0
// Created: 10/29/2006
//------------------------

var witch1 = new Image();
var witch2 = new Image();
var witch3 = new Image();
witch1.src = 'halloween/witch1.gif';
witch2.src = 'halloween/witch2.gif';
witch3.src = 'halloween/witch3.gif';

{
	var oldOnload = window.onload ? window.onload : function() {}
	window.onload = function() { Halloween(); oldOnload() };
}

function Halloween()
{
	var div = document.createElement('div');
	div.style.position = 'absolute';
	div.style.overflow = 'hidden';
	div.style.width = getWindowWidth() + 'px';
	div.style.height = getWindowHeight() + 'px';
	div.style.top = '0px';
	div.style.left = '0px';
	div.style.bottom = '0px';
	div.style.right = '0px';
	var img = document.createElement('img');
	var oldResize = window.onresize ? window.onresize : function() {}
	window.onresize = function() { eventResize(); oldResize() };
	img.style.position = 'absolute';
	document.body.appendChild(div);
	div.appendChild(img);
	flyBy();
	
	function flyBy()
	{
		var half = -(getWindowWidth() - img.offsetWidth) / 2;
		if(img.src != witch1.src)
		{
			img.src = witch1.src;
			img.style.right = getWindowWidth() + 'px';
			img.style.bottom = ((getWindowHeight() - img.offsetHeight) / 2) + 'px';
		}
		else
			img.style.right = (parseInt(img.style.right)-5) + 'px';
		if(parseInt(img.style.right)>-half)
			window.setTimeout(flyBy,5)
		else
		{
			img.style.bottom = (parseInt(img.style.bottom)-50) + 'px';
			img.src = witch2.src
			setTimeout(fallDown,100);
		}
	}

	function fallDown()
	{
		img.style.right = (parseInt(img.style.right)-15) + 'px';
		img.style.bottom = (parseInt(img.style.bottom)-10) + 'px';
		if(parseInt(img.style.right)>-img.offsetWidth)
			window.setTimeout(fallDown,5)
		else
			setTimeout(helloIn,800);
	}

	function helloIn()
	{
		if(img.src != witch3.src)
		{
			img.src = witch3.src;
			img.style.left = '';
			img.style.bottom = -img.offsetHeight + 'px';
			img.style.right = '24px';
		}
		else
			img.style.bottom = (parseInt(img.style.bottom)+3) + 'px';
		if(parseInt(img.style.bottom)<0)
			window.setTimeout(helloIn,5)
		else
		{
			img.style.bottom = '0px';
			window.setTimeout(helloOut,2000);
		}
	} 

	function helloOut()
	{
		if(parseInt(img.style.bottom)> -img.offsetHeight)
		{
			img.style.bottom = (parseInt(img.style.bottom)-10) + 'px';
			window.setTimeout(helloOut,5)
		}
		else
		{
			window.onresize = oldResize;
			document.body.removeChild(div);
		}
	}
	
	function eventResize()
	{
		div.style.width = getWindowWidth() + 'px';
		div.style.height = getWindowHeight() + 'px';
	}
}

function getWindowWidth()
{
	if(self.innerWidth)
		return self.innerWidth
	else if(document.documentElement && document.documentElement.clientWidth)
		return document.documentElement.clientWidth
	else if(document.body)
		return document.body.clientWidth;
}

function getWindowHeight()
{
	if(self.innerHeight)
		return self.innerHeight
	else if(document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight
	else if(document.body)
		return document.body.clientHeight;
}
