if (document.all || document.getElementById){
	n=0;
	ie=1;
	fShow="visible";
	fHide="hidden";
} else if (document.layers) {
	n=1;
	ie=0;
	fShow="show";   
	fHide="hide";
}

//window.onerror=new Function("return true")
rightX = 0;
var timerid;

showToolbar();


function Menu(){
	this.bgColor = "#FFC000";
	if (ie) this.menuFont = "bold xx-small Verdana";
	if (n)  this.menuFont = "bold x-small Verdana";

	this.addItem    = addItem;
	this.addSubItem = addSubItem;
	this.showMenu   = showMenu;
	this.mainPaneBorder = 0;
	this.subMenuPaneBorder = 0;

	this.subMenuPaneWidth = 120;

	lastMenu = null;
	
	rightY = 0;
	leftY = 0;
	leftX = 0;

	HTMLstr = "";
	HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
	HTMLstr += "\n";
	if (ie) HTMLstr += "<div id='MainTable'>\n";
	HTMLstr += "<table width='100%' cellspacing='0' cellpadding='0'  border='"+this.mainPaneBorder+"'>\n";
	HTMLstr += "<tr>";
	if (n) HTMLstr += "<td> ";
	HTMLstr += "<!-- MAIN MENU STARTS -->\n";
	HTMLstr += "<!-- MAIN_MENU -->\n";
	HTMLstr += "<!-- MAIN MENU ENDS -->\n";
	if (n) HTMLstr += "</td>";
	HTMLstr += "</tr>\n";
	HTMLstr += "</table>\n";
	HTMLstr += "\n";
	HTMLstr += "<!-- SUB MENU STARTS -->\n";
	HTMLstr += "<!-- SUB_MENU -->\n";
	HTMLstr += "<!-- SUB MENU ENDS -->\n";
	HTMLstr += "\n";
	if (ie) HTMLstr+= "</div>\n";
	HTMLstr += "<!-- MENU PANE DECALARATION ENDS -->\n";
}

var timeidDisplaySub = null;
function displayTimeoutSubMenu(idItem) {
	timeidDisplaySub = setTimeout('displaySubMenu("' + idItem + '");', 500);
}

function addItem(idItem, text, hint, location, altLocation){
	var Lookup = "<!-- ITEM "+idItem+" -->";
	if (HTMLstr.indexOf(Lookup) != -1){
		alert(idParent + " bestaat al");
		return;
	}
	var MENUitem = "";
	MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
	if (n)
	{
		MENUitem += "<ilayer onmouseout=\"hideAllTimeOut()\" name="+idItem+">";
		MENUitem += "<a href='.' class=clsMenuItemNS onmouseover=\"displaySubMenu('"+idItem+"')\" onclick=\"return false;\">";
		MENUitem += "| ";
		MENUitem += text;
		MENUitem += "</a>";
		MENUitem += "</ilayer>";
	}
	if (ie){
		MENUitem += "<td valign='top' nowrap>\n";
		MENUitem += "<div onmouseover=\"hideAll();displayTimeoutSubMenu('"+idItem+"')\" onmouseout=\"hideAllTimeOut()\" id='"+idItem+"' style='position:relative; text-align:center; display:block; width:100%; font: "+this.menuFont+";'>\n";
		MENUitem += "<a ";
		MENUitem += "class=clsMenuItemIE ";
		if (hint != null)
			MENUitem += "title='"+hint+"' ";
		if (location != null){
			MENUitem += "href='"+location+"' ";
			MENUitem += "onmouseover=\"hideAll();displaySubMenu('"+idItem+"')\" ";

		} else {
			if (altLocation != null)
				MENUitem += "href='"+altLocation+"' ";
			else
				MENUitem += "href='.' ";
			
			MENUitem += "onclick=\"return false;\" "
		}
		MENUitem += ">";
		MENUitem += text;
		MENUitem += "</a>\n";
		MENUitem += "</div>\n";
		MENUitem += "</td>\n";
	}
	MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
	MENUitem += "<!-- MAIN_MENU -->\n";

	HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

function addSubItem(idParent, text, hint, location, target){
	var MENUitem = "";
	Lookup = "<!-- ITEM "+idParent+" -->";
	if (HTMLstr.indexOf(Lookup) == -1)
	{
		alert(idParent + " not found");
		return;
	}
	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
	if (HTMLstr.indexOf(Lookup) == -1){
		if (n)
		{
			MENUitem += "\n";
			MENUitem += "<layer onmouseout=\"hideAllTimeOut()\" onmouseover=\"displaySubMenu('"+idParent+"')\" id='"+idParent+"submenu' visibility=hide bgcolor='"+this.bgColor+"' >\n";
			MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+" >\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</layer>\n";
			MENUitem += "\n";
		}
		if (ie)
		{
			MENUitem += "\n";
			MENUitem += "<div onmouseout=\"hideAllTimeOut()\" onmouseover=\"displaySubMenu('"+idParent+"')\" id='"+idParent+"submenu' style='z-index:20; position:absolute; visibility: hidden; width: "+this.subMenuPaneWidth+"; font: "+this.menuFont+"; top: -300;'>\n";
			MENUitem += "<table cellspacing='0' cellpadding='0' class='clsSubMenuLineIE' 'bgcolor='"+this.bgColor+"' width="+this.subMenuPaneWidth+" style='z-index:20;'>\n";
			MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
			MENUitem += "</table>\n";
			MENUitem += "</div>\n";
			MENUitem += "\n";
		}
		MENUitem += "<!-- SUB_MENU -->\n";
		HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
	}

	Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
	if(target == null){
		target = '_self';
	}
	if (n)  MENUitem = "<tr><td><a class=clsSubMenuItemIE title='"+hint+"' href='"+location+"' target='"+target+"'>"+text+"</a></td></tr>\n";
	if (ie) MENUitem = "<tr><td><a class=clsSubMenuItemIE title='"+hint+"' href='"+location+"' target='"+target+"'>"+text+"</a></td></tr>\n";
	MENUitem += Lookup;
	HTMLstr = HTMLstr.replace(Lookup, MENUitem);

}

function showMenu(){
	//document.getElementById('mainContainer').offsetLeft;
	document.writeln(HTMLstr);
	UpdateIt();
}

function displaySubMenu(idMainMenu){
	var menu;
	var submenu;
	var idMainMenu;
	if (n){
		submenu = document.layers[idMainMenu+"submenu"];
		if (lastMenu != null && lastMenu != submenu) hideAll();
		submenu.left = document.layers[idMainMenu].pageX;
		submenu.top  = document.layers[idMainMenu].pageY + 25;
		submenu.visibility = fShow;

		leftX  = document.layers[idMainMenu+"submenu"].left;
		rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
		leftY  = document.layers[idMainMenu+"submenu"].top + document.layers[idMainMenu+"submenu"].clip.height;
		rightY = leftY;
	} else if (ie) {
		if(document.getElementById(idMainMenu+"submenu")){	
			//alert(idMainMenu);
			//menu = eval(idMainMenu);
			menu = document.getElementById(idMainMenu);			
			//submenu = eval(idMainMenu+"submenu.style");
			submenu = document.getElementById(idMainMenu+"submenu").style;
			document.getElementById(idMainMenu+"submenu").style.left = calculateSumOffset(menu, 'offsetLeft')-(document.getElementById('mainContainer').offsetLeft) + 'px';
			
			//document.getElementById(idMainMenu+"submenu").style.top  = menu.style.top+26;
			document.getElementById(idMainMenu+"submenu").style.visibility = fShow;			
			
			if (lastMenu != null && lastMenu != submenu) hideAll();
	
			leftX  = document.getElementById(idMainMenu+"submenu").style.posLeft;
			rightX = leftX + document.getElementById(idMainMenu+"submenu").offsetWidth;
	
			leftY  = document.getElementById(idMainMenu+"submenu").style.posTop + document.getElementById(idMainMenu+"submenu").offsetHeight;
			rightY = leftY;
			
			if(document.getElementById("menu_iframe")) {
				var iframe = document.getElementById("menu_iframe");
				//alert(document.getElementById(idMainMenu+"submenu").offsetTop + 150 + 'px');
				iframe.style.top = document.getElementById(idMainMenu+"submenu").offsetTop + document.getElementById("header").clientHeight + 'px';
				if(checkBrowser() == 0){
					iframe.style.left = calculateSumOffset(menu, 'offsetLeft') + 'px';
				} else {
					if(document.getElementById('fObject')){
						//iframe.style.left = calculateSumOffset(menu, 'offsetLeft') - 135 + 'px';
						iframe.style.left = calculateSumOffset(menu, 'offsetLeft')-(document.getElementById('mainContainer').offsetLeft) + 'px';
					} else {
						iframe.style.left = calculateSumOffset(menu, 'offsetLeft') + 'px';
						//iframe.style.left = calculateSumOffset(menu, 'offsetLeft')-(document.getElementById('mainContainer').offsetLeft) + 'px';
					}
				}
				iframe.style.width = document.getElementById(idMainMenu+"submenu").scrollWidth;
				iframe.style.height = document.getElementById(idMainMenu+"submenu").clientHeight;
				iframe.style.display = "inline";
			}
		}
	}
	lastMenu = submenu;
	if(timerid){
		clearTimeout(timerid);
	}
}

function hideAll(){
	if (lastMenu != null){
		lastMenu.visibility = fHide;
		lastMenu.left = 0;
	}
	if(document.getElementById("menu_iframe")) {
		var iframe = document.getElementById("menu_iframe");
		iframe.style.display = "none";
	}
}

function hideAllTimeOut(){
	clearTimeout(timeidDisplaySub);
	timerid = setTimeout("hideAll()", 500);	
}

function calculateSumOffset(idItem, offsetName){
	var totalOffset = 0;
	var item = eval('idItem');
	//alert(idItem.offsetLeft);
	do
	{
		totalOffset += eval('item.'+offsetName);
		//totalOffset += idItem.offsetLeft;
		item = eval('item.offsetParent');
	} while (item != null);
	
	return totalOffset;
}

function updateIt(e){
	if (ie){
		var x = window.event.clientX;
		var y = window.event.clientY;

		if (x > rightX || x < leftX) hideAll();
		else if (y > rightY) hideAll();
	}
	if (n){
		var x = e.pageX;
		var y = e.pageY;

		if (x > rightX || x < leftX) hideAll();
		else if (y > rightY) hideAll();
	}
}

if (document.all || document.getElementById){
	/*
	document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
	*/
}
if (document.layers){
	document.onmousedown=hideAll;
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=updateIt;
}

function showToolbar(){
	// AddItem(id, text, hint, location, alternativeLocation);
	// AddSubItem(idParent, text, hint, location);

	// Menu object
	menu = new Menu();
	
	// Hoofdmenu items
	menu.addItem("link1",		"Home",  				"Home",   				BASE_URL + "index.cfm", 							null);
	menu.addItem("link2",		"Actueel",				"Actueel",				null,												null);
	menu.addItem("link3",		"Occasionmarkt",  		"Occasionmarkt",	   	null,												null);
	menu.addItem("link4",		"CaraFans Forum",		"CaraFans Forum",   	null,												null);
	menu.addItem("link5",		"Reizen",				"Reizen",				null,												null);
	menu.addItem("link6",		"Kalender",				"Kalender",				null,												null);
	menu.addItem("link7",		"Links",				"Links",				null,												null);
	//menu.addItem("link8",		"Webshop",  			"Webshop",   			BASE_URL + "Content/webshop.cfm", 					null);
	menu.addItem("link9",		"Reactie",  			"Reactie",   			BASE_URL + "Content/Reactie/Reactie.cfm", 			null);

	// Submenu items
	menu.addSubItem("link2", 	"CaraFans nieuws",   						"CaraFans nieuws",  					BASE_URL + "Content/Caravannieuws/Caravannieuws.cfm",			null);
	menu.addSubItem("link2", 	"Dealer-acties",   							"Dealer-acties",  						BASE_URL + "Content/Actueel/Dealer-acties.cfm",				null);
	menu.addSubItem("link2", 	"Weer & Verkeer",   						"Weer & Verkeer",  						BASE_URL + "Content/Actueel/weer_file.cfm",					null);
	menu.addSubItem("link2", 	"Vacatures",   								"Vacatures",  							BASE_URL + "Content/Vacatures/Vacatures.cfm",				null);
	menu.addSubItem("link2", 	"Plaats vacature",   						"Plaats vacature",  					BASE_URL + "Content/Vacatures/plaats_vacature.cfm",			null);
	
	menu.addSubItem("link3", 	"Occasions",								"Occasions",  							BASE_URL + "Content/Campbank/occasions.cfm",				null);
	menu.addSubItem("link3", 	"Dealerzoeker",								"Dealerzoeker",  						BASE_URL + "Content/DealerZoeker/",							null);
	menu.addSubItem("link3", 	"Stallingzoeker",							"Stallingzoeker",  						BASE_URL + "Content/Reizen/stallers.cfm",							null);
	menu.addSubItem("link3", 	"Particulier aanbod",						"Particulier aanbod",  					BASE_URL + "Content/CaraForum/VoertuigAanbod.cfm",				null);
	menu.addSubItem("link3", 	"Bied uw caravan aan",						"Bied uw caravan aan",  				BASE_URL + "Content/Reizen/bied_caravan.cfm",					null);
	//menu.addSubItem("link3", 	"Motorverhuur",   							"Motorverhuur",  						BASE_URL + "Content/Reizen/motorverhuur.cfm",				null);
	menu.addSubItem("link3", 	"Geld & Verzekering",  						"Geld & Verzekering",  					BASE_URL + "Content/Geld/geld_verzek.cfm",					null);
	
	
	menu.addSubItem("link4",	"Forum",  									"Forum",								BASE_URL + "Content/CaraForum/",							null);
	if(bMemberLoggedIn == 'Y'){
		menu.addSubItem("link4",	"Uitloggen",  								"Uitloggen",   							BASE_URL + "Content/CaraForum/LogIn.cfm?logout",			null);
		menu.addSubItem("link4",	"Instellingen",								"Instellingen",							BASE_URL + "Content/CaraForum/Preferences.cfm",				null);
		menu.addSubItem("link4",	"Mijn Abonnementen",						"Mijn Abonnementen",					BASE_URL + "Content/CaraForum/MijnAbonnementen.cfm",		null);
		menu.addSubItem("link4",	"Nieuwe Berichten",							"Nieuwe Berichten",						BASE_URL + "Content/CaraForum/MissedMessages.cfm",			null);
	}else{
		menu.addSubItem("link4",	"Inloggen",  								"Inloggen",   							BASE_URL + "Content/CaraForum/LogIn.cfm",					null);
		menu.addSubItem("link4",	"Aanmelden",  								"Aanmelden",							BASE_URL + "Content/CaraForum/Register.cfm?Agree=Yes",		null);
		menu.addSubItem("link4",	"Actieve discussies",						"Actieve discussies",					BASE_URL + "Content/CaraForum/todaytopics.cfm",				null);
	}
	menu.addSubItem("link4",	"Zoeken",  									"Zoeken",								BASE_URL + "Content/CaraForum/Search.cfm",					null);



	//menu.addSubItem("link5", 	"Motorverhuur",   							"Motorverhuur",  						BASE_URL + "Content/Reizen/motorverhuur.cfm",				null);
	//menu.addSubItem("link5", 	"Gebruikerservaringen",   					"Gebruikerservaringen",  				BASE_URL + "Content/motorxp.cfm",							null);
	menu.addSubItem("link5", 	"Campings",   								"Campings",  							BASE_URL + "Content/Campings/index.cfm",					null);
	menu.addSubItem("link5", 	"Reisverslagen",   							"Reisverslagen",  						BASE_URL + "Content/Reizen/Reisverslagen/Reisverslagen.cfm",null);
	menu.addSubItem("link5", 	"Routeplanner",   							"Routeplanner",  						BASE_URL + "Route.cfm",										null);
	menu.addSubItem("link5", 	"Vakantie bestemming",  					"Vakantie bestemming",  				BASE_URL + "Content/Campings/index.cfm",					null);

	menu.addSubItem("link6", 	"Evenementen",   							"Evenementen",  						BASE_URL + "Content/Kalender/Evenementen/Evenementen.cfm",	null);
	//menu.addSubItem("link6", 	"Agenda's",   								"Agenda's",  							BASE_URL + "",												null); 

	menu.addSubItem("link7",	"Diversen", 								"Diversen",								BASE_URL + "Content/Links/Diversen.cfm",					null);
	menu.addSubItem("link7",	"Link naar ons", 							"Link naar ons",						BASE_URL + "Content/Links/links_naar_ons.cfm",				null);
	//menu.addSubItem("link7",	"Merkenclubs", 								"Merkenclub",							BASE_URL + "Content/Links/Merkenclubs.cfm",					null);
	//menu.addSubItem("link7",	"Regionale clubs", 							"Regionale clubs",						BASE_URL + "Content/Links/Regionaal.cfm",					null);
	//menu.addSubItem("link7",	"Wat Anders?", 								"Wat Anders?",							BASE_URL + "Content/Links/WatAnders.cfm",					null);

}

function UpdateIt(){
	if (document.all || document.getElementById){
		document.getElementById("MainTable").style.top = document.body.scrollTop;
		setTimeout("UpdateIt()", 200);
	}
}
