function toggleDealerArea(on){
	if (on == 'login'){
		document.getElementById('loginLightbox').style.display = 'block';
		document.getElementById('signUpLightbox').style.display = 'none';
		document.getElementById('passwordLightbox').style.display ='none';
	}
	else if (on == 'signup'){
		document.getElementById('loginLightbox').style.display = 'none';
		document.getElementById('signUpLightbox').style.display = 'block';
		document.getElementById('passwordLightbox').style.display ='none';
	}
	else if (on == 'password'){
		document.getElementById('loginLightbox').style.display = 'none';
		document.getElementById('signUpLightbox').style.display = 'none';
		document.getElementById('passwordLightbox').style.display ='block';
	}
	else{
		document.getElementById('loginLightbox').style.display = 'none';
		document.getElementById('signUpLightbox').style.display = 'none';
		document.getElementById('passwordLightbox').style.display ='none';
	}
}


function centerDropdowns(){
	var	topLevel = $$('.menu');
	
	for (i=0;i<topLevel.length;i++){
		topLevel[i].getElements('li').each(function(el){
			var listRef = el.getElement('.sub-menu');
			
			//Only calculate new margin if link has a sub-menu
			if(listRef != null){
				//Remove top border from first sub-menu entry
				listRef.getElement('.menu-item').setStyle('background','none');
	
				//Center sub-menu on mouseover
				el.addEvent('mouseenter',function(){
					var linkRef = el.getElement('a');
					var linkWidth = linkRef.getStyle('width').replace('px','');
					var menuWidth = listRef.getStyle('width').replace('px','');
					
					//20px subtracted from width for link padding
					var width = parseInt((menuWidth - linkWidth)/2)-10;
					
					listRef.setStyle('marginLeft',-width+'px');
				});
				addUpArrow(listRef);
			}
		});
	}
}


/*
 * Adds a small arrow to the top of the submenu which is provided
 * as an element. The submenu also receives a top margin to 
 * compensate for the required space of the arrow.
 *
 * @param subMenu expects a submenu of the the main menu as an
 * element
 */
function addUpArrow(subMenu){
	//Push all sub-menus 12px down to make room for arrow
	subMenu.setStyle('marginTop','12px');
	
	//Create arrow
	var arrow = document.createElement('span');
	arrow.setAttribute('class','navArrow');

	//Add arrow to sub menu
	subMenu.appendChild(arrow);
}

// JavaScript Document
window.addEvent('domready',function(){
	centerDropdowns();
});
