window.onload = initPage;

function initPage() {
  rotateImage("rImage");
	var buttons = document.getElementById("navigation").getElementsByTagName("a");
  for (var i=0; i<buttons.length; i++) {
    var currentBtn = buttons[i];
	if(currentBtn.title == "home") {
		currentBtn.href = "index.html";
	} else {
		currentBtn.onclick = changeHTML;
	}
  }
  var dirButton = document.getElementById("directions").getElementsByTagName("a");
  dirButton[0].onclick = changeHTML;
    var dirButton = document.getElementById("casLink").getElementsByTagName("a");
  dirButton[0].onclick = changeHTML;
  var radioBtn = document.getElementById("news").getElementsByTagName("a");
  for (var i=0; radioBtn.length; i++) {
	  if (radioBtn[i].title == "radioSpot") {
		  radioBtn[i].onclick = changeHTML;
	  }
  }	
}
function needPix() {
	alert("We need pictures for 2006!");
}

function testing() {
	/*var me = getActivatedObject(e); */
	var thisButton = this.title;
	alert("I've been Clicked: " + thisButton);
}

function changeHTML(){
  var request = createRequest();
  var url = "HTMLpages/" + this.title + ".html";
  if (request == null) {
    alert("Unable to create request");
    return;
  }
  request.onreadystatechange = showPage;
  request.open("GET", url, true);
  request.send(null);
  changeWoody(this.title);
}

function showPage() {
  if (request.readyState == 4) {
    if (request.status == 200) {
      document.getElementById("mainContent").innerHTML = request.responseText;
    }	
  }
}

function changeWoody(pageName) {
	var woody = document.getElementById("navigation");
	switch(pageName) {
		case "home":
			woody.style.backgroundPositionY = "0em";
			changeActive("home");
			break;
		case "events":
			woody.style.backgroundPositionY = "2.5em";
			changeActive("events");
			break;
		case "scores":
			woody.style.backgroundPositionY = "5em";
			changeActive("scores");
			break;
		case "photos":
			woody.style.backgroundPositionY = "7em";
			changeActive("photos");
			break;
		case "links":
			woody.style.backgroundPositionY = "9em";
			changeActive("links");
			break;
		case "contact":
			woody.style.backgroundPositionY = "11em";
			changeActive("contact");
			break;
		default:
			woody.style.backgroundPositionY = "0em";
			changeActive("home");
	} 
}

function setContactForm() {
	var emailSendTo = document.getElementById("emailLink").getElementsByTagName("a");
	for (var i=0; i < emailSendTo.length; i++) {
		switch(emailSendTo[i].title) {
			case "mudflat":
			emailSendTo[i].href = "mailto:tmperin@comcast.net";
			break;
			case "doc":
			emailSendTo[i].href = "mailto:rwydro@comcast.net";
			break;
			default:
			emailURL[i].url = "";
		}
	}
}
function dummy() {
	alert("Come on, We haven't shot that Match yet!");
}

function changeActive(linkTitle) {
	var buttons = document.getElementById("navigation").getElementsByTagName("a");
	for(var i=0;i<buttons.length;i++){
		if(buttons[i].title == linkTitle){
		buttons[i].className = "active";
		alert("this is the active class " + e.title);
		} else {
			buttons[i].className = "inactive";
		}
	}
}
