//@Author Derrick Barra
//The internal website logic
//Using This: index.html, 
//Using:


/*********************************
Global Data Members
**********************************/
var currentMenu = "";
var currentSubmenu = "";
var currentPortfolioMenu = "";
var currentPortfolioPiece = "";

/*********************************
Global Functions
**********************************/
function doNothing()
{
	//Does what it says on the tin.
}


//Return a random within the integer parameters sent in.
//Code snippet from http://www.admixweb.com/2010/08/24/javascript-tip-get-a-random-number-between-two-integers/
function getRandomInt(from, to)
{
    return Math.floor(Math.random() * (to - from + 1) + from);
}


//Remove all of the mainMenu image rollovers
function removeMainRollovers()
{
	document.getElementById("menu1").src = "images/menu1.png";
	document.getElementById("menu2").src = "images/menu2.png";
	document.getElementById("menu3").src = "images/menu3.png";
}

//Remove all of the subMenu image rollovers
function removeSubRollovers()
{
	document.getElementById("resumeSubmenu1").src = "images/resumeSubmenu1.png";
	document.getElementById("resumeSubmenu2").src = "images/resumeSubmenu2.png";
	
	document.getElementById("portfolioSubmenu1").src = "images/portfolioSubmenu1.png";
	document.getElementById("portfolioSubmenu2").src = "images/portfolioSubmenu2.png";
	document.getElementById("portfolioSubmenu3").src = "images/portfolioSubmenu3.png";
	
	document.getElementById("contactSubmenu1").src = "images/contactSubmenu1.png";
	document.getElementById("contactSubmenu2").src = "images/contactSubmenu2.png";
	document.getElementById("contactSubmenu3").src = "images/contactSubmenu3.png";
}


//Remove any rollovers from the portfolio pieces
function removePortfolioRollovers()
{
	//Count the number of portfolio pieces that are currently being displayed
	var portfolioSize;
	if      (currentPortfolioMenu.id == "portfolioSubmenu1"){portfolioSize = jQuery("#design img").size();}			//Design
	else if (currentPortfolioMenu.id == "portfolioSubmenu2"){portfolioSize = jQuery("#programming img").size();}	//Programming
	else if (currentPortfolioMenu.id == "portfolioSubmenu3"){portfolioSize = jQuery("#art img").size();}			//Art

	//For each portfolio piece that exists, reset their rollover state
	for (i = 0; i < portfolioSize; i++)
	{
		if      (currentPortfolioMenu.id == "portfolioSubmenu1"){document.getElementById("designLink" + i).src = "images/design/" + i + ".png";}
		else if (currentPortfolioMenu.id == "portfolioSubmenu2"){document.getElementById("programmingLink" + i).src = "images/programming/" + i + ".png";}
		else if (currentPortfolioMenu.id == "portfolioSubmenu3"){document.getElementById("artLink" + i).src = "images/art/" + i + ".png";}
	}
}

//Hide all of the sub menus
function hideSubmenus()
{
	document.getElementById("resumeSubmenuWrapper").style.display = "none";
	document.getElementById("contactSubmenuWrapper").style.display = "none";
	document.getElementById("portfolioSubmenuWrapper").style.display = "none";
}

//Hide all the portfolio pieces
function hidePortfoliomenus()
{
	document.getElementById("design").style.display = "none";
	document.getElementById("programming").style.display = "none";
	document.getElementById("art").style.display = "none";
}

/*
*	Called when the user clicks on the header image (the logo), resets any rollovers and hides all the submenus,
*	Also brings up the splash page again.
*/
function resetMenus()
{
	//Reset the currentMenu and currentSubmenu and currentPortfolioMenu
	currentMenu = "";           //Portfolio, Resume, Contact (EX: menu1, menu2, menu3)
	currentSubmenu = "";		//Portfolio -->	Design, Programming, Art (EX: portfolioSubmenuWrapper, resumeSubmenuWrapper, contactSubmenuWrapper)
	currentPortfolioMenu = "";	//Portfolio --> Design (EX: portfolioSubmenu1, portfolioSubmenu2, portfolioSubmenu3)
	currentPortfolioPiece = "";
	
	//Remove any rollovers 
	removeMainRollovers(); 
	removeSubRollovers();
	currentPortfolioPiece = "";
	removePortfolioRollovers();
	
	//Hide all the sub menus and portfolio menus
	hideSubmenus();
	hidePortfoliomenus();
	
	//Reset the content area 
	document.getElementById("content").src = "images/design/content/off.png";
	
	//Hide the portfolio content area
	document.getElementById("content").style.display = "none";
	
	//Show the splash page again
	document.getElementById("splashWrapper").style.display = "";
}

/*
*	Fires when a user clicks on one of the main menu links (portfolio, resume, contact)
*	Resets the current portfolio sub menu back to nothing,
*	Hides the splash page,
*	Hides all the sub menus, resets all the rollovers, then sets the new rollover image
*	and shows the appropriate sub menu
*	PARAM: name- The name of the menu buttons id (EX: "menu1")
*/
function mainMenuClick(name)
{
	//Reset the portfolio pieces image rollovers
	currentPortfolioPiece = "";
	removePortfolioRollovers();
	
	//Reset the current portfolio subMenu
	currentPortfolioMenu = "";
	
	//Remove the portfolio pieces wrappers
	hidePortfoliomenus();
	
	//Hide the splash page
	document.getElementById("splashWrapper").style.display = "none";
	
	//Reset the content area 
	document.getElementById("content").src = "images/design/content/off.png";
	
	//Hide the portfolio content
	document.getElementById("content").style.display = "none";
	
	//Remove all of the rollovers and hide all the sub menus 
	if (name != currentMenu.id){removeMainRollovers(); removeSubRollovers();}
	hideSubmenus();
	
	//Turn the buttons rollover graphics on
	setRollover(true, '', name);
	
	//Set the current menu and subMenu's
	currentMenu = document.getElementById(name);
	if      (name == "menu1"){currentSubmenu = document.getElementById("portfolioSubmenuWrapper");}
	else if (name == "menu2"){currentSubmenu = document.getElementById("resumeSubmenuWrapper");}
	else if (name == "menu3"){currentSubmenu = document.getElementById("contactSubmenuWrapper");}
	
	//Show the new subMenu
	currentSubmenu.style.display = "";
}


/*
*	Fires when a user clicks on one of the sub menu links while under the portfolio menu (design, programming, art)
*	Removes all the current sub menu rollovers,
*	Removes all the current portfolio pieces,
*	Set the new rollover image,
*	Set the currentPortfolioMenu to the button that was clicked
*	Show the portfolio pieces
*	PARAM: name- The name of the menu buttons id (EX: "portfolioSubmenu1")
*/
function subMenuClick(name)
{
	//Remove the current sub menu rollovers
	removeSubRollovers();
	
	//Reset the portfolio pieces image rollovers
	currentPortfolioPiece = "";
	removePortfolioRollovers();
	
	//Remove the portfolio pieces wrappers
	hidePortfoliomenus();
	
	//Reset the content area 
	document.getElementById("content").src = "images/design/content/off.png";
	
	//Remove the content area
	document.getElementById("content").style.display = "none";
	
	//Turn the sub menu's buttons rollover graphics on
	if (currentPortfolioMenu.id != name){setRollover(true, "", name);}
	else {setRollover(true, "", currentPortfolioMenu.id, true);} //If the user clicks on the same subMenus multiple times, keep the image set to the rollover

	//Set the currentPortfolioMenu to the button that was clicked
	if      (name == "portfolioSubmenu1"){currentPortfolioMenu = document.getElementById("portfolioSubmenu1");}
	else if (name == "portfolioSubmenu2"){currentPortfolioMenu = document.getElementById("portfolioSubmenu2");}
	else if (name == "portfolioSubmenu3"){currentPortfolioMenu = document.getElementById("portfolioSubmenu3");}
	
	//Show the portfolio pieces wrapper
	document.getElementById("portfolioPiecesWrapper").style.display = "";
	
	//Show the portfolio pieces
	if      (currentPortfolioMenu.id == "portfolioSubmenu1"){document.getElementById("design").style.display = "";}
	else if (currentPortfolioMenu.id == "portfolioSubmenu2"){document.getElementById("programming").style.display = "";}
	else if (currentPortfolioMenu.id == "portfolioSubmenu3"){document.getElementById("art").style.display = "";}
}


/*
*	Fires when a user clicks on a portfolioPieceImage.
*	PARAM: type- string, either design, programming, or art.
*	PARAM: number- int, the image number that was clicked on (EX: 0, 1, 2)
*/
function portfolioPieceClick(type, number)
{
	//Sets the currentPortfolioPiece to the correct piece
	currentPortfolioPiece = type + "Link" + number;
	
	//Shows the content area
	document.getElementById("content").style.display = "";
	
	//Removes the rollover state of the portfolioPiece images
	removePortfolioRollovers();
	
	//Sets the rollover state of the clicked on portfolioPiece image
	document.getElementById(currentPortfolioPiece).src = "images/" + type + "/" + number + "Rollover.png";
	
	//Remove all content
	removeContent();
	
	//Load up the content
	document.getElementById(type + number).style.display = "";
}


//Hide all the content area divs
function removeContent()
{
	for (var i = 0; i < 8; i++)
	{
		document.getElementById("design" + i).style.display = "none";
		document.getElementById("programming" + i).style.display = "none";
		document.getElementById("art" + i).style.display = "none";
	}
}


/*
*	Fires when a user either mouseover's or mouseouts over a button.
*	Sets the rollover image on or off appropriately
*	PARAM: t- boolean, whether the image should display the rollover or not
*	PARAM: path- string, concatenated onto the end of "images/" to provide a lower path to the rollover image
*	PARAM: name- string, the name of the image that will have the rollover turned on or off
*/
function setRollover(t, path, name, forceChange, portfolioPieceNumber)
{
	//Did this call come from onmouseover or onmouseout (are we turning the rollover on or off?)
	var rollover;
	if (t != undefined && t!= null && t){rollover = "Rollover";}
	else {rollover = "";}
	
	//Is this image the currentMenu or subMenu? If so then don't change the image, otherwise go ahead and change it
	if (name == currentMenu.id || name == currentSubmenu.id || name == currentPortfolioMenu.id || name == currentPortfolioPiece && !forceChange){}
	else 
	{
		//Did this come from a portfolio piece link?
		if (portfolioPieceNumber != null && portfolioPieceNumber != undefined){document.getElementById(name).src = "images/" + path + portfolioPieceNumber + rollover + ".png";}
		else {document.getElementById(name).src = "images/" + path + name + rollover + ".png";}
	}
}
