		$(function(){
			
			Array.prototype.in_array =  function(search_term) {
			   for (var i = 0; i < this.length; i++) {
		    	  if (this[i] === search_term) {
		         return true;
		   	   }
		  	 }
		   return false;
			}
			
			var currentMenuItem, currentSubMenuItem;
			var dropMenuHideTimeout, dropSubMenuHideTimeout, dropSubMenuShowTimeout, holdSubMenuTimeout;
			var hoveredMenuId, hoveredSubMenuId; // the items that are just hovered
			var holdSubMenu = false;
			var item;
			
			// dropmenu
			$("#menu .dropMenu").hide();
			$("#menu .dropMenuContainer").hover(function(){
				clearTimeout(dropMenuHideTimeout);
				if (hoveredMenuId && $(this).attr("id") != hoveredMenuId) {
					$('#'+hoveredMenuId).children(".dropMenu").hide();
				}
				$(this).children(".dropMenu").show();
								
			}, function(){
				//$("#menu .dropSubMenu").hide();
				currentMenuItem = $(this);
				hoveredMenuId = currentMenuItem.attr("id");
				dropMenuHideTimeout = setTimeout(function(){currentMenuItem.children(".dropMenu").hide()}, 500);
			});
			
			// dropsubmenu
			$("#menu .dropSubMenu").hide();
			$("#menu .dropSubMenuContainer").hover(function(){
				if (holdSubMenu) {
					// don't show this hovered submenu when another is just opened..
					itemId = $(this).attr("id");
					holdSubMenuTimeout = setTimeout(function(){clearHold(itemId)}, 350);
					return;
				}
		
				clearTimeout(dropSubMenuHideTimeout);
				clearTimeout(dropSubMenuShowTimeout);
				//$("#menu .dropSubMenu").hide();
				if (hoveredSubMenuId && $(this).attr("id") != hoveredSubMenuId) {
					$('#'+hoveredSubMenuId).children(".dropSubMenu").hide();
				}
				//$(this).children(".dropSubMenu").show();
				currentSubMenuItem = $(this);
				dropSubMenuShowTimeout = setTimeout(function(){showSubMenu(currentSubMenuItem)}, 100);
				//showSubMenu(currentSubMenuItem);
				//alert($(this).attr("id"));
				
			}, function(){
				currentSubMenuItem = $(this);
				hoveredSubMenuId = currentSubMenuItem.attr("id");
				//$(this).children(".dropSubMenu").slideUp();
				dropSubMenuHideTimeout = setTimeout(function(){currentSubMenuItem.children(".dropSubMenu").hide()}, 500);
			});
			 
			function showSubMenu(theSubMenu) {
				// show subMenu, don't hide it when user hovers over mainmenu item
				clearTimeout(dropSubMenuShowTimeout);
				$("#menu .dropSubMenu").hide(); // force all to hide
				theSubMenu.children(".dropSubMenu").show();
				holdSubMenu = true;
			}
			function clearHold(hoveredSubMenuId) {
				holdSubMenu=false;
				showSubMenu($('#'+hoveredSubMenuId));
				return;
				// if other than holded submenu...
				//if (hoveredSubMenu != currentSubMenuItem) {
				if (hoveredSubMenuId && hoveredSubMenuId != currentSubMenuItem.attr("id")) {
					currentSubMenuItem.children(".dropSubMenu").hide();
					$('#'+hoveredSubMenuId).children(".dropSubMenu").show();
				}
			}
			
			//togglebutton
			$(".toggleItem").hide();
			$(".toggleButton").click(function(){
				$(".toggleItem").toggle();
				$(this).toggleClass('toggleButtonHide');
			});
			
			// calendar columns
			$("table.calendar tr.weekdays th a").mouseover( function() {
				var iIndex = $(this).parent().parent().children('th').index($(this).parent()[0]);
				$("table.calendar tr td:nth-child(" + (iIndex+1) + ") a").addClass('active');
			 });
			$("table.calendar tr.weekdays th a").mouseout( function() {
				var iIndex = $(this).parent().parent().children('th').index($(this).parent()[0]);
				$("table.calendar tr td:nth-child(" + (iIndex+1) + ") a").removeClass('active');
			 });
			 
			// calendar rows
			$("table.calendar th.week a").mouseover( function() {
				$(this).parents('tr').find('a').addClass('active') });
			$("table.calendar th.week a").mouseout( function() {
				$(this).parents('tr').find('a').removeClass('active') });

				
			//styled select
			$('.selectorContainer').hover(
				function(){
					$(this).children('.pullDown').show();
				},
				function(){
					$(this).children('.pullDown').hide();
				});
			
			$(".pullDown span").hover(
				function(){
					$(this).addClass('dropMenuHover');
				},
				function(){
					$(this).removeClass('dropMenuHover');
				}
			)
		});