﻿function hideWarning() {
	if (!document.getElementsByTagName) return false;  //tests the browser's js support
	if (!document.getElementById) return false; //tests the browser's js support
	if (document.getElementById("warning")) {
		document.getElementById("warning").style.display = "none";
	}
	return false;
}


/* this function prepareNav tests for browser compatibility and then adds the onclick function to every link in subnav to call the next function (when clicked) */
function prepareNav() {
	if (!document.getElementsByTagName) return false;  //tests the browser's js support
	if (!document.getElementById) return false; //tests the browser's js support
	if (!document.getElementById("blurbs")) return false;
	if (!document.getElementById("thumbnails")) return false;
	if (!document.getElementById("firstBlurb")) return false;
	document.getElementById("firstBlurb").style.display = "block";
	var thumbList = document.getElementById("thumbnails");
	var links = thumbList.getElementsByTagName("a"); 
	for ( var i=0; i < links.length; i++) {
		var linkTitle = links[i].getAttribute("title");
		var name = linkTitle + "Blurb";
		var blurb = document.getElementById(name);
		if (name != ("firstBlurb")) {
			blurb.style.display = "none"; 
		}
		links[i].onmouseout = function() {
			return hideBlurb(this);
		}
		links[i].onmouseover = function() { 
			return showBlurb(this); 
		}
		if (document.getElementById("videoPlayer")) {
			links[i].onclick = function() {
				return playClip(this);
			}
		}
		if (document.getElementById("aboutBody")) { // this prevents the bio links from being followed if javascript is on
			links[i].onclick = function() {
				return emptyLinks(this);
			}
		} 
	}
}

function emptyLinks(link) { // this prevents the bio links from being followed if javascript is on
	var newLink = link;
	return false;
}

function showBlurb(whichLink) {
	var linkTitle = whichLink.getAttribute("title");
	var name = linkTitle + "Blurb";
	var blurb = document.getElementById(name);
	blurb.style.display = "block";
	var thumbList = document.getElementById("thumbnails");
	var links = thumbList.getElementsByTagName("a");
	for ( var i=0; i < links.length; i++) {	
		var x = links[i].getAttribute("title"); 
		var z = x + "Blurb";
		var y = document.getElementById(z);
		if (y != blurb) {
			y.style.display = "none";
		}
	} 
	return false; 
}

function hideBlurb(whichLink) {
	var linkTitle = whichLink.getAttribute("title");
	var name = linkTitle + "Blurb";
	var blurb = document.getElementById(name);
	blurb.style.display = "none";
	document.getElementById("firstBlurb").style.display = "block";
	return false; 
}


/* ######################################################### */

function playClip(whichclip) {
	var clip = whichclip.getAttribute("title");
	if (clip == "first") {
		sceneOne();
		return false
	}
	if (clip == "second") {
		sceneTwo();
		return false
	}
	if (clip == "third") {
		sceneThree();
		return false
	}
	if (clip == "fourth") {
		sceneFour();
		return false
	}
	if (clip == "fifth") {
		sceneFive();
		return false
	}
	return false;
}


function getClip(movieName) {
  if (window.document[movieName]) {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet") == -1) {
    if (document.embeds && document.embeds[movieName]) {
      return document.embeds[movieName]; 
    }
  }
  else {
    return document.getElementById(movieName);
  }
}

function sceneOne() {
	var clip = getClip("movie");
	clip.GotoFrame(0);	
	return false;
}
function sceneTwo() {
	var clip = getClip("movie");
	clip.GotoFrame(1);	
	return false;
}
function sceneThree() {
	var clip = getClip("movie");
	clip.GotoFrame(2);	
	return false;
}
function sceneFour() {
	var clip = getClip("movie");
	clip.GotoFrame(3);	
	return false;
}
function sceneFive() {
	var clip = getClip("movie");
	clip.GotoFrame(4);	
	return false;
}

/* ######################################################### */

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

/* this is just a handy generic trick to allow you to add to the list at the bottom of this page to begin any number of functions when the page loads */ 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/* the following command begins the following list of scripts after the page has loaded. You can add as many as you want thanks to the above addLoadEvent script */
addLoadEvent(hideWarning);
addLoadEvent(prepareNav);
addLoadEvent(externalLinks);