// GLOBALS
var leftNavContainer = "leftNav"; // Id of element containing left navigation
var leftNavButtons = "navButton"; // Class of elements that will be site buttons
var leftNavActive = "leftNavSlider"; // Id of element that slides next to active item
var navSpeed = 750; // Speed that the navigation animations will be

var topNavContainer = "topNav"; // Id of element containing top navigation
var topNavHidden = "topNavHidden"; // Id of the element that contains the top navigation that is not viewable currently
var topNavWrap = "topNavWrap"; // Id of the element that contains the top navigation that is viewable currently
var topNavButtonsClass = "topButton"; // Class of elements that will be top site buttons
var topNavGroups = "topNavGroup"; // Class of the element that containsthe site buttons
var topNavActive = "topNavSlider"; // Id of element that slides next to active items at the top
var topButtonsWidth = 54; // Width of top nav buttons including the margins in pixels
var topNavBack = "topNavBack" // Id of the top navigations back button
var topNavNext = "topNavNext" // Id of the top navigations back button

var internalLinks = "linkTo" // Class on items that will work as internal links. Refers to rel or alt tag to know which page to view
var leftNavAnim = new Array();
var activeSlider;

var topNavButtons;
var topNavAnim = new Array();
var topNavWrapAnim;
var topActiveSlider;

function createLeftNav()
{
	activeSlider = new Fx.Morph(leftNavActive, {duration: navSpeed, link: 'cancel', transition: Fx.Transitions.Sine.easeInOut});
	leftNavButtons = $(leftNavContainer).getElements("."+leftNavButtons);
	leftNavButtons.each(function(button){
		leftNavAnim[button.id.replace("left_","")] = new Fx.Morph(button, {duration: navSpeed, link: 'cancel', transition: Fx.Transitions.Sine.easeInOut});
		button.addEvent("click",function(){
			if(button.id != "left_"+currentPage)
			{
				if($("left_"+currentPage) && button.offsetTop < $("left_"+currentPage).offsetTop) dir = "up";
				else dir = "down";
				shiftContent(currentPage,button.id.replace("left_",""),dir,wrapper,hidden);
				currentPage = button.id.replace("left_","");
				HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
			}
		});
	});
}
function createTopNav()
{
	topNavGroups = $(topNavContainer).getElements("."+topNavGroups);
	topActiveSlider = new Fx.Morph(topNavActive, {duration: navSpeed, link: 'cancel', transition: Fx.Transitions.Sine.easeInOut});
	topNavWrapAnim = new Fx.Morph(topNavWrap, {duration: navSpeed, link: 'cancel', transition: Fx.Transitions.Sine.easeInOut});
	topNavButtons = $(topNavContainer).getElements("."+topNavButtonsClass);
	topNavButtons.each(function(button){
		topNavAnim[button.id.replace("top_","")] = new Fx.Morph(button, {duration: navSpeed, link: 'cancel', transition: Fx.Transitions.Sine.easeInOut});
		button.addEvent("click",function(){
			if(button.id != "top_"+currentPage+"_"+currentSect[currentPage])
			{
				if($("top_"+currentPage+"_"+currentSect[currentPage]) && button.offsetLeft < $("top_"+currentPage+"_"+currentSect[currentPage]).offsetLeft) dir = "left";
				else dir = "right";
				shiftContent(subs[currentPage][currentSect[currentPage]],subs[currentPage][button.id.replace("top_"+currentPage+"_","")],dir,$(currentPage),subHiddens[currentPage]);
				currentSect[currentPage] = button.id.replace("top_"+currentPage+"_","").toInt();
				HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
			}
		});
	});
	$(topNavBack).addEvent("click",function(){
		if(subs[currentPage][currentSect[currentPage]-1])
		{
			shiftContent(subs[currentPage][currentSect[currentPage]],subs[currentPage][currentSect[currentPage]-1],"left",$(currentPage),subHiddens[currentPage]);
			currentSect[currentPage]--;
			HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
		}
		else
		{
			if($("left_"+currentPage).getPrevious()) nextPage = $("left_"+currentPage).getPrevious().id.replace("left_","");
			else nextPage = $(leftNavActive).getPrevious().id.replace("left_","");
			shiftContent(currentPage,nextPage,dir,wrapper,hidden);
			currentPage = nextPage;
			HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
		}
	});
	$(topNavNext).addEvent("click",function(){
		if(subs[currentPage][currentSect[currentPage]+1])
		{
			shiftContent(subs[currentPage][currentSect[currentPage]],subs[currentPage][currentSect[currentPage]+1],"right",$(currentPage),subHiddens[currentPage]);
			currentSect[currentPage]++;
			HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
		}
		else
		{
			if($("left_"+currentPage).getNext().id != leftNavActive) nextPage = $("left_"+currentPage).getNext().id.replace("left_","");
			else nextPage = $(leftNavContainer).getFirst("."+leftNavButtons).id.replace("left_","");
			shiftContent(currentPage,nextPage,dir,wrapper,hidden);
			currentPage = nextPage;
			HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
		}
	});
}

function createInternalLinks()
{
	internalLinks = $$("."+internalLinks);
	
	internalLinks.each(function(button){
		if(button.rel) var newLoc = button.rel;
		else if(button.alt) var newLoc = button.alt;
		button.style.cursor = "pointer";
		button.addEvent("click",function(){
			if(newLoc != currentPage)
			{
				if($("left_"+currentPage) && $("left_"+newLoc).offsetTop < $("left_"+currentPage).offsetTop) dir = "up";
				else dir = "down";
				shiftContent(currentPage,newLoc,dir,wrapper,hidden);
				currentPage = newLoc;
				HistoryManager.addState(currentPage +"/"+ currentSect[currentPage]);
			}
		});
	});

}
