var defaultFillColor = "F0EEE2";
var defaultFontColor = "6E6E6D";
var defaultSection = null;
var currentSection = null;
var sections = new Array();

// Load Initial Values When The Document Loads

// Load the array
sections[0] = new Array();
sections[0].menuName = "Biba";
sections[0].lineColor = "0071BB";
sections[0].fillColor = "0071BB";
sections[0].timer = null;
sections[0].count = null;
sections[0].isActive = false;
sections[1] = new Array();
sections[1].menuName = "Food";
sections[1].lineColor = "828257";
sections[1].fillColor = "999966";
sections[1].timer = null;
sections[1].count = null;
sections[1].isActive = false;
sections[2] = new Array();
sections[2].menuName = "Wine";
sections[2].lineColor = "6F0601";
sections[2].fillColor = "98100A";
sections[2].timer = null;
sections[2].count = null;
sections[2].isActive = false;
sections[3] = new Array();
sections[3].menuName = "Gallery";
sections[3].lineColor = "D9570B";
sections[3].fillColor = "F46A16";
sections[3].timer = null;
sections[3].count = null;
sections[3].isActive = false;
sections[4] = new Array();
sections[4].menuName = "contatti";
sections[4].lineColor = "6889A8";
sections[4].fillColor = "9AB0C5";
sections[4].timer = null;
sections[4].count = null;
sections[4].isActive = false;

function navInit() {
	// Loop over the sections
	for (i = 0; i < sections.length; i++) {
		if (document.getElementById) {
			document.getElementById("nav" + sections[i].menuName + "Bottom").style.backgroundColor = sections[i].lineColor;
			document.getElementById("nav" + sections[i].menuName + "BottomLine").style.backgroundColor = sections[i].lineColor;
			document.getElementById("subNav" + sections[i].menuName).style.visibility = "hidden";
		} else if (document.all) {
			document.all["nav" + sections[i].menuName + "Bottom"].style.backgroundColor = sections[i].lineColor;
			document.all["nav" + sections[i].menuName + "BottomLine"].style.backgroundColor = sections[i].lineColor;
		} else if (document.layers) {
			document.layers["nav" + sections[i].menuName + "Bottom"].style.backgroundColor = sections[i].lineColor;
			document.layers["nav" + sections[i].menuName + "BottomLine"].style.backgroundColor = sections[i].lineColor;
		}
		
		if (sections[i].menuName.toUpperCase() == navSection.toUpperCase()) {
			defaultSection = i;
		}
	}
	navChange(defaultSection);
}

function navClear(navIndex) {
	// Loop over the sections
	for (i = 0; i < sections.length; i++) {
		if (sections[i].isActive && i != navIndex) {
			if (navIndex != null || i != defaultSection) {
				if (sections[i].timer != null) {
					clearInterval(sections[i].timer);
				}
				sections[i].count = 5;
				
				if (document.getElementById) {
					document.getElementById("nav" + sections[i].menuName + "Top").style.backgroundColor = "F0EEE2";
					document.getElementById("subNav" + sections[i].menuName).style.visibility = "hidden";
				} else if (document.all) {
					document.all["nav" + sections[i].menuName + "Top"].style.backgroundColor = "F0EEE2";
					document.all["subNav" + sections[i].menuName].style.visibility = "hidden";
				} else if (document.layers) {
					document.layers["nav" + sections[i].menuName + "Top"].style.backgroundColor = "F0EEE2";
					document.layers["subNav" + sections[i].menuName].style.visibility = "hidden";
				}
				//document.getElementById("nav" + sections[i].menuName + "Top").style.backgroundColor = "F0EEE2";
				//document.getElementById("subNav" + sections[i].menuName).style.visibility = "hidden";
				
				sections[i].timer = setInterval("changeCellDown(" + i + ")", 3);
			}
		}
		
		/*
		if (sections[i].isActive && i != navIndex) {
			if (sections[i].timer != null) {
				clearInterval(sections[i].timer);
			}
			sections[i].count = 5;
			document.getElementById("nav" + sections[i].menuName + "Top").style.backgroundColor = "F0EEE2";
			document.getElementById("subNav" + sections[i].menuName).style.visibility = "hidden";
			sections[i].timer = setInterval("changeCellDown(" + i + ")", 3);
		}
		*/
	}
	
	if (navIndex == null && defaultSection != null && !sections[defaultSection].isActive) {
		navChange(defaultSection);
	}
}

function navChange(navIndex) {
	if (!sections[navIndex].isActive) {
		sections[navIndex].isActive = true;
		if (sections[navIndex].timer != null) {
			clearInterval(sections[navIndex].timer);
		}
		sections[navIndex].count = 1;
		if (document.getElementById) {
			document.getElementById("nav" + sections[navIndex].menuName + "Bottom").style.backgroundColor = sections[navIndex].fillColor;
		} else if (document.all) {
			document.all["nav" + sections[navIndex].menuName + "Bottom"].style.backgroundColor = sections[navIndex].fillColor;
		} else if (document.layers) {
			document.layers["nav" + sections[navIndex].menuName + "Bottom"].style.backgroundColor = sections[navIndex].fillColor;
		}
		//document.getElementById("nav" + sections[navIndex].menuName + "Bottom").style.backgroundColor = sections[navIndex].fillColor;
		sections[navIndex].timer = setInterval("changeCellUp(" + navIndex + ")", 3);
		
		// Clear the other items
		navClear(navIndex);
	}
}

function changeCellUp(navIndex) {
	if (document.getElementById) {
		document.getElementById("nav" + sections[navIndex].menuName + sections[navIndex].count).style.backgroundColor = sections[navIndex].fillColor;
		document.getElementById("nav" + sections[navIndex].menuName + sections[navIndex].count).style.color = "FFFFFF";
	} else if (document.all) {
		document.all["nav" + sections[navIndex].menuName + sections[navIndex].count].style.backgroundColor = sections[navIndex].fillColor;
		document.all["nav" + sections[navIndex].menuName + sections[navIndex].count].style.color = "FFFFFF";
	} else if (document.layers) {
		document.layers["nav" + sections[navIndex].menuName + sections[navIndex].count].style.backgroundColor = sections[navIndex].fillColor;
		document.layers["nav" + sections[navIndex].menuName + sections[navIndex].count].style.color = "FFFFFF";
	}
	
	if (sections[navIndex].count < 5) {
		sections[navIndex].count++;
	} else {
		clearInterval(sections[navIndex].timer);
		if (document.getElementById) {
			document.getElementById("nav" + sections[navIndex].menuName + "Top").style.backgroundColor = sections[navIndex].lineColor;
		} else if (document.all) {
			document.all["nav" + sections[navIndex].menuName + "Top"].style.backgroundColor = sections[navIndex].lineColor;
		} else if (document.layers) {
			document.layers["nav" + sections[navIndex].menuName + "Top"].style.backgroundColor = sections[navIndex].lineColor;
		}
		document.getElementById("subNav" + sections[navIndex].menuName).style.visibility = "visible";
		sections[navIndex].count = 1;
	}
}

function changeCellDown(navIndex) {
	if (document.getElementById) {
		document.getElementById("nav" + sections[navIndex].menuName + sections[navIndex].count).style.backgroundColor = defaultFillColor;
		document.getElementById("nav" + sections[navIndex].menuName + sections[navIndex].count).style.color = defaultFontColor;
	} else if (document.all) {
		document.all["nav" + sections[navIndex].menuName + sections[navIndex].count].style.backgroundColor = defaultFillColor;
		document.all["nav" + sections[navIndex].menuName + sections[navIndex].count].style.color = defaultFontColor;
	} else if (document.layers) {
		document.layers["nav" + sections[navIndex].menuName + sections[navIndex].count].style.backgroundColor = defaultFillColor;
		document.layers["nav" + sections[navIndex].menuName + sections[navIndex].count].style.color = defaultFontColor;
	}
	
	if (sections[navIndex].count > 1) {
		sections[navIndex].count--;
	} else {
		clearInterval(sections[navIndex].timer);
		if (document.getElementById) {
			document.getElementById("nav" + sections[navIndex].menuName + "Bottom").style.backgroundColor = sections[navIndex].lineColor;
		} else if (document.all) {
			document.all["nav" + sections[navIndex].menuName + "Bottom"].style.backgroundColor = sections[navIndex].lineColor;
		} else if (document.layers) {
			document.layers["nav" + sections[navIndex].menuName + "Bottom"].style.backgroundColor = sections[navIndex].lineColor;
		}
		sections[navIndex].isActive = false;
		sections[navIndex].count = 1;
	}
}
