/*
 * colbert.js
 *
 * Fonctions pour mise en page des menus
 *
 * @(#) $Id: colbert.js,v 1.1 2009/11/08 18:21:30 amalacchina Exp $
 *
 */
var mmOpenContainer = null;
var mmOpenMenus = null;
var mmHideMenuTimer = null;
var debugWindow = null;

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_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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 MM_menuStartTimeout(hideTimeout) {
	mmHideMenuTimer = setTimeout("MM_menuHideMenus()", hideTimeout);
}

function MM_menuHideMenus() {
	MM_menuResetTimeout();
	if(mmOpenContainer) {
		var c = document.getElementById(mmOpenContainer);
        if (c != null) c.style.visibility = "inherit";
		mmOpenContainer = null;
	}
	if( mmOpenMenus ) {
		for(var i = 0; i < mmOpenMenus.length ; i++) {
			var m = document.getElementById(mmOpenMenus[i]);
            if (m != null) m.style.visibility = "hidden";
		}
		mmOpenMenus = null;
	}
}

function MM_menuHideSubmenus(menuName) {
	if ( mmOpenMenus ) {
		var h = false;
		var c = 0;
		for(var i = 0; i < mmOpenMenus.length ; i++) {
			if( h ) {
				var m = document.getElementById(mmOpenMenus[i]);
				m.style.visibility = "hidden";
			} else if( mmOpenMenus[i] == menuName ) {
				h = true;
			} else {
				c++;
			}
		}
		mmOpenMenus.length = c+1;
	}
}

function MM_menuOverMenuItem(menuName, subMenuSuffix) {
	MM_menuResetTimeout();
	MM_menuHideSubmenus(menuName);
	if( subMenuSuffix ) {
		var subMenuName = "" + menuName + "_" + subMenuSuffix;
		MM_menuShowSubMenu(subMenuName);
	}
}

function MM_menuShowSubMenu(subMenuName) {
	MM_menuResetTimeout();
	var e = document.getElementById(subMenuName);
    if (e != null) {
    	e.style.visibility = "inherit";
    }
	if( !mmOpenMenus ) {
		mmOpenMenus = new Array;
	}
	mmOpenMenus[mmOpenMenus.length] = "" + subMenuName;
}

function MM_menuResetTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
}

function MM_menuShowMenu(containName, menuName, xOffset, yOffset, triggerName) {
	MM_menuHideMenus();
	MM_menuResetTimeout();
	MM_menuShowMenuContainer(containName, xOffset, yOffset, triggerName);
	MM_menuShowSubMenu(menuName);
}

function MM_menuShowMenuContainer(containName, x, y, triggerName) {
	var c = document.getElementById(containName);
    if (c != null) {
	    var s = c.style;
	    s.visibility = "inherit";
    }
	mmOpenContainer = "" + containName;
}

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();
            }
        }
    }
}



/* debug */

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();
        }
    }
}

function ouvrirPopupScrollbars(url, width, height) {
    var popupScrollbars = window.open("","popupScrollbars","toolbar=no,scrollbars=yes,status=no,resizable=yes,,left=50,top=50,width="+width+",height="+height);
    popupScrollbars.location.href = url;
    popupScrollbars.focus();
}

