var openMenuId = false;
var idOfElementToScrollToOnClose = 'projectsNavigationMenu';
var projectsScroller = new scrollHandler();

/*
* action: either open or close.
*/
function toggleTopProjectData(action) {
	
	var expandLinkItem = document.getElementById('openTopLink');
	var contractLinkItem = document.getElementById('closeTopLink');
	
	if(action == 'close') {
		
		expandLinkItem.className = 'imHidden';
		contractLinkItem.className = 'hideMe'; // Lets indicate that the link wants to be hidden
		//contractLinkItem.style.display = 'none'; // Hide the clicked link immediately
		
		// Hide the flash elements
		this.toggleFlashElements('hidden');
		
		// If the element we want to scroll to is above the current y pos of the body, meaning that
		// it isnt visible
		if(parseInt(getYPos(document.getElementById(idOfElementToScrollToOnClose))) < getYOfBodyTop()) {
		
			var myCallbackFuncs = new Array();
			myCallbackFuncs[0] = 'onProjectClose';
			
			projectsScroller.setCallbackFuncs(myCallbackFuncs);
			projectsScroller.scrollToElement(idOfElementToScrollToOnClose);
			
		} else { // Id of element to scroll to is visible
			
			this.onProjectClose();
			
		}
		
	} else { // Open
		
		// Hide the flash elements
		this.toggleFlashElements('hidden');
		
		contractLinkItem.className = 'imHidden';
		expandLinkItem.className = 'hideMe'; // Lets indicate that the link wants to be hidden
		expandLinkItem.style.visibility = 'hidden'; // Hide the clicked link immediately
		
		var myCallbackFuncs = new Array();
		myCallbackFuncs[0] = 'toggleTopProjectLinks';
		myCallbackFuncs[1] = 'showFlashElements';
		
		var heightShifter = new elementHeightShifter('hideableTopContent', element('hideableTopContentInner').getH(), 'open', scrollTime, myCallbackFuncs, false);
		heightShifter.start();		

	}

}

/**
*
*/
this.showFlashElements = function() {
	
	this.toggleFlashElements('visible');	
	
}

/**
*
*/
this.toggleFlashElements = function(visibilityVal) {
	
	var flashWrapperElements;
	var flashWrapperElementsLength;
	var classNameToSearchFor = 'visibleEtypesFlashWrapper';
	var classNameToChangeTo = 'hiddenEtypesFlashWrapper';
	
	
	// If we are showing the flash elements
	if(visibilityVal == 'visible') {
			
		// Swap the value sof the classname variables
		var tmpClassNameToChangeTo = classNameToChangeTo;
		classNameToChangeTo = classNameToSearchFor;
		classNameToSearchFor = tmpClassNameToChangeTo;
		
	}
	
	// Get the flashelements and count them
	flashWrapperElements = getElementsByClassName(classNameToSearchFor, 'div', document.getElementById('hideableTopContent'));	
	flashWrapperElementsLength = flashWrapperElements.length;
	
	// Loop the elements
	for(var i = 0; i < flashWrapperElementsLength; i++) {
		
		//flashWrapperElements[i].childNodes[0].style.visibility = visibilityVal; 
		flashWrapperElements[i].className = classNameToChangeTo;
		
	}
	
}

/**
*
*/
function onProjectClose() {
	
	var myCallbackFuncs = new Array();
	myCallbackFuncs[0] = 'toggleTopProjectLinks';
	
	var heightShifter = new elementHeightShifter('hideableTopContent', 0, 'close', scrollTime, myCallbackFuncs, false);
	heightShifter.start();	
	
}

/**
*
*/
function toggleTopProjectLinks(force) {
	
	var expandLinkItem = document.getElementById('openTopLink');
	var contractLinkItem = document.getElementById('closeTopLink');
	
	if(force == 'showOpen' || (force != 'showClose' && contractLinkItem.className == 'hideMe')) {
		
		expandLinkItem.style.visibility = 'visible';
		//contractLinkItem.style.display = 'none';		
		
	} else {
		
		expandLinkItem.style.visibility = 'hidden';
		//contractLinkItem.style.visibility = 'visible';		
		
	}
	
}

/**
*
*/
function closeAllOpenDropMenus() {
	
	if(openMenuId != false) {
		
		// "Close" the menu
		document.getElementById(openMenuId).style.display = "none";
		
		document.getElementById(openMenuId + '_Toggler').style.backgroundColor = '#34302b';
		document.getElementById(openMenuId + '_Toggler').style.backgroundImage = 'url(/images/projectsDropDownArrow.gif)';
		document.getElementById(openMenuId + '_Toggler').style.color = '#b2a9a2';		
		
	}
	
	openMenuId = false;
	
}

/**
*
*/
function toggleDropMenu(menuElmId) {	
	
	// If the menu is open
	if(document.getElementById(menuElmId).style.display == 'block') {
		
		setDisplay(menuElmId, 'none');
		openMenuId = false;
		
	} else { // Menu is closed

		closeAllOpenDropMenus();
		
		document.getElementById(menuElmId + '_Toggler').style.backgroundColor = '#FFFFFF';
		document.getElementById(menuElmId + '_Toggler').style.backgroundImage = 'none'; //url(/images/projectsDropDownArrowHover.gif)';
		document.getElementById(menuElmId + '_Toggler').style.color = '#5e5956';
	
		openMenuId = menuElmId;
		
		setDisplay(menuElmId, 'block');
	
	}

}

var projectsIdOfElementToScrollTo;

function goToHiddenContentAnchor(id) {

	var expandLinkItem = document.getElementById('openTopLink');
	var contractLinkItem = document.getElementById('closeTopLink');		
	
	// Only do this if the dataelement is closed
	if(expandLinkItem.style.visibility != 'hidden') {
	
		projectsIdOfElementToScrollTo = id;
		
		//showFlashElements();
	
		// Show the entire content of the hidden div
		//document.getElementById('hideableTopContent').style.height = element('hideableTopContentInner').getH() + 'px';
		
		contractLinkItem.className = 'imHidden';
		expandLinkItem.className = 'hideMe'; // Lets indicate that the link wants to be hidden
		expandLinkItem.style.visibility = 'hidden'; // Hide the clicked link immediately
		
		var myCallbackFuncs = new Array();
		myCallbackFuncs[0] = 'toggleTopProjectLinks';
		myCallbackFuncs[1] = 'showFlashElements';
		myCallbackFuncs[2] = 'scrollToElementCallback';
		
		var heightShifter = new elementHeightShifter('hideableTopContent', element('hideableTopContentInner').getH(), 'open', scrollTime, myCallbackFuncs, false);
		heightShifter.start();	

	} else {
		
		projectsScroller.scrollToElement(id);

	}
	
}

function scrollToElementCallback() {
	
	// Wait for it
	setTimeout('projectsScroller.scrollToElement(projectsIdOfElementToScrollTo)', 200);
}