

addOnload(show);
addOnload(rolloverInit);
addOnload(rotate);

function addOnload(newFunction) {
	
	var oldOnload = window.onload;
	
	if(typeof oldOnload == "function") {
		window.onload = function() {
			if(oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	}
	else {
		window.onload = newFunction;
	}
}


function show(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById(id)) {document.getElementById(id).style.display='none';}			
		}
	if (d) {d.style.display='block'; }
}

function hide(id) {
	var d = document.getElementById(id);
		for (var i = 1; i<=10; i++) {
			if (document.getElementById(id)) {document.getElementById(id).style.display='block';}			
		}
	if (d) {d.style.display='none';}
}



function rolloverInit() {
	for (var i=0; i < document.images.length; i++) {
		//alert(document.images[i].id);
		//alert(document.images[i].parentNode.tagName);
		if(document.images[i].parentNode.tagName == "LI" || 
			document.images[i].id == "allevents" || 
			document.images[i].id == "pindies" ||
			document.images[i].id == "home" ||
			document.images[i].id == "news" ||
			document.images[i].id == "events" ||
			document.images[i].id == "tickets" ||
			document.images[i].id == "sound" ||
			document.images[i].id == "photos" ||
			document.images[i].id == "history" ||
			document.images[i].id == "blog" ||
			document.images[i].id == "merch"
			) {
			setupRollover(document.images[i]);
		}
	}
}

function setupRollover(thisImage){
	//alert(thisImage.id);
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;
	
	thisImage.overImage = new Image();
	thisImage.overImage.src = "menu_buttons/" + thisImage.id + "_over.jpg";
	thisImage.onmouseover = rollOver;
}

function rollOver(){
	this.src = this.overImage.src;
}
function rollOut(){
	this.src = this.outImage.src;
}



function validEmail(email) {
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?w+)*(\.\w{2,3})+$/;
	
	return re.test(email);
}

var xmlHttp;
function ajaxSubmit()
{ 
	if (!validEmail(document.getElementById("mailfield").value)) {
		//alert("not valid");
		document.getElementById("mailfield").value = "please enter valid address";
		return false;						   
   }
   else
   {
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		 {
		 alert ("Browser does not support HTTP Request")
		 return
		 }
		var url="maillist.php";		
		url=url+"?mailfield="+ document.getElementById('mailfield').value;
		//alert(url);
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
		
	function stateChanged() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		 	document.getElementById("mailfield").value=xmlHttp.responseText;
		 } 
	}
		
	function GetXmlHttpObject() {
		var xmlHttp=null;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			//Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		return xmlHttp;
	}

}
function newWinLinks() {
	for (var i=0; i<document.links.length; i++) {
		if(document.links[i].className == "player") {
			document.links[i].onclick = newWindow;
		}
		else if (document.links[i].className == "mapper") {
			document.links[i].onclick = mapWindow;
		}
		
	}
}
function newWindow() {
	var playerWindow = window.open(this.href, "On The One Player", "width=250, height=100, toolbar=no");
	playerWindow.focus();
	return false;
}
function mapWindow() {
	window.open(this.href, "On The One Map", "width=420, height=370, toolbar=no");	
	return false;	
}

function openSoundWindow(theURL) { //v2.0
  window.open(theURL,'Player','width=390, height=190, toolbar=no');
}

function openBrowserWindow(theURL) { //v2.0
  window.open(theURL,'Map','width=600, height=600, scrollbars=no, toolbar=no');
}
function openMailerWindow(theURL) { //v2.0
  window.open(theURL,'Mail','width=693, height=590, scrollbars=yes, toolbar=no');
}
function openMapWindow(theURL) { //v2.0
  window.open(theURL,'Mail','width=518, height=590, scrollbars=no, toolbar=no');
}
/*
function foto(picpath) {
	//alert(picpath);
	document.getElementById("foto").innerHTML = "<img src='" + picpath + "'>";
}
*/