  /*	==========================================================
	Filename		: minimenu.js
	Author			: Copyright 2001-2003 La Mire(www.lamire.com)
	Created			: mercredi 26 novembre 2003 16:14:53
	Last Updated	: mercredi 26 novembre 2003 16:14:53
	Comments		: 
	
	USAGE : 
	
	on load : 
	
	function init(){
	rootmenus['x1']={'delay':delay,'to':0,'current':null };
	// MM_attach (nom du groupe, élément bouton, élément panel, position d'ouverture);
	MM_attach('x1','menu1','sub_menu1','bottom-left'); 
	MM_attach('x1','menu2','sub_menu2','bottom-left'); 
	MM_attach('x1','menu3','sub_menu3','top-right');

}
	HTML : 
	
	==========================================================*/

// the only global - handle time outs;
var rootmenus = new Array(); 



function MM_attach(group,handler,panel,where) {
	o = gE(handler);
	if (!o) alert (handler+ " n'est pas un objet.");
	o.submenu = panel;
	o.group = group;
	o.where = where;
	o.style.cursor = 'hand';
	if (o.style.cursor!='hand')o.style.cursor = 'pointer';
	
	o = gE(panel);
	if (!o) alert (panel+ " n'est pas un objet.");
	o.onmouseout = new Function("MM_wait(this,'"+group+"');");
	o.onmouseover= new Function("MM_CancelTimo('"+group+"');");
}

function MM_showsub(handler,group){
	var x,y,r,ws,panelwidth;
	if (!handler.submenu) return;
	var panel = gE(handler.submenu);  // the panel
	if (!panel) alert (handler.submenu + ' n\est pas un objet');
	
	MM_reset(group); // reset timeout
	rootmenus[group].current = handler.submenu;
	
	// ==================  positionnement du panneau ==========================
	r=eltRect(handler);
	ws =  winSize();
	panelwidth = panel.clientWidth || panel.offsetWidth || panel.style.width;
	// alert (' screen height : '+ ws.x + ', screen width:' + ws.y +', left : '+ r.left + ', width : '+ panelwidth );
	
  switch(handler.where) {
       case 'bottom-left': 
           	x= ((r.left+panelwidth)>ws.w) ? ws.w-panelwidth-2 : r.left;
			y = r.bottom;
           break;
       case 'top-right':
           	x= ((r.right+panelwidth)>ws.w) ? ws.w-panelwidth-2 : r.right;
			y = r.top;
           break;
   }
	sX(panel,x);
	sY(panel,y); 
	if (ie){
		// option : add filters effect
		panel.style.filter = "revealTrans(Transition=5, Duration=0.15)";
		panel.filters.revealTrans.apply();
		sE(panel);
		panel.filters.revealTrans.play();
	} else {
		sE(panel);
	}
}

function MM_hide(o,group){
	var obj = gE(o);
	if (!obj) alert ('MM_hide : '+ o +' not an object');
	hE(obj);
}
function MM_wait(o,group){
	clearTimeout(rootmenus[group].to); // reset timeout
	rootmenus[group].to = setTimeout('MM_reset("'+group+'")',rootmenus[group].delay);
}
function MM_CancelTimo(group){
	clearTimeout(rootmenus[group].to); // reset timeout
}

function MM_reset(group){
	clearTimeout(rootmenus[group].to); // reset timeout
	if (rootmenus[group].current)MM_hide(rootmenus[group].current,group); //close currently open
	rootmenus[group].current =null;
}

// DEBUG ONLY
function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object 
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to 
      // build the message. Message includes i (the object's property name) 
      // then the object's property value on a new line 
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they 
      // click "CANCEL" then quit this level of recursion 
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object 
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}