addCSS = function(relPath) {
	if(document.getElementsByTagName("head")) {
		var head = document.getElementsByTagName("head")[0]; 
		var newStyle = document.createElement("link");
   		newStyle.setAttribute("type", "text/css");
		newStyle.setAttribute("rel", "stylesheet"); 
		newStyle.setAttribute("href", relPath); 
		head.appendChild(newStyle);
	}
}
addCSS("lib/megstyle_js.css");

function showHide() {
	this.allPreviews = new Array;
	this.collection = new Array;
	var workLists = document.getElementsByTagName("ul");	
	for (var i=0; i<workLists.length; i++) {
		if (workLists[i].className == "hide_work") {
			var workChildren = workLists[i].getElementsByTagName('*');
			for (var j=0; j<workChildren.length; j++) {
				if (workChildren[j].tagName.toLowerCase() == "a") {
					this.allPreviews[this.allPreviews.length] = workChildren[j];
				}
			}
			for (var k=0; k<workChildren.length; k++) {
				if (workChildren[k].tagName.toLowerCase() == "span") {
					this.control = workChildren[k];
				}
				else if (workChildren[k].tagName.toLowerCase() == "a") {
					this.target = workChildren[k];
				}
				if (this.target) {
					this.collection[this.collection.length] = new showHider(this, this.control, this.target, this.allPreviews);
					this.control == null;
					this.target == null;
				}
			}
		}
	}
	// work menu (years)
	var workMenu = document.getElementById("work_menu");
	var workMenuItems = workMenu.getElementsByTagName("span");
	for (var c=0; c<workMenuItems.length; c++) {
		workMenuItems[c].onclick = function() {
			for (var m=0; m<workMenuItems.length; m++) {
				workMenuItems[m].className = "";
			}
			for (var n=0; n<workLists.length; n++) {
				if (workLists[n].className == "show_work") {
					workLists[n].className = "hide_work";
				}
			}
			this.newId = "work" + this.innerHTML;
			document.getElementById(this.newId).className = "show_work";
			this.className = "current";
			return false;
		}
		workMenuItems[c].onmouseover = function() {
			if (this.className != "current") {
				this.className = "over";
			}
		}
		workMenuItems[c].onmouseout = function() {
			if (this.className != "current") {
				this.className = "";
			}
		}
	}
	// main menu (if no flash)
	if (!document.getElementById("about")) {
		return false;
	}
	else {
		var mmAbout = document.getElementById("about");
		mmAbout.onclick = function () {
			menSel(1,"sec");
			return false;
		}
		var mmWork = document.getElementById("work");
		mmWork.onclick = function () {
			menSel(2,"sec");
			return false;
		}
		var mmContact = document.getElementById("contact");
		mmContact.onclick = function () {
			menSel(3,"sec");
			return false;
		}
		mmAbout.onmouseover = function() { mmOver(this); }
		mmAbout.onmouseout = function() { mmOver(this); }
		mmWork.onmouseover = function() { mmOver(this); }
		mmWork.onmouseout = function() { mmOver(this); }
		mmContact.onmouseover = function() { mmOver(this); }
		mmContact.onmouseout = function() { mmOver(this); }
	}
}
function mmOver(mm) {
	if (mm.className != "over") {
		mm.className = "over";
	}
	else {
		mm.className = "";	
	}
}
showHider = function(showHide,control,target,allPreviews) {
	this.showHide = showHide;
	this.control = control;
	this.target = target;
	this.allPreviews = allPreviews;
	this.control.showHider = this;
	this.control.onclick = function() {
		this.showHider.toggle(this);
		return false;
	}
	this.control.onmouseover = function() {
		this.className = "over";
	}
	this.control.onmouseout = function() {
		this.className = "";
	}
}
showHider.prototype.toggle = function(control) {
	this.control = control;
	for(var m = 0; m<this.allPreviews.length; m++) {
		this.allPreviews[m].className = "hide_preview";
	}
	this.target.className = "show_preview";
}

/* start functions triggered by flash */
function menSel(number,prefix) {
	var sec = prefix + number;
	turnOn(sec,prefix);
	//window.document.mg_menu.setVariable("which_page", sec);
}

function turnOn(sec,prefix) {
	clearAll(prefix);
	document.getElementById(sec).className = "show_content";
}

function clearAll(prefix) {
	for (var count=1;count<=3;count++) {
		var sec = prefix + count;
		turnOff(sec);
	}
}

function turnOff(sec) {
	document.getElementById(sec).className = "hide_content";
}
/* end functions triggered by flash */
