//Navigation
function lowNav(id) {
  if (document.getElementById) {
    document.getElementById(id).className = 'nav';
    document.getElementById(id+'TD').className = 'nav';
    if (document.getElementById(id+'Foot')) {
      document.getElementById(id+'Foot').className = 'nav';
    }
    if (document.getElementById(id+'FootTD')) {
      document.getElementById(id+'FootTD').className = 'nav';
    }
    lowSubNav(id);
  }
}
function highNav(id) {
  if (document.getElementById) {
    document.getElementById(id).className = 'navHigh';
    document.getElementById(id+'TD').className = 'navHigh';
    if (document.getElementById(id+'Foot')) {
      document.getElementById(id+'Foot').className = 'navHigh';
    }
    if (document.getElementById(id+'FootTD')) {
      document.getElementById(id+'FootTD').className = 'navHigh';
    }
    highSubNav(id);
  }
}
function lowSubNav(id) {
  if (document.getElementById && document.getElementById(id+'SubNav')) {
    document.getElementById(id+'SubNav').style.display = 'none';
  }
}
function highSubNav(id) {
  if (document.getElementById && document.getElementById(id+'SubNav')) {
    document.getElementById(id+'SubNav').style.display = 'block';
  }
}

//Home page image rotation
function startSwitch(id1,leftPx,topPx) {
	var image1 = 'image'+id1;
	var id2 = id1 + 3;
	if (id2 > pictureCount) {
	  id2 -= pictureCount;
	}
	var image2 = 'image'+id2;
	
  if (document.getElementById && document.getElementById(image1) && document.getElementById(image2)) {
    document.getElementById(image1).style.left = leftPx+'px';
    document.getElementById(image1).style.top = topPx+'px';
    document.getElementById(image2).style.left = leftPx+'px';
    document.getElementById(image2).style.top = topPx+'px';
    fadeOut(image1, image2, 100);
  }
  setTimeout("startSwitch("+(id2)+","+leftPx+","+topPx+");",10000);
}
function fadeOut(image1, image2, i) {
  document.getElementById(image1).className = 'opacity'+twoDigit(i);
  if (i > 0) {
    setTimeout("fadeOut('"+image1+"','"+image2+"',"+(i-5)+");",50);
	} else {
		fadeIn(image2,0);
	}
}
function fadeIn(image, i) {
  document.getElementById(image).className = 'opacity'+twoDigit(i);
  if (i < 100) {
    setTimeout("fadeIn('"+image+"', "+(i+5)+");",50);
  }
}

//pop up windows
function openInfoWindow(pageUrl) {
  newWindow(pageUrl,'info',315,300);
}
function openGameWindow(pageUrl) {
  newWindow(pageUrl,'game',500,500);
}
function newWindow(mypage, myname, w, h) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no'
  win = window.open(mypage, myname, winprops)
  if (win.window.focus()) { win.window.focus(); }
}

//form submission
function submitContactForm() {
	if (document.contactForm.name.value != '' && document.contactForm.email.value != '' && document.contactForm.message.value != '') {
		if (document.contactForm.email.value == document.contactForm.confirmEmail.value) {
			openInfoWindow('');
			document.contactForm.submit();
		} else {
			alert('The "Email" and "Confirm Email" fields do not match.  If your email address is not correct, you message will not be sent.');
		}
	} else {
		alert('All required fields are not completed.  Please make sure you have entered: "Name", "Email", and "Message".');
	}
}

//Misc
function twoDigit(num) {
  if (num < 10) {
    return '0'+num;
  } else {
    return num;
  }
}