﻿/**
* CSShiarchMenu v0.3
*	written by: me[AT]daantje[DOT]nl
*	last update: Sun May 29 13:04:00 CEST 2005
*
*	Documentation:
*		Build this small script cause all the gpl-ed scripts I found where too big
*		and had too many options I never going to use, or the config for the menu
*		was not easy to set with a PHP routine.
*
*	License:
*		Use this script any way you like...
*/


//declare
var submenu = new Array();
var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';

// EXAMPLE CONFIG
var menuWidth 		= 440;			//width of submenu in pixels
var alignSubmenu 	= 'bottom';		//bottom or right side of the main button.
var useLastItemCSS	= true;			//generate last menu item too
									//if false, it will behave as a normal item
									//and the css menuItemLast class will not be used

//zero submenu tree
submenu['menu0'] = new Array();
submenu['menu0'][0] = menuItem('• IMPRESSIES','index.cfm?page=textiel','_self');
submenu['menu0'][1] = menuItem('• HERSTOFFERINGEN','index.cfm?page=textiel1','_self');
submenu['menu0'][2] = menuItem('• STOFFENCOLLECTIE','index.cfm?page=textiel2','_self');
submenu['menu0'][3] = menuItem('• GORDIJNEN & LUIKEN','index.cfm?page=textiel3','_self');




// END OF EXAMPLE CONFIG


//build or unhide submenu div...
function buildSubmenu(obj){
	lastOverId = obj.id;

	//get common part of div id
	menuPath = obj.id.split('_');

	//unset mousout of parent menus and make sure they are visible...
	x = "div";
	for(i=0;i<menuPath.length;i++){
		x+= '_' + menuPath[i];
		if(document.getElementById(x)){
			if(tmr[x])
				window.clearTimeout(tmr[x]);
			document.getElementById(x).style.visibility = 'visible';
		}
	}

	//check if we have a submenu of the obj... 
	if(submenu[obj.id]){
		//check if allready build...
		c = document.getElementById('div_' + obj.id);
		if(c){
			//unhide...
			c.style.visibility = 'visible';
			c.style.zIndex = last_zIndex++;
		}else{
			//calc position of mouseover
			d = obj;
			if(d){
				L_pos = d.offsetLeft + d.offsetWidth ;
				T_pos = d.offsetTop ;
				while(d.offsetParent){
					d = d.offsetParent;
					L_pos+= d.offsetLeft;
					T_pos+= d.offsetTop ;
				}
			}

			//patch first submenu to go right below the main buttons...
			if(obj.className.indexOf('menuItem') < 0 && alignSubmenu == 'bottom'){
				L_pos-= obj.offsetWidth;
				T_pos+= obj.offsetHeight;
			}

			//build new div
			subObj = document.createElement('div');
			subObj.id = 'div_' + obj.id;
			subObj.className = 'submenu';
			subObj.style.position = 'absolute';
			subObj.style.zIndex = last_zIndex++;
			subObj.style.width = menuWidth ;
			subObj.style.top = T_pos;
			subObj.style.left = L_pos;

			//write div to the body...
			document.getElementsByTagName('body')[0].appendChild(subObj);

			//build html for submenu
			content = "<div  onmouseout=\"hideSubmenu(this)\" onmouseover=\"buildSubmenu(this)\" id=\"" + obj.id + "_" + i +"\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"  ><tr><td ></td>";
			m = submenu[obj.id];
			for(i=0;i<m.length;i++){

				//make item
				 if(m[i][2] == "leeg"){
					content+= "</tr><td height=\"10\"></td></tr><tr>";
				} 
				else {
					content+= "<td width=\"10\"></td>";
				}


				
				content+= "<td  height=\"80\"   valign=\"middle\" align=\"center\" ><a class=\"menu\" href=\"" + m[i][1] + "\"><p style=\" _position: relative; _top: 40%\"> " + m[i][0] + "</p> </a></td>";


				

				
			
				
				adj[i] = obj.id + "_" + i;
			}
			content+= "</table></div>"
			
		

			//insert new menu
			subObj.innerHTML = content;

			
		}
	}
}

//hide a submebu div
function hideSubmenu(obj){
	//get common part of div id
	closePath = obj.id.split('_');

	//hide path
	x = "div";
	for(i=0;i<closePath.length;i++){
		x+= '_' + closePath[i];
		if(document.getElementById(x))
			tmr[x] = window.setTimeout("document.getElementById('"+x+"').style.visibility = 'hidden';",500);
		//The timeout above is needed for MSIE browsers... Or else the menu's will disapear on EVERY mousout!!!
		//Please get a normal browser like Firefox, Mozilla or Opera!!
	}
}

//add an menu item to the config array (called in the config lines)
function menuItem(txt,url,tar){
	return new Array(txt,url,tar);
}

//*** Patch for firefox bug with focus on mouseover...
//		This function should be called onMouseOver of every iFrame that's under the menu structure.
function iFramePatch(){
	if(!document.all && lastOverId)
		hideSubmenu(document.getElementById(lastOverId));
}

//*** Now a patch for MSIE lag of CSS2 compliance!!
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')==-1){
	document.onmouseover = function(){
		obj = event.srcElement;
		if(obj.className == 'menuItemFirst' || obj.className == 'menuItem' || obj.className == 'menuItemLast')
			obj.className+='Over';
	}
	document.onmouseout = function(){
		obj = event.srcElement;
		if(obj.className == 'menuItemFirstOver' || obj.className == 'menuItemOver' || obj.className == 'menuItemLastOver')
			obj.className = obj.className.substring(0,(obj.className.length - 4));
	}
}
//*** End of msie patch
