var navRoot = false;

function initPage()
{
	navRoot = document.getElementById("sub-nav");
	
	if (navRoot == null) {
		return;
	}
	
	var lis = navRoot.getElementsByTagName("li");
	for (var i=0; i<lis.length; i++) {
		var links = lis[i].getElementsByTagName("a");
		if (lis[i].parentNode == navRoot) {
			//alert ("lis["+i+"].parentNode = " + lis[i].parentNode);
			links[0].onclick = function() {

				if (this.parentNode.childNodes.length >2) {
					
					/*
					this bit of script removed the active class from an anchor that was already set to active
					and clicked for a second time (like a toggle).  There was no need for this script to be here
					since it made navigation confusing.  It was removed on Jan 22nd, 2008
					
					if (this.parentNode.className.indexOf("active") != -1 ) {  
						this.parentNode.className = this.parentNode.className.replace("active", "");
						return false;
					}
					*/
					
					var levelis = this.parentNode.parentNode.getElementsByTagName("li");
					
					for (var j=0; j<levelis.length; j++) {
						if (levelis[j] != this) {
							if (levelis[j].parentNode == navRoot) {
								levelis[j].className = levelis[j].className.replace("active", "");
							}
						}
					}
					
					this.parentNode.className += " active";
					return true;
				} else {
					return true;
				}
			}
		}
	}
}

function popUp(sURL, theWidth, theHeight) {
	//    Gets screen size
	var iPageWidth, iPageHeight;
	if (self.innerHeight) {
		iPageWidth = self.innerWidth;
		iPageHeight = self.innerHeight;
	}
	else if (document.all && document.getElementById) {
		iPageWidth = screen.availWidth;
		iPageHeight = screen.availHeight;
	}
	else if (document.body) {
		iPageWidth = document.body.clientWidth;
		iPageHeight = document.body.clientHeight;
	}

	leftSideOfPopup = (iPageWidth - theWidth)/2;
	topSideOfPopup = (iPageHeight - theHeight)/2;
	features = "toolbar=0,width=" + theWidth + ",height=" + theHeight + ",status=0,scrollbars=0,resize=0,menubar=0,location=0,directories=0,screenX=" + leftSideOfPopup + ",left=" + leftSideOfPopup + ",screenY=" + topSideOfPopup + ",top=" + topSideOfPopup;

	theWindow = window.open(sURL, "", features);
}

function tourPopup() {
	// check to see that the browser supports the getElementsByTagName method
	// if not, exit the loop 
	if (!document.getElementsByTagName) {
		return false; 
	} 
	// create an array of objects of each link in the document 
	var popuplinks = document.getElementsByTagName("a");
	// loop through each of these links (anchor tags) 	
	for (var i=0; i < popuplinks.length; i++) {	
		// if the link has a class of "popup"...	
		if (popuplinks[i].getAttribute("id") == "tourWindow") {
			if (popuplinks[i].className == "gateway") {
				popuplinks[i].href = "javascript:void(popUp('http://www.media-seaway.com/seaway_handbook/flash-tour-en/tour.htm',738,504))";
				/* popuplinks[i].onclick = function() {	
					popUp('http://www.media-seaway.com/english/tour.htm',738,504);
					return false;
				} */
			} else if (popuplinks[i].className == "gateway_fr") {
				popuplinks[i].href = "javascript:void(popUp('http://www.media-seaway.com/seaway_handbook/flash-tour-fr/tour.htm',738,504))";
				/* popuplinks[i].onclick = function() {	
					popUp('http://www.media-seaway.com/french/tour.htm',738,504);
					return false;
				} */
			}
		}
	}
}

if (window.addEventListener) {
	window.addEventListener("load", initPage, false);
	window.addEventListener("load", tourPopup, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", initPage);
	window.attachEvent("onload", tourPopup);
}