function hoover(e) {
	cross("OVER").style.left = getRealLeft(e);
	cross("OVER").style.top = getRealTop(e);
	cross("OVER").style.width = e.width + 1;
	cross("OVER").style.visibility = "visible";
}

function unhoover() {
	cross("OVER").style.visibility = "hidden";
}

function setCookie(name, value) {
	var theCookie = name + "=";
	
	theCookie = theCookie + escape(value);
	
	document.cookie = theCookie;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name) {
	var arg = name + "=";
	var aLen = arg.length;
	var cLen = document.cookie.length;

	var i = 0;

	while(i < cLen) {
		var j = i + aLen;
		
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		
		i = document.cookie.indexOf(" ", i) + 1;
		
		if (i == 0) break;
	}
	
	return null;
}

function getRandomCSS() {
	if (document.cookie.indexOf("dasK") != -1) {
		cookieEnabled = true
	}
	else {
		cookieEnabled = false;
	}
	
	if (cookieEnabled) {
		return getCookie('dasK');
	}
	else {
		var cssList = new Array('color_1.css', 'color_2.css', 'color_3.css');
		var randNum = Math.floor(cssList.length * Math.random());
		
		setCookie('dasK', cssList[randNum]);
		
		return cssList[randNum];
	}
}

function changeCSS() {
	cross("random").setAttribute("href", getRandomCSS());
}

function getRealLeft(e) {
	xPos = e.offsetLeft;
	t = e.offsetParent;
	
	while (t != null) {
		xPos += t.offsetLeft;
		t = t.offsetParent;
	}
	
	return xPos;
} 

function getRealTop(e) {
	yPos = e.offsetTop;
	t = e.offsetParent;
	
	while (t != null) {
		yPos += t.offsetTop;
		t = t.offsetParent;
	}
	
	return yPos;
} 

function cross(e) {
	return document.getElementById ? document.getElementById(e) : document.all[e];
}

function doInit() {
	changeCSS();
	
	if (document.all) {
		offsetLeft = Math.round((document.body.offsetWidth - 20 - 640) / 2) - 64;
		
		var dv = document.all.tags("div");
		var im = document.all.tags("img");
		var sp = document.all.tags("span");
	}
	else if (document.getElementById) {
		offsetLeft = Math.round((window.innerWidth - 20 - 640) / 2) - 64;
		
		var dv = document.getElementsByTagName("div");
		var im = document.getElementsByTagName("img");
		var sp = document.getElementsByTagName("span");
	}
	else {
		return;
	}
	
	var preLoads = new Object();
	
	for (i=0; i<im.length; i++) {
		if (im[i].id) {
			preLoads[im[i].id] = new Image;

			if (im[i].id.indexOf("button") == 0) {
				im[i].onmouseover = function() { hoover(this); }
				im[i].onmouseout = function() { unhoover(); }
			}
		}
	}

	for (i=0; i<sp.length; i++) {
		sp[i].onmouseout = function() {
			this.style.textDecoration = "none";
			this.style.cursor = "default";
		}
			
		sp[i].onmouseover = function() {
			this.style.textDecoration = "underline";
			
			if (document.all) {
				this.style.cursor = "hand";
			}
			else {
				this.style.cursor = "pointer";
			}
		}
	}
	
	if (offsetLeft > 0) {
		for (i=0; i<dv.length; i++) {
			dv[i].style.left = dv[i].offsetLeft + offsetLeft + "px";
		}
	}
}
