var 
	menuOrientation	= "v",
	OffsetX 	= 2,
	OffsetY 	= 0,
	itemSpacing 	= 0,  
	itemWidth 	= 221, 
	itemHeight 	= 23,  
	itemClass 	= "", 
	itemClassOver 	= "",
	labelClass 	= "sub-menu-label", 
	labelClassOver	= "sub-menu-label-over",
	itemColor	= "", 
	itemColorOver	= "", 
	itemImage	= "", 
	itemImageOver	= "", 
	itemAlign 	= "",
	transPNG	= "";

var	init_x, init_y;

var MENU = {
	'items' : [
		{
			'caption' 	: "Home", 
			'itemSpacing' 	: 2,  
			'itemImage' 	: "img/main-menu/home.gif", 
			'itemImageOver' : "img/main-menu/home-over.gif", 
			'open' : {
				'url' : "index.php",
				'target' : "_self"
			}
		} ,
		{
			'caption' 	: "Over ons", 
			'itemSpacing' 	: 2,  
			'itemImage' 	: "img/main-menu/over-ons.gif", 
			'itemImageOver' : "img/main-menu/over-ons-over.gif", 
			'open' : {
				'url' : "over-ons.html",
				'target' : "_self"
			}
		} ,
		{
			'caption' 	: "Lease producten", 
			'itemSpacing' 	: 2, 
			'itemImage'	: "img/main-menu/lease-producten.gif", 
			'itemImageOver'	: "img/main-menu/lease-producten-over.gif", 
			'open' : {
				'url' : "",
				'target' : "_self"
			}, 
			'popup' : {
				'items' : [
					{
						'caption' 	: "Full Operational Lease", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18,  
						'transPNG'	: "img/sub-menu-bg2.png", 
						'open' : {
							'url' : "full_operational.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "Netto Operational Lease", 
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18, 
						'transPNG'	: "img/sub-menu-bg1.png", 
						'open' : {
							'url' : "netto_operational.html",
							'target' : "_self"
						}
					} ,					
					{
						'caption' 	: "Flex Lease", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18,  
						'transPNG'	: "img/sub-menu-bg2.png", 
						'open' : {
							'url' : "flex.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "Short Lease", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18,  
						'transPNG'	: "img/sub-menu-bg2.png", 
						'open' : {
							'url' : "short.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 8,  
						'transPNG'	: "img/sub-menu-bg3.png"
					}
				]
			}
		} ,
		{
			'caption'	: "Klant", 
			'itemSpacing' 	: 2, 
			'itemImage'	: "img/main-menu/klant.gif", 
			'itemImageOver'	: "img/main-menu/klant-over.gif", 
			'open' : {
				'url' : "",
				'target' : "_self"
			}, 
			'popup' : {
				'items' : [
					{
						'caption' 	: "offerte", 
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18, 
						'transPNG'	: "img/sub-menu-bg1.png", 
						'open' : {
							'url' : "offerte.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "aanbieding", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18,  
						'transPNG'	: "img/sub-menu-bg2.png", 
						'open' : {
							'url' : "aanbieding.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 8,  
						'transPNG'	: "img/sub-menu-bg3.png"
					}
				]
			}
		} ,
		{
			'caption'	: "Berijder", 
			'itemSpacing' 	: 2, 
			'itemImage'	: "img/main-menu/berijder.gif", 
			'itemImageOver' : "img/main-menu/berijder-over.gif", 
			'open' : {
				'url' : "",
				'target' : "_self"
			}, 
			'popup' : {
				'items' : [
					{
						'caption' 	: "Offerte", 
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18, 
						'transPNG'	: "img/sub-menu-bg1.png", 
						'open' : {
							'url' : "offerte.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "Schademelding", 
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18, 
						'transPNG'	: "img/sub-menu-bg1.png", 
						'open' : {
							'url' : "schademelding.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "Groenekaart", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 18,  
						'transPNG'	: "img/sub-menu-bg2.png", 
						'open' : {
							'url' : "groenekaart.html",
							'target' : "_self"
						}
					} ,
					{
						'caption' 	: "", 
						'itemSpacing' 	: 0,  
						'itemWidth' 	: 150, 
						'itemHeight' 	: 8,  
						'transPNG'	: "img/sub-menu-bg3.png"
					}
				]
			}
		} ,
		{
			'caption'	: "Verhuur", 
			'itemSpacing' 	: 2, 
			'itemImage' 	: "img/main-menu/verhuur.gif", 
			'itemImageOver'	: "img/main-menu/verhuur-over.gif", 
			'open' : {
				'url' : "verhuur.html",
				'target' : "_self"
			}
		} ,
		{
			'caption'	: "Sponsoring", 
			'itemSpacing' 	: 2, 
			'itemImage'	: "img/main-menu/sponsoring.gif", 
			'itemImageOver'	: "img/main-menu/sponsoring-over.gif", 
			'open' : {
				'url' : "sponsoring.html",
				'target' : "_self"
			}
		}, 
		{
			'caption'	: "Contact", 
			'itemSpacing' 	: 2, 
			'itemImage'	: "img/main-menu/contact.gif", 
			'itemImageOver'	: "img/main-menu/contact-over.gif", 
			'open' : {
				'url' : "contact.html",
				'target' : "_self"
			}
		}
	]
};




var menu_items = [];
var killer = null;

function get_element(id)
{
	return document.getElementById ? document.getElementById(id) : document.all[id];
}

function menu_item(caption, pos, align, size, class1, class2, lclass1, lclass2, image1, image2, color1, color2, transPNG, parent, url, target, z)
{

	this.caption = caption;
	this.id = menu_items.length;
	menu_items[this.id] = this;
	this.parent = parent;
	this.pos = pos;
	this.align = align;
	this.size = size;
	this.class1 = class1;
	this.class2 = class2;
	this.lclass1 = lclass1;
	this.lclass2 = lclass2;
	this.color1 = color1;
	this.color2 = color2;
	this.image1 = image1;
	this.image2 = image2;
	this.url = url;
	this.target = target;
	this.transpng = transPNG;

	if (image1 != '' && image2 != '')
	{
		this.imageitem = true;
	}
	else
	{
		this.imageitem = false;
	}

	if (this.imageitem)
	{
		document.write('<div id="div' + this.id + '" style="position:absolute; left:' + pos[0] + 'px; top:' + pos[1] + 'px; z-index:' + z + '; visibility:hidden"><table width="' + size[0] + '" border="0" cellpadding="0" cellspacing="0"><tr><td id="cell' + this.id + '" width="' + size[0] + '" height="' + size[1] + '"');

		if (align != '')
		{
			document.write(' align="' + align + '"');
		}

		document.write(' onmouseover="menu_mouseover(' + this.id + ')" onmouseout="menu_mouseout(' + this.id + ')" onclick="menu_click(' + this.id + ')">');

		document.write('<img src="' + image1 + '" alt="' + caption + '" id="img' + this.id + '" width="' + size[0] + '" height="' + size[1] + '" />');

		document.write('</td></tr></table></div>');

		this.img = get_element('img' + this.id);

		this.overimg = new Image;
		this.overimg.src = image2;
	}
	else
	{
		if (this.transpng != '')
		{
			if (navigator.appName=="Netscape" || navigator.userAgent.indexOf("Opera")!=-1)
			{
				document.write('<div id="div' + this.id + '" style="position:absolute; left:' + pos[0] + 'px; top:' + pos[1] + 'px; z-index:' + z + '; visibility:hidden;"><table width="' + size[0] + '" border="0" cellpadding="0" cellspacing="0"><tr><td id="cell' + this.id + '" width="' + size[0] + '" height="' + size[1] + '" background="' + this.transpng + '"');
			}
			else
			{
				document.write('<div id="div' + this.id + '" style="position:absolute; left:' + pos[0] + 'px; top:' + pos[1] + 'px; z-index:' + z + '; visibility:hidden;  filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + this.transpng + '\', sizingMethod=\'scale\');" onmouseover="menu_mouseover(' + this.id + ')" onmouseout="menu_mouseout(' + this.id + ')" onclick="menu_click(' + this.id + ')"><table width="' + size[0] + '" border="0" cellpadding="0" cellspacing="0"><tr><td id="cell' + this.id + '" width="' + size[0] + '" height="' + size[1] + '"');
			}
		}

		if (class1 != '')
		{
			document.write(' class="' + class1 + '"');
		}

		if (color1 != '')
		{
			document.write(' bgcolor="' + color1 + '"');
		}

		if (align != '')
		{
			document.write(' align="' + align + '"');
		}

		document.write(' onmouseover="menu_mouseover(' + this.id + ')" onmouseout="menu_mouseout(' + this.id + ')" onclick="menu_click(' + this.id + ')">');

		document.write('<div');

		if (lclass1 != '')
		{
			document.write(' class="' + lclass1 + '"');
		}

		document.write(' id="label' + this.id + '">' + caption);

		document.write('</div></td></tr></table></div>');

		this.cell = get_element('cell' + this.id);
		this.label = get_element('label' + this.id);
	}

	this.div = get_element('div' + this.id);

	this.popup = [];
}

menu_item.prototype.add_child = function(child_id)
{
	this.popup[this.popup.length] = child_id;
}

menu_item.prototype.show = function()
{
	this.div.style.visibility = "visible";
}

menu_item.prototype.hide = function()
{
	this.div.style.visibility = "hidden";
}

menu_item.prototype.move = function(x,y)
{
	this.pos[0] += x;
	this.pos[1] += y;
	this.div.style.left=this.pos[0] + 'px';
	this.div.style.top=this.pos[1] + 'px';
}

menu_item.prototype.select = function()
{
	if (this.imageitem)
	{
		this.img.src = this.image2;	
	}
	else
	{
		this.cell.className = this.class2;	
		this.cell.bgColor = this.color2;
		this.label.className = this.lclass2;
	}
	for (var i in this.popup)
	{
		menu_items[this.popup[i]].show();
		menu_items[this.popup[i]].unselect();
	}
}

menu_item.prototype.unselect = function()
{
	for (var i in this.popup)
	{
		menu_items[this.popup[i]].unselect();
		menu_items[this.popup[i]].hide();
	}
	if (this.imageitem)
	{
		this.img.src = this.image1;
	}
	else
	{	
		this.cell.className = this.class1;
		this.cell.bgColor = this.color1;
		this.label.className = this.lclass1;
	}
}

function menu_mouseover(id)
{
	if (killer != null) clearTimeout(killer);
	killer = null;
	var p = menu_items[id].parent;
	for (var i in menu_items)
	{
		if (menu_items[i].parent == p)
		{
			if (i == id) menu_items[id].select();
			else menu_items[i].unselect();
		}
	}
}

function collapse()
{
	for (var i in menu_items)
	{
		if (menu_items[i].parent == -1)
		{
			menu_items[i].unselect();
		}
	}
}

function menu_mouseout(id)
{
	killer = setTimeout("collapse()", 100);
}

function menu_click(id)
{
	if (menu_items[id].url!="")
	{
		var target = (menu_items[id].target!="")? menu_items[id].target : "_self";
		window.open(menu_items[id].url, target);
	}
}

function create_submenu(sub, x, y, z)
{
	var parent = menu_items.length - 1;

	var orientation = (sub.menuOrientation)? sub.menuOrientation : menuOrientation;

	for (var i in sub.items)
	{


		var item_width 		= (sub.items[i].itemWidth)? sub.items[i].itemWidth : itemWidth;
		var item_height		= (sub.items[i].itemHeight)? sub.items[i].itemHeight : itemHeight;
		var item_spacing	= (sub.items[i].itemSpacing)? sub.items[i].itemSpacing : itemSpacing;

		var item_class1		= (sub.items[i].itemClass)? sub.items[i].itemClass : itemClass;
		var item_class2		= (sub.items[i].itemClassOver)? sub.items[i].itemClassOver : itemClassOver;

		var label_class1	= (sub.items[i].labelClass)? sub.items[i].labelClass : labelClass;
		var label_class2	= (sub.items[i].labelClassOver)? sub.items[i].labelClassOver : labelClassOver;

		var item_color1		= (sub.items[i].itemColor)? sub.items[i].itemColor : itemColor;
		var item_color2		= (sub.items[i].itemColorOver)? sub.items[i].itemColorOver : itemColorOver;

		var item_image1		= (sub.items[i].itemImage)? sub.items[i].itemImage : itemImage;
		var item_image2		= (sub.items[i].itemImageOver)? sub.items[i].itemImageOver : itemImageOver;

		var item_align		= (sub.items[i].itemAlign)? sub.items[i].itemAlign : itemAlign;

		var item_transPNG	= (sub.items[i].transPNG)? sub.items[i].transPNG : transPNG;

		var pos = [x,y];

		var size = [item_width,item_height];

		var url = (sub.items[i].open)? sub.items[i].open.url : "";

		var target = (sub.items[i].open)? sub.items[i].open.target : "";

		var new_item = new menu_item(sub.items[i].caption, pos, item_align, size, item_class1, item_class2, label_class1, label_class2, item_image1, item_image2, item_color1, item_color2, item_transPNG, parent, url, target, z);

		if (parent >- 1)
		{
			menu_items[parent].add_child(new_item.id);
		}
		else
		{
			new_item.show();
		}

		if (orientation.toLowerCase() == "vertical" || orientation.toLowerCase() == "v")
		{
			if (sub.items[i].popup) create_submenu(sub.items[i].popup, x + item_width + OffsetX, y, z+1);
			y += item_height + item_spacing;
		}
		else
		if (orientation.toLowerCase() == "horisontal" || orientation.toLowerCase() == "h")
		{
			if (sub.items[i].popup) create_submenu(sub.items[i].popup, x, y + item_height + OffsetY, z+1);
			x += item_width + item_spacing;
		}
	}
}


function menu_init(x, y)
{
	init_x = x;
	init_y = y;
	create_submenu(MENU, x, y, 4);
}

function menu_move(x, y)
{
	var dx = x - init_x;
	var dy = y - init_y;
	init_x += dx;
	init_y += dy;
	for (var i in menu_items)
	{
		menu_items[i].move(dx,dy);
		if (menu_items[i].parent==-1) menu_items[i].show();
	}
}
