function SlidingMenu(admin) {
	
	this.init = function() {
		if(!me.subMenuDiv) {
			me.subMenuDiv = document.createElement("div");
			me.subMenuDiv.className = "subMenu";
		}
		if(!me.subMenuDiv2) {
			me.subMenuDiv2 = document.createElement("div");
			me.subMenuDiv2.className = "subMenu";
		}
		if(me.admin) {
			SlidingMenu.menuItems[SlidingMenu.menuItems.length] = {
				"name": "admin",
				"type": "href",
				"url": "/admin/index.html",
				"subMenu": new Array(
					{
						"name":"users",
						"type": "href",
						"url": "/admin/users.html"
					},
					{
						"name":"photo galleries",
						"type": "href",
						"url": "/admin/gallery.html"
					},
					{
						"name":"specials",
						"type": "href",
						"url": "/admin/inventory.html"
					},
					{
						"name":"faqs",
						"type": "href",
						"url": "/admin/faqs.html"
					},
					{
						"name":"content",
						"type": "href",
						"url": "/admin/content.html"
					},
					{
						"name":"log out",
						"type": "href",
						"url": "/admin/logout.html"
					}
				)
			}
		}		
		me.drawMenu();
	};
	
	this.drawMenu = function() {
		
		var ul = document.createElement("ul");
		me.baseNode.appendChild(ul);
		
		for(var i=0; i<SlidingMenu.menuItems.length; i++) {
			var menuItem = SlidingMenu.menuItems[i];
			
			var li = document.createElement("li");
			ul.appendChild(li);
			if(menuItem["type"] == "href") {
				li.url = menuItem["url"];
				li.style.cursor = "pointer";
				li.onclick = function() {
					window.location.href = this.url;
				};
			}
			
			if(menuItem["subMenu"]) {
				li.subMenu = menuItem["subMenu"];
				var img = document.createElement("img");
				img.src = "/lib/img/simple_small_right_arrow.png";
				img.style.cssFloat = "right";
				img.style.styleFloat = "right";
				li.appendChild(img);
				li.onmouseover = function() {
					if(me.subMenuLvl1Timer) {
						window.clearTimeout(me.subMenuLvl1Timer);
					}
					me.showSubMenuLvl1(this);
				}
				li.onmouseout = function() {
					if(me.subMenuLvl1Timer) {
						window.clearTimeout(me.subMenuLvl1Timer);
					}
					
					me.subMenuLvl1Timer = window.setTimeout(
						function() {
							me.subMenuDiv.style.display = "none";
						}, SlidingMenu.MENU_HIDE_TIME
					);
					
					me.subMenuDiv.onmouseover = function() {
						if(me.subMenuLvl1Timer) {
							window.clearTimeout(me.subMenuLvl1Timer);
						}
					};
					
					me.subMenuDiv.onmouseout = function() {
						if(me.subMenuLvl1Timer) {
							window.clearTimeout(me.subMenuLvl1Timer);
						}
						
						me.subMenuLvl1Timer = window.setTimeout(
							function() {
								me.subMenuDiv.style.display = "none";
							}, SlidingMenu.MENU_HIDE_TIME
						);
					};
					
				}
			}
			li.appendChild(document.createTextNode(menuItem["name"]));
		}
	};
	
	this.showSubMenuLvl1 = function(parentNode) {

		me.subMenuDiv.style.left = parseInt(parentNode.offsetLeft + parentNode.offsetWidth, 10)+"px";
		me.subMenuDiv.style.top = parentNode.offsetTop+"px";
		
		/* hack for ie7 because it's dumb and doesn't do things the same as everything else */
		if(BROWSER == IE7) {
			
			me.subMenuDiv.style.top = parseInt(parentNode.offsetTop + parentNode.offsetParent.offsetTop, 10)+"px";
			
			me.subMenuDiv.style.left = parseInt(
				parentNode.offsetParent.parentNode.offsetLeft + 
				parentNode.parentNode.offsetLeft +
				parentNode.parentNode.offsetWidth
				,10)+"px";
			
		}
		
		
		me.subMenuDiv.style.display = "block";
		document.body.appendChild(me.subMenuDiv);
		
		cleanNode(me.subMenuDiv);
		
		var ul = document.createElement("ul");
		me.subMenuDiv.appendChild(ul);
		
		for(var i=0; i<parentNode.subMenu.length; i++) {
			var subMenu = parentNode.subMenu[i];
			
			var li = document.createElement("li");
			ul.appendChild(li);
			
			if(subMenu["subMenu"]) {
				li.subMenu = subMenu["subMenu"];
				var img = document.createElement("img");
				img.src = "/lib/img/simple_small_right_arrow.png";
				img.style.cssFloat = "right";
				img.style.styleFloat = "right";
				li.appendChild(img);
				li.onmouseover = function() {
					if(me.subMenuLvl2Timer) {
						window.clearTimeout(me.subMenuLvl2Timer);
					}
					me.showSubMenuLvl2(this);
				}
				li.onmouseout = function() {
					if(me.subMenuLvl2Timer) {
						window.clearTimeout(me.subMenuLvl2Timer);
					}
					
					me.subMenuLvl2Timer = window.setTimeout(
						function() {
							me.subMenuDiv2.style.display = "none";
						}, SlidingMenu.MENU_HIDE_TIME
					);
					
					me.subMenuDiv2.onmouseover = function() {
						if(me.subMenuLvl1Timer) {
							window.clearTimeout(me.subMenuLvl1Timer);
						}
						if(me.subMenuLvl2Timer) {
							window.clearTimeout(me.subMenuLvl2Timer);
						}
					};
					
					me.subMenuDiv2.onmouseout = function() {
						if(me.subMenuLvl1Timer) {
							window.clearTimeout(me.subMenuLvl1Timer);
						}
						if(me.subMenuLvl2Timer) {
							window.clearTimeout(me.subMenuLvl2Timer);
						}
						
						me.subMenuLvl1Timer = window.setTimeout(
							function() {
								me.subMenuDiv.style.display = "none";
							}, SlidingMenu.MENU_HIDE_TIME
						);
						
						me.subMenuLvl2Timer = window.setTimeout(
							function() {
								me.subMenuDiv2.style.display = "none";
							}, SlidingMenu.MENU_HIDE_TIME
						);
					};
				}
			}
			
			li.appendChild(document.createTextNode(subMenu["name"]));
			
			if(subMenu["type"] == "href") {
				if(!li.link) {
					li.link = subMenu['url'];
				}
				li.onclick = function() {
					window.location.href = this.link;
				};
			}
		}
		
	};
	
	this.showSubMenuLvl2 = function(parentNode) {
		
		me.subMenuDiv2.style.top = parseInt(parentNode.parentNode.parentNode.offsetTop+10,10)+"px";
		me.subMenuDiv2.style.left = parseInt(parentNode.parentNode.parentNode.offsetLeft+parentNode.parentNode.parentNode.offsetWidth, 10)+"px";
		me.subMenuDiv2.style.display = "block";
		document.body.appendChild(me.subMenuDiv2);
		
		cleanNode(me.subMenuDiv2);
		
		var ul = document.createElement("ul");
		me.subMenuDiv2.appendChild(ul);

		for(var i=0; i<parentNode.subMenu.length; i++) {
			var subMenu = parentNode.subMenu[i];
			
			var li = document.createElement("li");
			ul.appendChild(li);
			
			if(subMenu["subMenu"]) {
				li.subMenu = subMenu["subMenu"];
				var img = document.createElement("img");
				img.src = "/lib/img/simple_small_right_arrow.png";
				img.style.cssFloat = "right";
				img.style.styleFloat = "right";
				li.appendChild(img);
				li.onmouseover = function() {
					if(me.subMenuLvl2Timer) {
						window.clearTimeout(me.subMenuLvl2Timer);
					}
					me.showSubMenuLvl2(this);
				}
				li.onmouseout = function() {
					if(me.subMenuLvl2Timer) {
						window.clearTimeout(me.subMenuLvl2Timer);
					}
					
					me.subMenuLvl2Timer = window.setTimeout(
						function() {
							me.subMenuDiv2.style.display = "none";
						}, SlidingMenu.MENU_HIDE_TIME
					);
					
					me.subMenuDiv2.onmouseover = function() {
						if(me.subMenuLvl1Timer) {
							window.clearTimeout(me.subMenuLvl1Timer);
						}
						if(me.subMenuLvl2Timer) {
							window.clearTimeout(me.subMenuLvl2Timer);
						}
					};
					
					me.subMenuDiv2.onmouseout = function() {
						if(me.subMenuLvl1Timer) {
							window.clearTimeout(me.subMenuLvl1Timer);
						}
						if(me.subMenuLvl2Timer) {
							window.clearTimeout(me.subMenuLvl2Timer);
						}
						
						me.subMenuLvl1Timer = window.setTimeout(
							function() {
								me.subMenuDiv.style.display = "none";
							}, SlidingMenu.MENU_HIDE_TIME
						);
						
						me.subMenuLvl2Timer = window.setTimeout(
							function() {
								me.subMenuDiv2.style.display = "none";
							}, SlidingMenu.MENU_HIDE_TIME
						);
					};
					
				}
			}
			
			li.appendChild(document.createTextNode(subMenu["name"]));
			if(subMenu["type"] == "href") {
				li.subMenu = subMenu;
				li.onclick = function() {
					window.location.href = this.subMenu["url"];
				};
			}
		}
	};
	
	var me = this;
	this.baseNode = document.getElementById("menu");
	this.subMenuLvl1Timer = null;
	this.subMenuLvl2Timer = null;
	this.subMenuDiv = null;
	this.subMenuDiv2 = null;
	this.admin = admin;
	this.init();
}

SlidingMenu.MENU_HIDE_TIME = 300;

/**
 * name, title, url, subMenu
 * 
 */
SlidingMenu.menuItems = new Array(
	{
		"name": "home",
		"title": "Northern Log And Timber Home",
		"type": "href",
		"url": "/"
	},
	{
		"name": "about northern log",
		"title": "About Northern Log And Timber",
		"type": "href",
		"url": "/about-northern-log-and-timber.html"
	},
	{
		"name": "machined log homes",
		"title": "Machined Log Homes",
		"type": "href",
		"url": "/machined-standard-features.html",
		"subMenu": new Array(
				{
					"name": "info",
					"type": "href",
					"url": "/machine-log-homes-info.html"
				},
				{
					"name": "standard features",
					"type": "href",
					"url": "/machined-standard-features.html"
				},
				{
					"name": "construction photos",
					"type": "href",
					"url": "/browse-machine-log-homes.html"
				}
		)
	},
	{
		"name": "hand crafted log homes",
		"title": "Hand Crafted Log Homes",
		"type": "href",
		"url": "/handcrafted-log-homes-standard-features.html",
		"subMenu": new Array(
				{
					"name": "info",
					"type": "href",
					"url": "/handcrafted-log-homes-info.html"
				},
				{
					"name": "standard features",
					"type": "href",
					"url": "/handcrafted-log-homes-standard-features.html"
				},
				{
					"name": "construction photos",
					"type": "href",
					"url": "/browse-handcrafted-log-homes.html"
				}
		)
	},
	{
		"name": "specialty timbers / associated products",
		"title": "Specialty Timbers / Associated Products",
		"type": "href",
		"url": "/timber-frame-standard-features.html",
		"subMenu": new Array(
				{
					"name": "standard features",
					"type": "href",
					"url": "/timber-frame-standard-features.html"
				},
				{
					"name": "photos",
					"type": "href",
					"url": "/browse-specialty-timber.html"
				}
		)
	},
	{
		"name": "plans and pricing",
		"title": "plans and pricing",
		"type": "href",
		"url": "/plans.html",
		"subMenu": new Array(
				{
					"name": "plans",
					"type": "href",
					"url": "/plans.html"
				},
				{
					"name": "general pricing",
					"type": "href",
					"url": "/pricing.html"
				},
				{
					"name": "handcrafted log pricing",
					"type": "href",
					"url": "/pricing-handcrafted.html"
				},
				{
					"name": "machined log pricing",
					"type": "href",
					"url": "/pricing-machined.html"
				}
		)
	},
	{
		"name": "drafting / design",
		"title": "Drafting and Design Services",
		"type": "href",
		"url": "/design-and-drafting-standard-features.html",
		"subMenu": new Array(
				{
					"name": "standard features",
					"type": "href",
					"url": "/design-and-drafting-standard-features.html"
				},
				{
					"name": "browse",
					"type": "href",
					"url": "/browse-design-and-drafting.html"
				}
		)
	},
	{
		"name": "gallery",
		"title": "Our Log Home Photo Gallery",
		"type": "href",
		"url": "/gallery-cabins.html",
		"subMenu": new Array(
				{
					"name": "cabins",
					"type": "href",
					"url": "/gallery-cabins.html"
				},
				{
					"name": "homes",
					"type": "href",
					"url": "/gallery-homes.html"
				},
				{
					"name": "commercial",
					"type": "href",
					"url": "/gallery-commercial.html"
				},
				{
					"name": "handcrafted log homes",
					"type": "href",
					"url": "/gallery-handcrafted.html"
				},
				{
					"name": "interiors - handcrafted log homes",
					"type": "href",
					"url": "/gallery-handcrafted-interiors.html"
				},
				{
					"name": "interiors - machined log homes",
					"type": "href",
					"url": "/gallery-machined-interiors.html"
				},
				{
					"name": "archives",
					"type": "href",
					"url": "/gallery-archives.html"
				}
		)
	},
	{
		"name": "contact",
		"title": "Contact Northern Log And Timber",
		"type": "href",
		"url": "/contact-northern-log-and-timber.html"
	},
	{
		"name": "faqs",
		"title": "Frequently Asked Questions",
		"type": "href",
		"url": "/faq-general.html",
		"subMenu": new Array(
				{
					"name": "general questions",
					"type": "href",
					"url": "/faq-general.html"
				},
				{
					"name": "maintenance and products",
					"type": "href",
					"url": "/faq-maintainence-and-products.html"
				}
		)
	},
	{
		"name": "specials",
		"title": "Northern Log And Timber's Specials",
		"type": "href",
		"url": "/specials.html"
	}
);