var imgArrowGrey	= new Image();
var imgArrowGreyDown= new Image();
var imgArrowRed		= new Image();
var imgArrowRedDown	= new Image();
imgArrowGrey.src	= '/images/small_arrow_grey.gif';
imgArrowGreyDown.src= '/images/small_arrow_grey_down.gif';
imgArrowRed.src		= '/images/small_arrow_darkred.gif';
imgArrowRedDown.src	= '/images/small_arrow_darkred_down.gif';

function toggleMenuBlock(menuItem,menuIndex){
	var menuBlock = document.getElementById('expSection' + menuIndex);
	var menuBlockHeaderImage = document.getElementById('expSectionImage' + menuIndex);

	if ( menuBlock.style.display == '' ) {
		menuBlock.style.display = 'none';
		menuBlockHeaderImage.src = imgArrowRed.src;
		menuItem.setAttribute('expanded','no');
	} else {
		menuBlock.style.display = '';
		menuBlockHeaderImage.src = imgArrowRedDown.src;
		menuItem.setAttribute('expanded','yes');
	}
}

function menuBlockHeaderClick(newLocation){
	if (document.location.pathname+document.location.search!=newLocation) document.location.href=newLocation;
}

function menuItemMouseOver(menuItem){
	//if (menuItem.className.indexOf("active")==-1 && menuItem.getAttribute('expanded')!='yes'){
	if (menuItem.className.indexOf("active")==-1){	
		var cells = menuItem.getElementsByTagName('td');

		if (!cells) return;
		if ( cells.length>=2 ){
			cells[0].className = 'mediumBlueBackground';
			cells[1].className = 'menuItem hover lightBlueBackground';

			var menuLink = cells[1].getElementsByTagName('a');
			if (menuLink) {
				if (menuLink.length){
					if ( menuLink[0].className ) {
						menuLink[0].className = 'menuItem hover';
						menuLink[0].style.fontWeight = '900';
						menuLink[0].style.color = '#6E1C1C';
					}
				}
			}
		}

		if (menuItem.className.indexOf("menuBlockHeader")!=-1){
			var imgArrow = cells[0].getElementsByTagName('img');
			if ( imgArrow ){
				if (imgArrow.length){
					if ( imgArrow[0].src ) {
						if ( menuItem.getAttribute('expanded')!='yes' ){
							imgArrow[0].src = imgArrowRed.src;
						} else {
							imgArrow[0].src = imgArrowRedDown.src;
						}
					}
				}
			}
		}
	}
}

function menuItemMouseOut(menuItem){
	//if (menuItem.className.indexOf("active")==-1 && menuItem.getAttribute('expanded')!='yes'){
	if (menuItem.className.indexOf("active")==-1){
		var cells = menuItem.getElementsByTagName('td');
		if (!cells) return;
		if ( cells.length>=2 ){
			cells[0].className = '';
			cells[1].className = 'menuItem';

			var menuLink = cells[1].getElementsByTagName('a');
			if ( menuLink.length ) {
				menuLink[0].className = 'menuItem';
				menuLink[0].style.fontWeight = '100';
				menuLink[0].style.color = '#575757';
			}
		}

		if (menuItem.className.indexOf("menuBlockHeader")!=-1){
			var imgArrow = cells[0].getElementsByTagName('img');
			if ( imgArrow ){
				if (imgArrow.length){
					if ( imgArrow[0].src ) {
						if ( menuItem.getAttribute('expanded')!='yes' ){
							imgArrow[0].src = imgArrowGrey.src;
						} else {
							imgArrow[0].src = imgArrowGreyDown.src;
						}
					}
				}
			}
		}
	}
}

function menuItemClick(menuItem){
	if (menuItem.className.indexOf("active")==-1){
		var cells = menuItem.getElementsByTagName('td');
		if (!cells) return;
		if ( cells.length==2 ){
			var menuLink = cells[1].getElementsByTagName('a');
			if ( menuLink.length ) document.location.href = menuLink[0].href;
		}
	}
}

function menuSubItemMouseOver(menuItem){
	if (menuItem.className.indexOf("active")==-1){
		var cells = menuItem.getElementsByTagName('td');

		if (!cells) return;
		if ( cells.length==1 ){
			cells[0].className = 'subMenuItem hover';

			var menuLink = cells[0].getElementsByTagName('a');
			if ( menuLink.length ) {
				menuLink[0].style.fontWeight = '900';
			}
		}
	
		menuItem.style.pointer = 'cursor';
	}
}

function menuSubItemMouseOut(menuItem){
	if (menuItem.className.indexOf("active")==-1){
		var cells = menuItem.getElementsByTagName('td');

		if (!cells) return;
		if ( cells.length==1 ){
			cells[0].className = 'subMenuItem';
			
			var menuLink = cells[0].getElementsByTagName('a');
			if ( menuLink.length ) {
				menuLink[0].style.fontWeight = '100';
			}
		}
	}
}

function menuSubItemClick(menuItem){
	if (menuItem.className.indexOf("active")==-1){
		var cells = menuItem.getElementsByTagName('td');

		if (!cells) return;
		if ( cells.length==1 ){
			var menuLink = cells[0].getElementsByTagName('a');
			if ( menuLink.length ) document.location.href = menuLink[0].href;
		}
	}
}
