function openFlash(name) {
	eval("window.open('flash/" + name + "', '" + name + "', 'width=100, height=100, left=0, top=0, status=yes')");
}

function tell(name) {
	eval("window.open('adventures/" + name + "/tell', 'tell', 'width=280, height=195, left=0, top=0')");
}

function checkForm(form) {
	if (form.name.value != '' && form.email.value != '' && form.comment.value != '') {
		if (form.email.value.lastIndexOf('@') != -1 && form.email.value.lastIndexOf('.') != -1) {
			return true;
		} else {
			alert('The email address you supplied is not valid');
			return false;
		}
	} else {
		alert('You must enter something for every item');
		return false;
	}
	return false;
}

function writeEmail(first, second) {
	var bits = 'bugger@off_mailto:';
	var firstRev = '';
	var secondRev = '';
	for (i = first.length; i > 0; i--) { 
		firstRev += first.substring(i-1,i);
    }
   	for (i = second.length; i > 0; i--) { 
		secondRev += second.substring(i-1,i);
    }

	document.write('<a href=\"'+bits.substring(11, 18)+firstRev+bits.substring(6, 7)+secondRev+'\">'+firstRev+bits.substring(6, 7)+secondRev+'</a>');
}


function getElementTop(obj) { 
	var top = obj.offsetTop;
	var op = obj.offsetParent;
	while (obj.parentNode && document.body != obj.parentNode) {
		obj = obj.parentNode;
		top -= obj.scrollTop;
		if(op == obj) { 
			top += obj.offsetTop;
			op = obj.offsetParent;
		}
	}
	return top;
}

function Resizer(obj) {
		if(!Resizer.Instances) Resizer.Instances = new Array();
		this.id = Resizer.Instances.length;
		Resizer.Instances[this.id] = this;

		this.object = obj;

		this.resizeTo = function(tw, th, frames) {
				clearTimeout(this.timer);
				this.ow = this.object.scrollWidth;
				this.oh = this.object.scrollHeight;
				this.tw = tw; this.th = th;
				this.frame = 0;
				this.frames = frames;
				this.timer = setInterval("Resizer.Instances["+this.id+"].run()", 30);
		}

		this.run = function() {
			var scale = (Math.cos(Math.PI*this.frame/this.frames)-1)/2;
			this.object.style.width = (this.ow - this.tw)*scale + this.ow + "px";
			this.object.style.height = (this.oh - this.th)*scale + this.oh + "px";
			/* Fix for IE */ if (navigator.userAgent.indexOf("MSIE") != -1) document.getElementById("footer").style.top = document.body.scrollHeight - 61;
				if (this.frame >= this.frames) {
						this.object.style.width = this.tw+"px";
						this.object.style.height = this.th+"px";
						clearTimeout(this.timer);
						this.frame = 0;
				}
				this.frame++;
		}
}

function Fader(obj) {
		if(!Fader.Instances) Fader.Instances = new Array();
		this.id = Fader.Instances.length;
		Fader.Instances[this.id] = this;

		this.object = obj;

		this.fadeTo = function(target) {
				clearTimeout(this.timer);
				this.old = this.getOpacity();
				this.target = target;
				this.frame = 0;
				this.timer = setInterval("Fader.Instances["+this.id+"].run()", 30);
		}

		this.getOpacity = function() {
				if (val = this.object.style.opacity) return val*100;
				else {
					if (this.object.style.filter) {
						if (val = this.object.style.filter.match(/opacity=([0-9.]+)\)$/)[1]) return val;
					}
					return 100;
				}
		}

		this.setOpacity = function(val) {
				this.object.style.opacity = val/100;
				this.object.style.filter = "alpha(opacity="+val+")";
		}

		this.run = function() {
				this.setOpacity((this.old - this.target)*(Math.cos(Math.PI*this.frame/20)-1)/2 + this.old);
				if (this.frame > 19) {
						this.setOpacity(this.target);
						clearTimeout(this.timer);
						this.frame = 0;
				}
				this.frame++;
		}
}

function ajaxRequest(url, returnFunction) {
		var ua = navigator.userAgent.toLowerCase();
		if (!window.ActiveXObject) request = new XMLHttpRequest();
		else if (ua.indexOf('msie 5') == -1) request = new ActiveXObject("Msxml2.XMLHTTP");
		else request = new ActiveXObject("Microsoft.XMLHTTP");

		request.open("GET", url, true);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		if (returnFunction) {
			request.onreadystatechange = function() {
				if (request.readyState == 4 && request.status == 200) {
					if (request.responseText) returnFunction(request.responseText);
				}
			};
		}
		request.send(null);
}
