var rootMainMenuDivName = 'left_menu';
var mainMenuDelay_show = 300;
var mainMenuDelay_hide = 800;
var dontHideClassName='nextLevel';
var ajaxRequest='http://www.wiener-flohmarkt.at/themes/vista/ajax_left_menu.php';

<!-- system settings, dont change -->
var mainMenuRoot = false;
var mainMenuZIndex = 800;
var visibleULs = new Array();
var loadedMenus = new Array();
var activeLI=false;
var menuIsActive=false;
var ajaxObjectArray = new Array();

<!-- AJAX functions -->

function ajaxOnCompletion(ajaxIndex, ulId)
{
	var ul = document.getElementById(ulId);
	if(ul)
	{
//		ul.style.display='none';
		var level = ul.className.replace(/[^0-9]/g, '');
		var numericId = ul.id.replace(/[^0-9]/g, '');
		var liIndex = numericId*100;
		level = level-0;   // to make '+' under int context
		ul.innerHTML = ajaxObjectArray[ajaxIndex].response;
		ajaxObjectArray[ajaxIndex] = false;
		var subLi = ul.getElementsByTagName('LI')[0];
		while(subLi)
		{
			if(subLi.tagName=='LI')
			{
				initSubMenu(subLi, level+1, liIndex)
				liIndex++;
			}
			subLi = subLi.nextSibling;
		}
/*
		if(menuIsActive && activeLI.id == 'listItem'+numericId)
		{
			ul.style.display='';
		}
*/
	}
}

function fillSubMenuLI(id)
{
	var li = document.getElementById(id);
	numericId = id.replace(/[^0-9]/g, '');
	if(li)
	{
		var ul = document.getElementById('subMenu'+numericId);
		if(ul && !loadedMenus[id])
		{
			// call ajax
			var a = li.getElementsByTagName('A')[0];
			if(a)
			{
// developer SEF addon FIX
		    var startIndex = a.href.indexOf('?');
        
        if( startIndex >= 0 ){
          var params = a.href.substring(startIndex, a.href.length);
        }else{          
          startIndex = a.href.indexOf('.at/');
          var params = "?"+a.href.substring(startIndex+4, a.href.length);
        }
        
///        var startIndex = a.href.indexOf('?');
//				var end = a.href.indexOf('?', start+1);
//				if(end==-1) end = a.href.length;
//				var params = a.href.substring(start+1,end);
///				var params = a.href.substring(startIndex, a.href.length);
				ajaxObjectArray[ajaxObjectArray.length] = new sack();
				var ajaxIndex = ajaxObjectArray.length-1;
				ajaxObjectArray[ajaxIndex].requestFile = ajaxRequest + params;
				ajaxObjectArray[ajaxIndex].onCompletion = function() { ajaxOnCompletion(ajaxIndex,ul.id); };	// Specify function that will be executed after file has been found
				ajaxObjectArray[ajaxIndex].runAJAX();		// Execute AJAX function
				loadedMenus['listItem'+numericId]=true;
			}
		}
	}
}

<!-- END AJAX functions -->

function elementTopPosition(obj)
{
	  var il_a = obj.getElementsByTagName('A')[0];
	  var ret = obj.offsetTop;
	  while((obj = obj.offsetParent) != null)
	  {
		  ret += obj.offsetTop;
	  }
	  return ret;
}

function elementLeftPosition(obj)
{
	  var ret = obj.offsetLeft;
	  while((obj = obj.offsetParent) != null)
	  {
		  ret += obj.offsetLeft;
	  }
	  return ret;
}

function showHideSubMenu()
{
  activeLI = this;
  var noHide = new Array();
  var command = 'showHideSubMenuTimer("'+this.id+'")';
  window.setTimeout(command, mainMenuDelay_show);
}

function hideWholeMenuTimer()
{
	if(!menuIsActive)
	{
		hideSubMenus(new Array());
	}
}

function showHideSubMenuTimer(id)
{
	if(activeLI.id == id && menuIsActive)
	{
		var numericId = id.replace(/[^0-9]/g, '')
		var ul = document.getElementById('subMenu'+numericId);
		var noHide = new Array();
		if(ul)
		{
			ul.style.display='';
			visibleULs.push(ul);
			fillSubMenuLI(id);
			noHide[ul.id]=true;
		}
		// show parents
		numericId = numericId.substring(0, numericId.length-2);
		var parentId = 'subMenu'+numericId;
		var parent = document.getElementById(parentId);
		while(numericId.length>0 && parent)
		{
			visibleULs.push(parent);
			noHide[parent.id] = true;
			parent.style.display='';
			numericId = numericId.substring(0, numericId.length-2)
			parent = document.getElementById('subMenu' + numericId);
		}
		hideSubMenus(noHide);
	}
}

function hideSubMenus(noHide)
{
	var newVisibleULs = new Array();
	for(a=0; a < visibleULs.length; ++a)
	{
		if(noHide[visibleULs[a].id])
		{
			newVisibleULs.push(visibleULs[a]);
		}
		else
		{
			visibleULs[a].style.display='none';
		}
	}
	visibleULs=newVisibleULs;
}

function mainMenuOver()
{
	menuIsActive = true;
}

function mainMenuOut()
{
	menuIsActive = false;
	setTimeout('hideWholeMenuTimer()', mainMenuDelay_hide);
}

function initSubMenu(objLi, level, numericId)
{
	var ul=false;
	var objFixArr = objLi.id.split("_");
  if(objFixArr[0]=='hasSubMenu')
	{
		ul = document.createElement('UL');
		ul.innerHTML="<li><span>Loading...</span></li>";
//		loadUl.id='subMenu'+numericId;
//		ul.appendChild(loadLI);
//		mainMenuRoot.appendChild(loadUl);
//		objLi.innerHTML += "<ul><li><span>Loading...</span></li></ul>";
	}
	else
	{
		// try to process subUL if has some
		ul = objLi.getElementsByTagName('UL')[0];
	}
	objLi.id = 'listItem'+numericId;
//	var ul = objLi.getElementsByTagName('UL')[0];
//	var numericId = objLi.id.replace(/[^0-9]/g, '');
	var liIndex = numericId*100;
	if(objLi.className!=dontHideClassName)
	{
		objLi.onmouseover = showHideSubMenu;
		if(ul)
		{
			ul.id='subMenu'+numericId;
			ul.style.position='absolute';
			ul.style.zIndex=mainMenuZIndex;
			ul.style.display='none';
			mainMenuZIndex++;
			ul.className='mainMenuBlock'+level;
			ul.onmouseover=mainMenuOver;
			ul.onmouseout=mainMenuOut;
			mainMenuRoot.appendChild(ul);
			ul.style.top=(elementTopPosition(objLi)+5)+'px';
			ul.style.left=(elementLeftPosition(objLi)+170)+'px';
		}
	}
	if(ul)
	{
		var li = ul.getElementsByTagName('LI')[0];
		while(li)
		{
			if(li.tagName=='LI')
			{
				initSubMenu(li,level+1, liIndex);
				liIndex++;
			}
			li = li.nextSibling;
		}
	}
}

function initLeftMenu()
{
	mainMenuRoot = document.getElementById(rootMainMenuDivName);
	var liIndex = 1;
	if(mainMenuRoot)
	{
		rootUl = mainMenuRoot.getElementsByTagName('UL')[0];
		if(rootUl)
		{
			rootUl.onmouseover = mainMenuOver;
			rootUl.onmouseout = mainMenuOut;
			var li = rootUl.getElementsByTagName('LI')[0];
			while(li)
			{
				if(li.tagName=='LI')
				{
					initSubMenu(li, 1, liIndex);
					liIndex++;
				}
				li = li.nextSibling
			}
		}
	}
}

