//This script is copyright Nate DeSimone, 2006

var imgOpen;
var dirLevels = 0;

//////////////////////////////
// Menu Animation Functions //
//////////////////////////////
function MenuOver(DivId)
{
	if(document.getElementById)
	{
		document.getElementById(DivId).className = "menuover";
		document.getElementById(DivId + "A").className = "mouseover";
	}
	else if(document.all)
	{
		document.all[DivId].className = "menuover";
		document.all[DivId + "A"].className = "mouseover";
	}
}

function MenuOut(DivId)
{
	if(document.getElementById)
	{
		document.getElementById(DivId).className = "menuitem";
		document.getElementById(DivId + "A").className = "normal";
	}
	else if(document.all)
	{
		document.all[DivId].className = "menuitem";
		document.all[DivId + "A"].className = "normal";
	}
}

/////////////////////////
// Common Menu Writing //
/////////////////////////

//This function is used to specify the number of directory levels
//there are between the currently loaded page and the root for the website
function setDirLevels(Levels)
{
	dirLevels = Levels;
}

function writeCommonMenu()
{
	var i;
	var homeURL     = "index.html";
	var aboutURL    = "about.html";
	var softwareURL = "software.html";
	var resumeURL   = "resume.html";
	
	for(i = 0; i < dirLevels; i++)
	{
		homeURL     = "../" + homeURL;
		aboutURL    = "../" + aboutURL;
		softwareURL = "../" + softwareURL;
		resumeURL   = "../" + resumeURL;
	}
	
	//Initial Headers
	document.write("<div class=\"menubar\">\n");
	document.write("<h1>Nate DeSimone's Homepage</h1>\n\n");
	
	//Menu Items
	writeMenuItem("MenuHome",homeURL,"Home");
	writeMenuItem("MenuAbout",aboutURL,"About Me");
	writeMenuItem("MenuSoftware",softwareURL,"Software");
	writeMenuItem("MenuResume",resumeURL,"Resume");
	//writeMenuItem("MenuWWWW","wwww.html","WWWW");
	
	//Footers
	document.write("<p style=\"margin:0px; height:22px\">&nbsp;</p>\n");
	document.write("</div>");
	document.write("<div class=\"content\">\n");
}

function writeMenuItem(Id, URL, Name)
{
	var ret = "<span id=\"" + Id + "\" class=\"menuitem\" onmouseover=\"MenuOver('" + Id + "');\"";
	ret += "onmouseout=\"MenuOut('" + Id + "');\" onclick=\"top.location.href = '" + URL + "';\">\n";
	ret += "<a id=\"" + Id + "A\" class=\"normal\" href=\"" + URL + "\">" + Name + "</a>\n";
	ret += "</span>\n";
	
	document.write(ret);
}

//////////////////////
// Pop Up Functions //
//////////////////////

//This function opens a new window of specified height and width with the filename src displayed
//It returns the name of the window
function openWindow(src,wide,height)
{
	//Temporary variables
	var i = 0;
	var temp = "";
	var win = null;
	
	//The name variable, this will contain the name of the window
	var name = src;

	//Because IE cannot handle names with '/' or '.' in them
	//This while loop will search the string of any '/' characters and remove them from the string
	while(name.indexOf("/") != -1)
	{
		i = name.indexOf("/");
		temp = name.substring(i+1,name.length);
		name = name.substring(0,i) + temp;
	}
	//Here is the name thing, only for removing '.' characters
	while(name.indexOf(".") != -1)
	{
		i = name.indexOf(".");
		temp = name.substring(i+1,name.length);
		name = name.substring(0,i) + temp;
	}

	//This is the list of optional arguments to be used to display the window
	var arguments = "toolbar=no,menubar=no,resizable=no,directories=no,location=no,scrollbars=no,status=no,dialog=yes,height=" + (height + 20) + ",width=" + (wide + 20) + ",top=" + (screen.height / 2 - height / 2) + ",left=" + (screen.width / 2 - wide / 2);
	win = window.open(src,name, arguments);
	if(win == null)
	{
		alert("A pop up blocker stopped the graphic from loading, try clicking again.");
	}
	return name;
}

//This function opens a new window with the specified image displayed in it, at the image's natural width and height
function openImageWindow(imgSrc)
{
	imgOpen = new Image();
	imgOpen.src = imgSrc;
	checkImageLoad(imgSrc);	
}

function checkImageLoad(imgSrc)
{
	if(imgOpen.complete == true)
	{
		//If the picture has completely loaded, open the window
		openWindow(imgSrc,imgOpen.width + 10,imgOpen.height + 20);
	}
	else
	{
		//Continue to poll until the browser has completely loaded the image from the network
		setTimeout("checkImageLoad('" + imgSrc + "');",50);
	}
}