// date :18/11/03

var lay;
var t;
var s;
//popTimer = 0;
believeTimer=false;
var s=new Array();
var lay=new Array();

/*
function openMenu(menuName) 
{

	//modifié le 11/12/03
	var targetMenuObj;
	var targetMenuStyle;
	// on vérifie que le menu est déclaré. si non, on le déclare
	if(getArrayPos(lay,menuName)<0) lay[lay.length]=menuName;
	
	
	//pour netscape
 	believeTimer = false;
	clearTimeout(popTimer);

	if(clientIs.ns && !clientIs.ns6 && !clientIs.ns7)
	{
		setTimeout("believeTimer = false;", 200);
		if (typeof(menuName) != "string") return false;
	}

	// on recherche le layer et son style pour pouvoir le manipuler
	targetMenuObj = getLayerObject(menuName);
	if(!targetMenuObj) return;
	targetMenuStyle = getLayerObject(menuName,true);
	if(!targetMenuStyle) return;
	
	//on efface tous les menu qui était visible
	hideall(menuName);

	//on rend visible le menu à ouvrir
	targetMenuObj.onmouseout =closeMenu;
	targetMenuObj.onmouseover=openMenu;
	
	targetMenuStyle.visibility = ((clientIs.ie || clientIs.ns6 || clientIs.ns7) ? ("visible") : "show" );
}
*/
/*
function closeMenu(menuName) 
{

	//// debug("closing "+menuName)
	believeTimer = true;
	if (typeof(menuName)!= "string" )
		//appel venant de la page html suite à un mouseOut
		{popTimer = setTimeout("hideall()", 500);}
	else
		//appel du à l'ouverture d'un autre menu
		{hideall(menuName);}
}
*/

/*
function hideall(menuName)
{
	str="";
	var targetMenuObj;
	var targetMenuStyle;
	
	if (!believeTimer && (typeof(menuName) != "string") && clientIs.ns && !clientIs.ns6 && !clientIs.ns7) return false;
	
	// on recherche un menu créé dynamiquement
	if(menuName) 
	{
		var menuObj = getMenuByName(menuName);
		if(menuObj) var parentArray = menuObj.getParentArray(menuName);
		//// debug(parentArray);
	}

	for(var i=0;i <lay.length;i++)
	{
		var targetMenuName = lay[i];
		if(menuName == targetMenuName) continue;
		//// debug(menuName+" "+lay[i]+" "+getArrayPos(parentArray,lay[i]))
		if(parentArray)
			if(getArrayPos(parentArray,targetMenuName)>0) continue;
		// on recherche le layer et son style pour pouvoir le manipuler
		targetMenuObj = getLayerObject(targetMenuName);
		if(!targetMenuObj) continue;
		targetMenuStyle = getLayerObject(targetMenuName,true);
		if(!targetMenuStyle) continue;
	
		
		// on efface les layers
		targetMenuStyle.visibility = ((clientIs.ie || clientIs.ns6 || clientIs.ns7) ? ("hidden") : "hide" );;
		
		var tmpMenu = getMenuByName(targetMenuName);

		if(!tmpMenu) return;

		tmpMenu.hide();
	}
}
*/

if (clientIs.ns) document.captureEvents(Event.MOUSEDOWN);
document.onclick = clickHandle;

function clickHandle(evt)
{
	believeTimer=true;
	hideall();
	if (clientIs.ns) document.routeEvent(evt);
}


/***************************************************************
		LayerDynamic v1  Date:17/11/03
***************************************************************/

function openMenuCommon(layerName)
{
	var navRef = layerName+"position";
	openMenuAt(layerName,navRef,9,-5);
}

function openMenuGauche(layerName)
{
	openMenuAt(layerName,'dim'+layerName,102,-4);
}
function openMenuHaut(layerName,navRef)
{
	openMenuAt(layerName,navRef,-7,17);
}
function openMenuBas(layerName,navRef)
{
	openMenuAt(layerName,navRef,0,0,3);
}
function openMenuBasDroite(layerName,navRef)
{
	openMenuAt(layerName,navRef,0,0,2);
}


function openMenuAt(layerName,navRef,xoffset,yoffset,cornerRef)
{
	if(!navRef) return ;
	//pos = getElementPosition(navRef);
	pos = new point(navRef);                                                                       
	pos.x = (!xoffset) ? 0 : xoffset;
	pos.y = (!yoffset) ? 0 : yoffset;
	
	var menuObj = getMenuByName(layerName);
	if(!menuObj) return; 
	
	var layerObj = menuObj.layerObject.getStyle();
                                                                                 
	if(!layerObj) 
	{
		closeMenu('');	
		return;
	}
	


	
	if(menuObj.refCorner==0)	// left top
	{
		// nothing
	}
	if(menuObj.refCorner==1)	// left bottom
	{
		pos.x = -menuObj.size.x-1;
	}
	if(menuObj.refCorner==2)	// right top
	{
		pos.y = -menuObj.size.y-1;
		pos.x = -menuObj.size.x-1;
	}
	if(menuObj.refCorner==3)	// right bottom
	{
		pos.y = -menuObj.size.y-1;
	}
	if(menuObj.refCorner==4)	// center top
	{
		pos.x = (pos.getSize().x/2)-(menuObj.size.x/2)-1;
	}
	if(menuObj.refCorner==5)	// center bottom
	{
		pos.y = -(menuObj.size.y)-1;
		pos.x = (pos.getSize().x/2)-(menuObj.size.x/2)-1;
	}
	
	// fin modif LG040614

	menuObj.setPosition(pos.getPosition().x + pos.x , pos.getPosition().y + pos.y);
	//layerObj.top = pos.getPosition().y + pos.y;
	//layerObj.left = pos.getPosition().x + pos.x;

	openMenu(layerName);
}



function HWLAYER(name)
{
	this.refName =name;
	this.ref = null;
	this.visible = ((clientIs.ie || clientIs.ns6 || clientIs.ns7) ? ("visible") : "show" );
	this.hidden = ((clientIs.ie || clientIs.ns6 || clientIs.ns7) ? ("hidden") : "hide" );
	this.displayed=false;
	this.getStyle = function()
	{
		if(clientIs.ns && !clientIs.ns6 && !clientIs.ns7) return this.getRef();
		//var obj = document.getElementById(this.name);

		return this.getRef().style;
		//return (!obj) ? null : obj.style;
	}
	this.setRef = function (refName){
		this.refName = refName; 	// nom de l'element de référence ( image ! layer (à tester)?! )
		//this.ref = (clientIs.ns && !clientIs.ns6) ? document.images[this.refName] : document.getElementById(this.refName) ;
		
		this.ref = MMNOAUTOLINK_findObj(this.refName);
	
		return this.ref;
	}
	this.getRef = function (){
	
		//if(!this.ref) this.ref = (clientIs.ns && !clientIs.ns6) ? document.images[this.refName] : document.getElementById(this.refName) ;
			
		if(!this.ref) this.setRef(this.refName);
		
		return this.ref;
	}

	this.display = function(){
		if(!this.ref) this.setRef(this.refName);
		if(this.displayed) return ;
		this.ref.onmouseout =closeMenu;
		this.ref.onmouseover= openMenu;
		debug("Displaying "+this.refName+"<br> "+this.ref.style);
		var tmpStyle = this.getStyle();
	
		//if(!tmpStyle) return ;
		tmpStyle.visibility = this.visible;
		this.displayed = true;
	}

	this.hide = function(){
	//	this.ref.onmouseout =closeMenu;
	//	this.ref.onmouseover=openMenu;
	if(!this.displayed) return ;
		var tmpStyle = this.getStyle();
		//if(!tmpStyle) return ;
		tmpStyle.visibility = this.hidden;
		this.displayed = false;
	}
	this.setPosition = function(x,y){
		var tmpStyleObj = this.getStyle();
		tmpStyleObj.left = x;
		tmpStyleObj.top = y;
	}
	this.getPosition = function(){
		var tmpStyleObj = this.getStyle();
		var a = new point()
		a.x = tmpStyleObj.left ;
		a.y = tmpStyleObj.top ;
		return a;
	}
	/*
	this.getLayerObject = function(returnStyle)
	{

		if(clientIs.ns && !clientIs.ns6 && !clientIs.ns7) return document[this.name];
	
		if(!document.getElementById(this.name)) return null;
		if(!returnStyle) return document.getElementById(this.name);
		return document.getElementById(this.name).style;
	}
	*/
	
}