/*
 * afp.js
 *
 * Fonctions pour mise en page des menus AFP
 *
 * @(#) $Id: lecentaure.js,v 1.1 2007/01/19 10:57:16 dcantau Exp $
 *
 */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function getPageOffsetLeft(el){
	x=el.offsetLeft;
	if (el.offsetParent!=null)
		x+=getPageOffsetLeft(el.offsetParent);
	return x;
}

function getPageOffsetTop(el){
	y=el.offsetTop;
	if (el.offsetParent!=null)
		y+=getPageOffsetTop(el.offsetParent);
	return y;
}

function showShim(obj) {
    var ishim = document.getElementById("ishim");
    if (ishim) {
     	ishim.style.left    = getPageOffsetLeft(obj)+"px"; /* parfois faux */
    	ishim.style.top     = getPageOffsetTop(obj)+"px";
    	ishim.style.width   = obj.offsetWidth+"px";
    	ishim.style.height  = obj.offsetHeight+"px";
	    obj.style.zIndex    = "101";
    	ishim.style.zIndex  = "0";
    	ishim.style.display = "block";
    }
}

function showShim2(obj, offsetLeft) {
    var ishim = document.getElementById("ishim2");
    if (ishim) {
     	ishim.style.left    = offsetLeft+"px"; /* parfois faux */
    	ishim.style.top     = getPageOffsetTop(obj)+"px";
    	ishim.style.width   = obj.offsetWidth+"px";
    	ishim.style.height  = (obj.offsetHeight + 1)+"px";
	    obj.style.zIndex    = "101";
    	ishim.style.zIndex  = "0";
    	ishim.style.display = "block";
    }
}

function hideShim() {
    var ishim = document.getElementById("ishim");
    if (ishim) {
    	ishim.style.display="none";
    }
}

function hideShim2() {
    var ishim = document.getElementById("ishim2");
    if (ishim) {
    	ishim.style.display="none";
    }
}

/* pour IE seulement */
function sfHover() {
    if (window.opera) return;
    // insérer une iframe
    if (document.getElementById("container")) {
        sText = '<iframe id="ishim" src="about:blank" ' +
            'scrolling="no" frameborder="0" style="position:absolute; ' +
            'top:0px; left:0px; display:none;"></iframe>';
        document.getElementById("container").insertAdjacentHTML('afterEnd', sText);
        sText = '<iframe id="ishim2" src="about:blank" ' +
            'scrolling="no" frameborder="0" style="position:absolute; ' +
            'top:0px; left:0px; display:none;"></iframe>';
        document.getElementById("container").insertAdjacentHTML('afterEnd', sText);
    }
    if (document.getElementById("nav")) {
        sfEls = document.getElementById("nav").getElementsByTagName("LI");
    	for (i=0; i<sfEls.length; i++) {
            /* mouveover */
            sfEls[i].onmouseover=function() {
		    	this.className+=" sfhover";
                // récupérer le a du li
                this.getElementsByTagName('a')[0].className += "sfhover";
                if (this.getElementsByTagName('a')[0].className == "daddysfhover") {
                    var ul = this.getElementsByTagName("UL")[0];
                    if (ul) {
                            var ishim = document.getElementById("ishim");
                            debugPrint('<hr>');
                            debugPrint('getPageOffsetLeft(ishim):' + getPageOffsetLeft(ishim));
                            debugPrint('ishim.offsetLeft        :' + ishim.offsetLeft);
                            debugPrint('ishim.offsetWidth       :' + ishim.offsetWidth);
                            debugPrint('ishim.clientWidth       :' + ishim.clientWidth);
                            debugPrint('ishim.style.width       :' + ishim.style.width);
                            debugPrint('<hr>');
                        showShim2(ul, ishim.offsetLeft + ishim.clientWidth - 1);
                    }
                }
                else {
                    var ul = this.getElementsByTagName("UL")[0];
                    if (ul) {
                        showShim(ul);
                    }
                }
            }
            /* mouseout */
    		sfEls[i].onmouseout=function() {
	    		this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                // récupérer le a du li
                a = this.getElementsByTagName('a')[0];
                a.className=a.className.replace(new RegExp("sfhover\\b"), "");
                // cacher la iframe
                debugPrint('onmouseout a.className:' + a.className);
                if (a.className == 'daddy')
                    hideShim2();
                else
                    hideShim();
            }
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);


/* debug */

var debugWindow = null;

function openDebugWindow() {
    debugWindow = window.open("","debugWin","toolbar=no,scrollbars,resizable=yes,width=600,height=400");
    if (debugWindow) {
        debugWindow.document.writeln('<html>');
        debugWindow.document.writeln('<head>');
        debugWindow.document.writeln('<title>JS Remote Debug Window</title>');
        debugWindow.document.writeln('</head>');
        debugWindow.document.writeln('<body style="font-size:10px"><font face="verdana,arial">');
        debugWindow.document.writeln('<hr size=1 width="100%">');
    }
}

function debugPrint(msg)
{
    return;
    if (!debugWindow) openDebugWindow();
    if (debugWindow) {
        debugWindow.document.writeln(msg);
        debugWindow.document.writeln('<br>');
        debugWindow.scrollTo(0,debugWindow.document.body.scrollHeight);
        if (window.opera) {
            debugWindow.focus();
        }
        else {
            self.focus();
        }
    }
}
