// Utilitaires...
function CloneObject( what ){
    for (i in what) this[i] = what[i];
}

// *** POPUP MENU MAIN OBJECT CONSTRUCTOR ***

function PopupMenu(myName)
{
 // These are the properties of any PopupMenu objects you create.
 this.myName = myName;

 // Manage what gets lit and shown when.
 this.showTimer = 0;
 this.hideTimer = 0;
 this.showDelay = 0;
 this.hideDelay = 500;
 this.showMenu = '';

 // 'menu': the main data store, contains subarrays for each menu e.g. pMenu.menu['root'][];
 this.menu =  new Array();
 // litNow and litOld arrays control what items get lit in the hierarchy.
 this.litNow = new Array();
 this.litOld = new Array();

 // The item the mouse is currently over. Used by click processor to help NS4.
 this.overM = 'root';
 this.overI = 0;

 // The active menu, to which addItem() will assign its results.
 this.actMenu = null;

 // Functions to create and manage the menu.
 this.over = popOver;
 this.out = popOut;
 this.changeCol = popChangeCol;
 this.position = popPosition;
 this.click = popClick;
 this.startMenu = popStartMenu;
 this.addItem = popAddItem;
 this.getHTML = popGetHTML;
 this.update = popUpdate;
 this.setupRef = popSetupRef;

 // Default show and hide functions, overridden in the example script by the clipping routine.
 this.showMenu = new Function('mName', 'this.menu[mName][0].lyr.vis("visible")');
 this.hideMenu = new Function('mName', 'this.menu[mName][0].lyr.vis("hidden")');
}

//'len', 'spacing', 'popInd', 'popPos', 'pad', 'outCol', 'overCol', 'outClass',
//  'overClass', 'outBorder', 'overBorder', 'outAlpha', 'overAlpha', 'normCursor', 'nullCursor'
var hBar = new ItemStyle(40, 0, '', 0, 0, '#336699', '#6699CC', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
 
var hBar1 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_bref.gif', '/francais/_menu/images/menu_bref-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
var hBar2 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_nouvelles.gif', '/francais/_menu/images/menu_nouvelles-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
var hBar3 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_profil.gif', '/francais/_menu/images/menu_profil-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
var hBar4 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_chercheurs.gif', '/francais/_menu/images/menu_chercheurs-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
var hBar5 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_projets.gif', '/francais/_menu/images/menu_projets-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
 var hBar6 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_partenaires.gif', '/francais/_menu/images/menu_partenaires-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
 var hBar7 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_ressources.gif', '/francais/_menu/images/menu_ressources-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
 var hBar8 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_workshop2004.gif', '/francais/_menu/images/menu_workshop2004-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');
 var hBar9 = new ItemStyle(158, 0, '', 0, 0, '/francais/_menu/images/menu_membres.gif', '/francais/_menu/images/menu_membres-roll.gif', 'highText', 'highText', '', '',
 null, null, 'hand', 'hand');

// *** STYLE POUR LES SOUS-MENU ***
var subM = new ItemStyle(48, 0, '&gt;', -15, 3, '/images/_menu/smenu_bg.gif', '/images/_menu/smenu_bg.gif', 'lowText', 'highText',
 '', '', 95, 95, 'hand', 'default');

var subMVideTop = new CloneObject(subM);
subMVideTop.outCol = '/images/_menu/smenu_titre.gif';
subMVideTop.overCol = '/images/_menu/smenu_titre.gif';
 
var subMTitleNouvelles = new CloneObject(subM);
subMTitleNouvelles.outCol = '/francais/_menu/images/smenu_titre_nouvelles.gif';
subMTitleNouvelles.overCol = '/francais/_menu/images/smenu_titre_nouvelles.gif';

var subMTitleProfil = new CloneObject(subM);
subMTitleProfil.outCol = '/francais/_menu/images/smenu_titre_profil.gif';
subMTitleProfil.overCol = '/francais/_menu/images/smenu_titre_profil.gif';

var subMTitleDemo = new CloneObject(subM);
subMTitleDemo.outCol = '/francais/_menu/images/smenu_titre_demos.gif';
subMTitleDemo.overCol = '/francais/_menu/images/smenu_titre_demos.gif';

var subMTitleProjets = new CloneObject(subM);
subMTitleProjets.outCol = '/francais/_menu/images/smenu_titre_projets.gif';
subMTitleProjets.overCol = '/francais/_menu/images/smenu_titre_projets.gif';

var subMTitlePartenaires = new CloneObject(subM);
subMTitlePartenaires.outCol = '/francais/_menu/images/smenu_titre_partenaires.gif';
subMTitlePartenaires.overCol = '/francais/_menu/images/smenu_titre_partenaires.gif';
 
var subMTitleRessources = new CloneObject(subM);
subMTitleRessources.outCol = '/francais/_menu/images/smenu_titre_ressources.gif';
subMTitleRessources.overCol = '/francais/_menu/images/smenu_titre_ressources.gif';

var subMTitleMembres = new CloneObject(subM);
subMTitleMembres.outCol = '/francais/_menu/images/smenu_titre_membres.gif';
subMTitleMembres.overCol = '/francais/_menu/images/smenu_titre_membres.gif';
 
var subMTitleUdeS = new CloneObject(subM);
subMTitleUdeS.outCol = '/images/_menu/smenu_titre.gif';
subMTitleUdeS.overCol = '/images/_menu/smenu_titre.gif';

var subMTitleUdeM = new CloneObject(subM);
subMTitleUdeM.outCol = '/images/_menu/smenu_titre.gif';
subMTitleUdeM.overCol = '/images/_menu/smenu_titre.gif';

var subMVideBottom = new ItemStyle(60, 0, '&gt;', -15, 3, '/images/_menu/smenu_bottom.gif', '/images/_menu/smenu_bottom.gif', 'lowText', 'lowText',
 '', '', 95, 95, 'hand', 'default');
 
var pMenu = new PopupMenu('pMenu');
with (pMenu)
{


//startMenu('nom', true, distance de gauche, distance du top, largeur de la "boite", style);
startMenu('root', true, 0, 105, 203, hBar);

// afficher dans la boite, liens vers un sous-menu ou un URL, 'sm:' si sous-menu et '' sinon, le style, hauteur
addItem('&nbsp;', '/francais/', '',hBar1,22);
//addItem('&nbsp;', 'm2', 'sm:',hBar2,19);
addItem('&nbsp;', '/francais/nouvelles/', '',hBar2,19);
addItem('&nbsp;', 'm3', 'sm:',hBar3,19);
addItem('&nbsp;', '/francais/chercheurs/', '',hBar4,20);
//addItem('&nbsp;', 'm4', 'sm:',hBar4,20);
addItem('&nbsp;', '/francais/projets/', '',hBar5,20);
//addItem('&nbsp;', 'm5', 'sm:',hBar5,20);
addItem('&nbsp;', '/francais/partenaires/', '',hBar6,20);
//addItem('&nbsp;', 'm6', 'sm:',hBar6,20);
addItem('&nbsp;', '/francais/ressources/', '',hBar7,20);
//addItem('&nbsp;', 'm7', 'sm:',hBar7,20);
addItem('&nbsp;', '/Workshop2004/f-acceuil.html', '',hBar8,18);
//addItem('&nbsp;', 'm8', 'sm:',hBar8,18);
addItem('&nbsp;', '/francais/membres/', '',hBar9,21);

// Nouvelles
/*startMenu('m2', true, 135, -10, 150, subM);
addItem('&nbsp;', '/francais/nouvelles/', '', subMTitleNouvelles,31);
addItem('Communiqu&eacute;', '/francais/nouvelles/press.htm', '', subM, 15, 0, '', 3);
addItem('&Eacute;v&eacute;nements', '/francais/nouvelles/events.htm', '', subM, 15, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);*/

// Profil
startMenu('m3', true, 135, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleProfil, 31);
addItem('Historique', '/francais/profil/historique.htm', '', subM, 15);
addItem('Mission', '/francais/profil/mission.htm', '', subM, 15);
addItem('Objectifs scientifiques', '/francais/profil/objectifs.htm', '', subM, 15);
addItem('Raison d\'&ecirc;tre et applications potentielles', '/francais/profil/applications.htm', '', subM, 30);
addItem('Gestion', '/francais/profil/gestion.htm', '', subM, 15);
//addItem('Chercheurs', '/francais/profil/chercheurs.htm', '', subM, 15);
addItem('&nbsp;', '', '', subMVideBottom,38);

// Demo
/*startMenu('m4', true, 135, -10, 150, subM);
addItem('&nbsp;', '/francais/demos/', '', subMTitleDemo,31);
addItem('Universit&eacute; de Sherbrooke', 'm4_s1', 'sm:', subM, 15);
addItem('Universit&eacute; de Montr&eacute;al', 'm4_s2', 'sm:', subM, 15);
addItem('&nbsp;', '', '', subMVideBottom,38);

// 2ieme niveau => UdeS
startMenu('m4_s1', true, 150, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleUdeS,31);
addItem('Atlas Search', '/francais/demos/UdeS.htm#AtlasSearch', '', subM, 15, 0, '', 3);
addItem('Autres...', '/francais/demos/UdeS.htm#Autres', '', subM, 15, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);

// 2ieme niveau => UdeM
startMenu('m4_s2', true, 150, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleUdeM,31);
addItem('Aucun', 'UdeM.htm', '', subM, 15, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);
*/
// Projets
/*startMenu('m5', true, 135, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleUdeS,31);
addItem('Interrogation et interface.', '/francais/projets/default.htm#interrogation-interface', '', subM, 15, 0, '', 3);
addItem('&Eacute;tude et mise en oeuvre des caract&eacute;ristiques bas-niveaux des images et des vid&eacute;os.', '/francais/projets/default.htm#features-low-level-img-video', '', subM, 60, 0, '', 3);
addItem('&Eacute;tudes et mise en oeuvre des caract&eacute;ristiques bas-niveaux de l\'audio.', '/francais/projets/default.htm#features-low-level-audio', '', subM, 45, 0, '', 3);
addItem('&Eacute;tudes et mise en oeuvre des caract&eacute;ristiques s&eacute;mantiques.', '/francais/projets/default.htm#features-hight-level', '', subM, 45, 0, '', 3);
addItem('Indexation.', '/francais/projets/default.htm#indexation', '', subM, 15, 0, '', 3);
addItem('&Eacute;tudes des standards des m&eacute;tadonn&eacute;es.', '/francais/projets/default.htm#standard-meta', '', subM, 30, 0, '', 3);
//addItem('&nbsp;', '', '', subM,38);
addItem('&Eacute;tude comportementale', '/francais/projets/default.htm#comportement', '', subM, 15, 0, '', 3);
addItem('Production de m&eacute;tadonn&eacute;es et de connaissances', '/francais/projets/default.htm#prod-meta', '', subM, 30, 0, '', 3);
addItem('Gestion du contenu num&eacute;rique', '/francais/projets/default.htm#contenu-num', '', subM, 30, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);
*/
/*startMenu('m5', true, 135, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleProjets,31);
addItem('Valorisation-Recherche Qu&eacute;bec (VRQ)', 'm5_s1', 'sm:', subM, 30);
addItem('CANARIE - Programme RAMI', 'm5_s2', 'sm:', subM, 30);
addItem('Patrimoine canadien - PCCE', 'm5_s3', 'sm:', subM, 30);
addItem('&nbsp;', '', '', subMVideBottom,38);

// 2ieme niveau => VRQ
startMenu('m5_s1', true, 150, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleUdeS,31);
addItem('Interrogation et interface.', '/francais/projets/vrq.htm', '', subM, 15, 0, '', 3);
addItem('&Eacute;tude et mise en oeuvre des caract&eacute;ristiques bas-niveaux des images et des vid&eacute;os.', '/francais/projets/vrq.htm', '', subM, 60, 0, '', 3);
addItem('&Eacute;tudes et mise en oeuvre des caract&eacute;ristiques bas-niveaux de l\'audio.', '/francais/projets/vrq.htm', '', subM, 45, 0, '', 3);
addItem('&Eacute;tudes et mise en oeuvre des caract&eacute;ristiques s&eacute;mantiques.', '/francais/projets/vrq.htm', '', subM, 45, 0, '', 3);
addItem('Indexation.', '/francais/projets/vrq.htm', '', subM, 15, 0, '', 3);
addItem('&Eacute;tudes des standards des m&eacute;tadonn&eacute;es.', '/francais/projets/vrq.htm', '', subM, 30, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);

// 2ieme niveau => CANARIE
startMenu('m5_s2', true, 150, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleUdeM,31);
addItem('Aucun...', '/francais/projets/canarie.htm', '', subM, 15, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);

// 2ieme niveau => PCCE
startMenu('m5_s3', true, 150, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleUdeM,31);
addItem('&Eacute;tude comportementale', '/francais/projets/pcce.htm#comportement', '', subM, 15, 0, '', 3);
addItem('Production de m&eacute;tadonn&eacute;es et de connaissances', '/francais/projets/pcce.htm#meta', '', subM, 30, 0, '', 3);
addItem('Gestion du contenu num&eacute;rique', '/francais/projets/pcce.htm#contenu', '', subM, 30, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);
*/
// Partenaires
//startMenu('m6', true, 140, -10, 250, subM);
//startMenu('m6', true, 140, -10, 150, subM);
//addItem('&nbsp;', '/francais/partenaires/', '', subMTitlePartenaires,31);
//addItem('Valorisation-Recherche Qu&eacutebec', '/francais/partenaires/default.htm#vrq', '', subM, 30, 0, '', 3);
//addItem('Patrimoine canadien', '/francais/partenaires/default.htm#patrimoine-canada', '', subM, 15, 0, '', 3);
//addItem('Universit&eacute de Sherbrooke', '/francais/partenaires/default.htm#UdeS', '', subM, 15, 0, '', 3);
//addItem('Copernic', '/francais/partenaires/default.htm#copernic', '', subM, 15, 0, '', 3);
//addItem('Laboratoire Universitaires Bell', '/francais/partenaires/default.htm#LUB', '', subM, 30, 0, '', 3);
//addItem('&nbsp;', '', '', subMVideBottom,38);

// Ressources
/*startMenu('m7', true, 135, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleRessources,31);
addItem('la liste', 'resources/resources.htm', '', subM, 15, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);
*/
//Section membres
/*startMenu('m8', true, 180, -10, 150, subM);
addItem('&nbsp;', '', '', subMTitleMembres,31);
addItem('la page de login et autres...', 'membres/membres.htm', '', subM, 30, 0, '', 3);
addItem('&nbsp;', '', '', subMVideBottom,38);
*/
}

/*
if (!isOp && navigator.userAgent.indexOf('rv:0.')==-1)
{
 pMenu.showMenu = new Function('mN','menuAnim(this, mN, 20)');
 pMenu.hideMenu = new Function('mN','menuAnim(this, mN, -20)');
}
*/

if (!isNS4)
{
 // Write menus now in non-NS4 browsers, by calling the "Fast" mode .update(true) method.
 pMenu.update(true);
 //anotherMenu.update(true);
}
else
{
 // For Netscape 4, back up the old onload function and make a new one to update our menus.
 // This is the regular "Dynamic" mode menu update, it works in IE and NS6 too if required.
 var popOldOL = window.onload;
 window.onload = function()
 {
  if (popOldOL) popOldOL();
  pMenu.update();
  //anotherMenu.update();
 }
}


// Other events must be assigned, these are less complicated, just add or remove menu objects.

var nsWinW = window.innerWidth, nsWinH = window.innerHeight, popOldOR = window.onresize;
window.onresize = function()
{
 if (popOldOR) popOldOR();
 if (isNS4 && (nsWinW!=innerWidth || nsWinH!=innerHeight)) history.go(0);
 pMenu.position();
 //anotherMenu.position();
}

window.onscroll = function()
{
 pMenu.position();
 //anotherMenu.position();
}


// NS4 can't reliably capture clicks on layers, so here's a workaround.
if (isNS4)
{
 document.captureEvents(Event.CLICK);
 document.onclick = function(evt)
 {
  with (pMenu) if (overI) click(overM, overI);
  //with (anotherMenu) if (overI) click(overM, overI);
  return document.routeEvent(evt);
 }
}

// Activate the window.onscroll() event in non-Microsoft browsers.
if (!isIE || isOp)
{
 var nsPX=pageXOffset, nsPY=pageYOffset;
 setInterval('if (nsPX!=pageXOffset || nsPY!=pageYOffset) ' +
 '{ nsPX=pageXOffset; nsPY=pageYOffset; window.onscroll() }', 50);
}

function menuAnim(menuObj, menuName, dir)
{
 // The array index of the named menu (e.g. 'mFile') in the menu object (e.g. 'pMenu').
 var mD = menuObj.menu[menuName][0];
 // Add timer and counter variables to the menu data structure, we'll need them.
 if (!mD.timer) mD.timer = 500;
 if (!mD.counter) mD.counter = 0;

 with (mD)
 {
  // Stop any existing animation.
  clearTimeout(timer);

  // If the layer doesn't exist (cross-frame navigation) quit.
  if (!lyr || !lyr.ref) return;
  // Show the menu if that's what we're doing.
  if (dir>0) lyr.vis('visible');
  // Also raise showing layers above hiding ones.
  lyr.sty.zIndex = 1001 + dir;


  // Clip the visible area. Tweak this if you want to change direction/acceleration etc.
    //  lyr.clip(0, 0, menuW+2, (menuH+2)*Math.pow(Math.sin(Math.PI*counter/200),0.75) );
        lyr.clip(0, 0, menuW+2, menuH+2);
  // Remove clipping in NS6 on completion, seems to help old versions.
  if ((isDOM&&!isIE) && (counter>=100)) lyr.sty.clip='';

  // Increment the counter and if it hasn't reached the end (10 steps either way),
  // set the timer to call the show/hide function again in 40ms.
  counter += dir;
  if (counter>100) counter = 100;
  else if (counter<0) { counter = 0; lyr.vis('hidden') }
  else timer = setTimeout(menuObj.myName+'.'+(dir>0?'show':'hide')+'Menu("'+menuName+'")', 40);
 }
}

// Here's the alternative IE5.5+ filter animation function.
function menuFilterShow(menuObj, menuName, filterName)
{
 var mD = menuObj.menu[menuName][0];
 with (mD.lyr)
 {
  sty.filter = filterName;
  var f = ref.filters;
  if (f&&f.length&&f[0]) f[0].Apply();
  vis('visible');
  if (f&&f.length&&f[0]) f[0].Play();
 }
}






