/**********************************************************************************
SlideMenu 2.0
*   Copyright (C) 2002 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli
*
*Script date: 08/20/2002 (keep this date to check versions)

** Feel free to remove all comments in this file (and the HTML file)
** as long the copyright message is intact to make the files smaller.
*********************************************************************************/
// ------------------------------------------------------------------------------
// FB modification:       Style and background depending on the row position
// 
// The Rows of a defined level can be customized with spécial styles and background images.
// If the style name or the images names used for a level contain "%curr%", "%top%" or
// "%root%" strings, these strings are changed with 
//     - the row position in the curent level for "%curr%"
//     - the row position of the top(parent) level for "%top%"
//     - the row position of the root level for "%root%"
// (search for "// FB bg modif" comments in the script to find the changes)
// example:
// For the third position item of the second root item: 
//             src="bg_%curr%.gif" is changed to  src="bg_3.gif"
//             class="style_%root%_%curr%" is changed to class="style_2_3"
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// FB modification:       Positionning a level on the side of the menu
// 
// In order to shift a level on the side of the menu: Two parameters (isSideLevel,
// sideBetween) are added to the level setting. 
// To shift the level on the side, use the "left" attribute, to shift the top level position (down or up), 
// use "sideShiftTop" attribute. isSideLevel must be set to 1 in order to shift the level on the side.
// (search for "// FB side modif" comments in the script to find the changes)
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// Rooivalk & thomas Brattli modification: to close the current opened level
// (search for "// Rooivalk" comments in the script to find the changes)
// ------------------------------------------------------------------------------
/************************************************************************************
Making cross-browser objects
************************************************************************************/
function makeMenuObj(obj,nest,rang){           // FB modification : a new parameter, rang. 
	nest=(!nest) ? "":'document.'+nest+'.'
	rang=(!rang) ? 0:rang   // FB
	this.evnt = document.getElementById?document.getElementById(obj):document.all?document.all[obj]:document.layers?eval(nest+'document.'+obj):0;	
	this.css = this.evnt.style?this.evnt.style:this.evnt;										
	this.ref=document.layers?this.evnt.document:document;		
	this.x=this.css.left||this.evnt.offsetLeft;
	this.y=this.css.top||this.evnt.offsetTop;		
	this.hideIt=b_hideIt; this.showIt=b_showIt; this.movey=b_movey
	this.moveIt=b_moveIt; this.moveBy=b_moveBy; this.status=0; 
	this.bgImg=b_bgImg;	this.obj = obj + "Object"; eval(this.obj + "=this"); 
	this.clipTo=b_clipTo;
	this.rang=rang;                            // FB modification : initializing rang attribute
	return this
}
function b_showIt(){this.css.visibility="visible"; this.status=1}
function b_hideIt(){this.css.visibility="hidden"; this.status=0}
function b_movey(y){this.y=y; this.css.top=this.y}	
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x;this.css.top=this.y}
function b_moveBy(x,y){this.x=this.x+x; this.y=this.y+y; this.css.left=this.x;this.css.top=this.y}
function b_bgImg(img){
	if(document.getElementById) document.getElementById(this.id+"_img").src = img
	else if(document.layers) this.ref.layers[0].document.images[0].src = img
	else document.images[this.id+"_img"].src = img
}
function b_clipTo(t,r,b,l,w){if(document.layers){this.css.clip.top=t;this.css.clip.right=r
this.css.clip.bottom=b;this.css.clip.left=l
}else{this.css.clip="rect("+t+"px,"+r+"px,"+b+"px,"+l+"px)"; if(w){this.css.pixelWidth=this.css.width=r; this.css.pixelHeight=this.css.height=b}}}

/********************************************************************************
Initiating page, making objects..
********************************************************************************/
createSlideMenu.prototype.init = function(){
	document.write("</div>")
	this.cont=new makeMenuObj(this.name+'cont')
	this.cont.moveIt(this.menux,this.menuy)
	var yy = 0, el 	//Make top menus
	for(var j=0;j<this.topmenus.length;j++){
		el = this.menus[this.topmenus[j]]
		el.rootNum =j;
		el.o = new makeMenuObj(this.name+"_"+el.num,this.name+"cont",j)
		el.o.moveIt(this.l[0].left,yy); el.top = j; el.origy = yy
		el.o.id = el.id; el.o.status=1; 
		el.o.h = this.l[0].height; 
		el.img = this.l[0].regImage;
		el.img.replace(/%curr%/g,j);           // FB bg modification 
		el.img.replace(/%top%/g,j);           // FB bg modification                    
		el.img.replace(/%root%/g,j);          // FB bg modification  
		yy+=el.o.h + this.l[0].between; el.o.clipTo(0,this.l[0].width,el.o.h,0,1)
		if(j!=this.topmenus.length-1)	el.nexttop = this.topmenus[el.top+1] 
		this.loop(el.num,j)
	}
	this.cont.showIt(); this.cont = null; this.level = null;
}
createSlideMenu.prototype.loop = function(num,j){
	var el = this.menus[num],temp,p,h,w,y,img
	el.rang = j;                                                      // FB bg modification
	for(var i=0;i<el.childs.length;i++){
		temp = el.childs[i]
		w = this.l[temp.lev].width; h = this.l[temp.lev].height
		y = el.o.y+el.o.h + h*i + this.l[temp.lev].between*i + this.l[temp.lev].between +  this.l[temp.lev].sideBetween
		temp.o = new makeMenuObj(this.name+"_"+temp.num,this.name+"cont",i)
		temp.o.hideIt(); temp.o.clipTo(0,w,h,0,1)
		temp.o.moveIt(this.l[temp.lev].left,y)
		el.endy =y+h; temp.origy = y
		temp.o.zIndex=temp.num
		temp.o.h = h; temp.top = j 
		temp.chnum = i; temp.o.id = temp.id 
		temp.rootNum = el.rootNum;
		temp.rang = i;
		if(this.useImages){ //Setting bgimage
			img=""
			if(temp.childs.length>0){ //With subs
				if(i==el.childs.length-1){ img=this.l[temp.lev].subRound; img=img.replace(/%curr%/g,temp.chnum); img=img.replace(/%root%/g,el.rootNum); img=img.replace(/%top%/g,el.rang);}                  // FB bg modification
				else { img=this.l[temp.lev].subImg; img=img.replace(/%curr%/g,temp.chnum); img=img.replace(/%root%/g,el.rootNum); img=img.replace(/%top%/g,el.rang); }                                        // FB bg modification
			}else	if(i==el.childs.length-1){
				img=this.l[temp.lev].roundImg2; img=img.replace(/%curr%/g,temp.chnum); img=img.replace(/%root%/g,el.rootNum); img=img.replace(/%top%/g,el.rang);                                          // FB bg modification
			}
			if(img){
				temp.o.bgImg(img.replace(/%curr%/g,temp.chnum).replace(/%root%/g,temp.rootNum).replace(/%top%/g,el.rang) );
				temp.img = img.replace(/%curr%/g,temp.chnum).replace(/%root%/g,temp.rootNum).replace(/%top%/g,el.rang) ;                           // FB bg modification
			}else temp.img = this.l[temp.lev].regImage.replace(/%curr%/g,temp.chnum).replace(/%root%/g,temp.rootNum).replace(/%top%/g,el.rang)     // FB bg modification
		}
		p = this.menus[temp.parent] //Setting the next elements
		if(temp.chnum != p.childs.length-1){ //Not the last el
			temp.nextel = p.childs[temp.chnum+1].num
			temp.nexttop = temp.lev==1?p.nexttop:p.nextel
		}else{ //Last el, so we only have nexttop
			temp.nexttop = p.nextel
			if(temp.nexttop==-1) temp.nexttop = p.nexttop
		}
		if(temp.childs.length>0){
			this.loop(temp.num,j) //Recursive call
		}	
	}
}

/********************************************************************************
Moving all objects in the array after a provided array number
********************************************************************************/
createSlideMenu.prototype.moveItems = function(px,num){
	for(i=num;i<this.menus.length;i++){
		if(this.menus[i].o.status){ //Moving all visible menus
			this.menus[i].o.movey(this.menus[i].o.y+px)
		}
	}	
}
/********************************************************************************
Switch menu function.
********************************************************************************/
createSlideMenu.prototype.switchMenu = function(num){	
if(this.going) return
	var m = this.menus[num]
    // if(m.childs.length==0) return;              // FBZ   la sortie directe si pas d'enfants est désactivé (Pb. Septembre)
	this.going = 1
	var y=m.o.y+ m.o.h +this.l[m.lev].between
	var clnum = m.num, olev = m.lev, onext = m.nextel
	if(this.active[0]>-1){
		var n = -1
		if(m.lev>0){
			if(this.active[m.lev]>-1) n=this.active[m.lev]
			else n=this.active[m.lev-1]
		}else n = this.active[0]
		m = this.menus[n]
		if(m.lev == 0 && olev==0) y = m.nexttop!=-1?this.menus[m.nexttop].origy:-1
		else if(clnum!=m.num){
			var ny = m.o.y + m.o.h + this.l[m.lev].between
			if(clnum>m.num && olev==m.lev) y = Math.min(ny,y)
			else	if(onext==m.num) y = Math.max(ny,y)
		}
	}
	this.moveUp(m.nextel!=-1?m.nextel:m.nexttop,num,y);
}


/********************************************************************************
Switch sub menu function.
********************************************************************************/
createSlideMenu.prototype.switchSubMenu = function(num){	
	var m = this.menus[num];
	
	for(var i=m.lev;i<this.active.length;i++){    // Reset images - actives et cetera
		if(this.active[i]>-1){
			var temp = this.menus[this.active[i]]
			var ch = temp.childs
			for(var j=0;j<ch.length;j++){
				ch[j].o.hideIt();
				ch[j].o.movey(ch[j].origy);
			}
			this.active[i] = -1
		}
	}
	for(var i=0;i<m.childs.length;i++){ //Show all
		m.childs[i].o.movey(m.childs[i].o.y) +this.l[m.lev+1].sideBetween    // FB side modif. sideLevel; move childs items hhhh  +this.l[m.lev+1].sideBetween
		m.childs[i].o.showIt()
		if(!this.l[m.lev+1].isSideLevel){
			y = m.childs[i].o.y + m.childs[i].o.h;
		}                         
	}
	this.active[m.lev] = num;
}


/********************************************************************************
Switch page function.
********************************************************************************/
createSlideMenu.prototype.switchPage = function(num){	
	//charger le lien que si l'on est sur la page non active (menu clické différent de menu ouvert) 
	var m = this.menus[num]
	if(num==this.numActivePage){  // avant:  this.active[m.lev]
	  }
	else{
	  document.location.href=m.activeLink; 
	  }
}
/********************************************************************************
Move items up
********************************************************************************/
createSlideMenu.prototype.moveUp = function(top,num,y){
	var move = 0, m, yy=0
	var yshift = 0
	if(this.active[0]>-1 && top>-1){
		m = this.menus[top]
		if(m.o.y>y){
			if((m.o.y-this.pxspeed)<y) yy = -(((m.o.y-y)))
			else yy=-this.pxspeed; this.moveItems(yy,top)
			move=1
		}
	}
	if(move){ 
		setTimeout(this.name+".moveUp("+top+","+num+","+y+")",this.timspeed)
	}
	else{
		m = this.menus[num] 
		var stopit=num == this.active[m.lev]?1:0       // Rooivalk modif : to close the current opened level  
		for(var i=m.lev;i<this.active.length;i++){    // Reset images - actives et cetera
			if(this.active[i]>-1){
				temp = this.menus[this.active[i]]
				temp.o.moveIt(temp.o.x-this.inset,temp.o.y)			
				if(this.useImages) 
				temp.o.bgImg(temp.img.replace(/%root%/g,temp.rootNum).replace(/%curr%/g,temp.rang).replace(/%top%/g,m.rang) ) 		              // FB bg modif.  !!!! 
				if(this.arrow) temp.ar.replaceChild(document.createTextNode("4"),temp.ar.childNodes[0])
				ch = temp.childs
				for(var j=0;j<ch.length;j++){
					ch[j].o.hideIt(); ch[j].o.movey(ch[j].origy)           
				}
				this.active[i] = -1
			}
		}
		//Then open the current one, if childs
		if((m.childs.length == 0 || stopit) && m.lev==0 ){this.going = 0; return}    // Rooivalk modif : to close the current opened level  ("if(m.childs.length == 0 || stopit") added
		for(i=0;i<m.childs.length;i++){ //Show all
			m.childs[i].o.movey(m.childs[i].o.y) +this.l[m.lev+1].sideBetween    // FB side modif. sideLevel; move childs items hhhh  +this.l[m.lev+1].sideBetween
			m.childs[i].o.showIt()
			if(!this.l[m.lev+1].isSideLevel){y = m.childs[i].o.y + m.childs[i].o.h }                         
		}
        //y+=this.l[m.lev+1].sideBetween                                          // FB side modif. sideLevel; move next items 
		y+=this.l[m.lev].between
		if(m.lev>0 && m.chnum!=this.menus[m.parent].childs.length-1){   
			yy=y ; 
			y = this.menus[m.parent].endy + this.l[m.lev].between     
		}
		m.o.moveIt(m.o.x+this.inset,m.o.y) 	//Inset current item:
		if(this.useImages) m.o.bgImg(this.l[m.lev].roundImg.replace(/%curr%/g,m.rang).replace(/%top%/g,m.parent.rang).replace(/%root%/g,m.rootNum)) 	   // FB bg modification
		this.active[m.lev] = num //Set active
		if(this.arrow) m.ar.replaceChild(document.createTextNode("6"),m.ar.childNodes[0])
		if(m.nexttop>-1 || m.nextel>-1){
             // Si le rang précédent a été décallé, décaller les rangs suivants
			 this.moveDown(m.nexttop,m.nextel,y,yy-this.l[m.lev].height)  // FBZ bug septembre       yy+this.l[m.lev+1].sideBetween // Then start moving all others elements down
		     }
		else this.going=0
	}
}


/********************************************************************************
showChilds
********************************************************************************/
createSlideMenu.prototype.showChilds = function(num){

	m = this.menus[num];
	//if childs show them
	if(m.childs.length != 0 ){
		for(i=0;i<m.childs.length;i++){ //Show all
			m.childs[i].o.showIt();
		    }
    }
}
/********************************************************************************
hideChilds
********************************************************************************/
createSlideMenu.prototype.hideChilds = function(num){

	m = this.menus[num];
	//if childs hide them
	if(m.childs.length != 0 ){
		for(i=0;i<m.childs.length;i++){ //Hide all
			m.childs[i].o.hideIt();
		    }
    }
}


/********************************************************************************
Move items down
********************************************************************************/
createSlideMenu.prototype.moveDown = function(top,num,y,yyy){
	var m = this.menus[top],yy
	if(m && m.o.y<y){
		if((m.o.y+this.pxspeed)>y) yy = y-m.o.y
		else yy=this.pxspeed
		this.moveItems(yy,top)
		setTimeout(this.name+".moveDown("+top+","+num+","+y+","+yyy+")",this.timspeed)
	}else if(num>-1){
		this.moveDown(num,-1,yyy,0)
	}else this.going=0
}
/********************************************************************************
Slide menu object
********************************************************************************/
function createSlideMenu(name){
	document.write('<div id="'+name+'cont">') //The cont div start
	this.name = name
	this.menus = new Array()
	this.curr = 0
	this.lasttype = new Array()
	this.writesubsonly = 0
	this.level = new Array()
	this.l = new Array()
	this.topmenus = new Array()
	this.active = new Array()
	this.numActivePage = -1
	return this
}
/********************************************************************************
Function to create the objects and the divs
********************************************************************************/
createSlideMenu.prototype.makeMenu = function(type,text,lnk,target,end){
	var str="",tg="",parent,m,cl
	m = this.menus[this.curr] = new Object();
	if(this.lasttype[type]!=null){prev=this.lasttype[type];}else{prev=-1;}  // hhhh;
	this.lasttype[type] = this.curr; if(!lnk) lnk="#"
	m.lev = 0; m.type = type; m.childs = new Array()
	m.num = this.curr; m.parent = -1; m.nextel = -1
	m.nexttop = -1; parent = 0
    m.rang = 0; m.rootNum = 0;      // FB bg modification
	m.text = text
	m.activeLink=lnk;
	m.prev = prev;              // hhhh

	if(type.indexOf("sub")>-1){ 	//Find parent type
		if(type.length == 3){ //sub
			parent = "top"; m.lev = 1
		}else{
			parent = type.substr(3,1) //sub2+
			m.lev = parent; parent--
			if(parent==1){
				parent = "sub"; m.lev = 2
			}else parent = "sub"+parent
		}	
	}
  if(m.lev>=this.l.length){//Level control (same as CM4)
    var p1,p2=0; 
		if(m.lev>=this.level.length) p1=this.l[this.level.length-1];
    else p1=this.level[m.lev]; 
		this.l[m.lev]=new Array(); 
		if(!p2) p2=this.l[m.lev-1]
    if(m.lev!=0 && p1){ 
      for(i in p1){ //Copying an entire object
				if(p1[i]==null) this.l[m.lev][i]=p2[i]; 
				else this.l[m.lev][i]=p1[i]
			}
    }else{
			this.l[m.lev]=this.level[0]; 
		}
    this.level[m.lev]=p1=p2=null 
  } 
	this.active[m.lev] = -1
	if(parent){ //Find parent element
		m.parent = this.lasttype[parent]
		parent = this.menus[this.lasttype[parent]]
		m.rang = parent.childs.length;      // FB bg modification  
		m.rootNum = parent.rootNum;         // FB bg modification   
		parent.childs[parent.childs.length] = m
		// m.prev = m.parent.childs[m.parent.childs.length-1].num;
		if(this.arrow && parent.childs.length==1){str='<span class="'+this.arrow+'">4</span>'
			if(document.getElementById && document.getElementById(parent.id).childNodes){
				parent.ar = document.getElementById(parent.id).childNodes[this.useImage?1:0].childNodes[0]
				parent.ar.innerHTML = str+parent.ar.innerHTML; parent.ar=parent.ar.childNodes[0]} else this.arrow=""
		     }
	       }
		else {
		   this.topmenus[this.topmenus.length] = this.curr; 
	       m.rang=this.topmenus.length-1;
		   m.rootNum=this.topmenus.length-1;
		   }
	if(!this.writesubsonly || type!="top"){
		// comportement différent en fonction du niveau ... "alert('prev:"+this.menus[this.curr].prev+", num:"+this.menus[this.curr].num+"');"
		if(m.lev==0){
			actionOnClick  = this.name+".switchMenu("+this.curr+"); ";
	    actionOnClick += this.name+".switchPage("+this.curr+"); ";
			actionOnClick += "  if(document.getElementById) this.blur(); ";
			if(lnk=="#") actionOnClick += " return false ";
           actionOnMouseOver="";
					 actionOnMouseOver="hideSubSubItems();";
		}
    if(m.lev==1){
    	actionOnClick  = this.name+".switchPage("+this.curr+"); ";
			actionOnClick += " if(document.getElementById) this.blur(); ";
                     
			//actionOnMouseOver  = this.name+".switchMenu("+this.curr+"); ";  
			actionOnMouseOver  = this.name+".switchSubMenu("+this.curr+"); ";    
			actionOnMouseOver += " if(document.getElementById) this.blur(); ";					 
			// actionOnMouseOver  = this.name+".hideChildsSameLevel("+this.curr+"); "+this.name+".switchMenu("+this.curr+"); ";
			// +this.name+".switchMenu("+this.curr+"); "					 
			// actionOnMouseOver += " if(document.getElementById) this.blur(); ";
    }
		if(m.lev==2){actionOnClick  = this.name+".switchPage("+this.curr+"); ";
					 actionOnClick += " if(document.getElementById) this.blur(); ";
                     actionOnMouseOver="";
					 }
		if(m.lev==3){actionOnClick  = this.name+".switchPage("+this.curr+"); ";
					 actionOnClick += " if(document.getElementById) this.blur(); ";
                     actionOnMouseOver="";
					 }
		cl = this.l[m.lev].className.replace(/%curr%/g,m.rang);    // FB bg modif.; spécific style if "%" charcater used in class name  
		cl = cl.replace(/%root%/g,m.rootNum);
		cl = cl.replace(/%top%/g,parent.rang);
		m.id = id = this.name + "_" + this.curr
		str= '<div id="'+id+'" class="'+cl+'" >' //main div start
		if(this.useImages){
			str+='<div class="'+this.bgClass+'">'//bgdiv
			str+='<img id="'+id+'_img" src="'+this.l[m.lev].regImage.replace(/%curr%/g,m.rang).replace(/%root%/g,m.rootNum).replace(/%top%/g,parent.rang)+'" />'       // FB bg modification, m.rang 
			str+='</div>' //bgdiv
		}
		if(target) tg =' target="'+target+'" '
		str+='<div class="'+this.txtClass+'"><TABLE width="'+this.l[m.lev].width+'" border="0" ><TR><TD width="'+(this.l[m.lev].height/2)+'">&nbsp;</TD><TD width="'+(this.l[m.lev].width-this.l[m.lev].height/2)+'" align="left">';
		str+='<a href="#" '+tg+' onClick= "'+actionOnClick+'" onMouseOver="'+actionOnMouseOver+'" ';
        str+='" class="'+this.l[m.lev].classNameA+'"> '+text+'</a></TD></TR></TABLE></div>\n'
		str+="</div>\n\n" // main div end
		document.write(str)
		//alert('str='+str);
	}
	this.curr++
}

/********************************************************************************
Level object
********************************************************************************/
function slideMenu_makeLevel(){
  var c=this, a=arguments; 
	c.left=a[0]||0; c.width=a[1]||null; c.height=a[2]||null;
	c.between=a[3]||null; c.className=a[4]||null; c.classNameA=a[5]||null;
	c.regImage=a[6]||null; c.roundImg=a[7]||null; c.roundImg2=a[8]||null; 
	c.subImg=a[9]||null; c.subRound=a[10]||null; 
	c.isSideLevel=a[11]||null;                            // FB side modif. Use it with c.left in order to fold a level on the side
	c.sideBetween=a[12]||null;                            // FB side modif. Relative height between this level and the previous one
	return c
}
/********************************************************************************
Preloading images
********************************************************************************/
function preLoadBackgrounds(){
  for(i=0;i<arguments.length;i++){
    this[i]=new Image()
    this[i].src=arguments[i]
  }
  return this
}
/********************************************************************************
Hiding items of level 2 wich overlay on the content area
********************************************************************************/
function hideSubSubItems(){
   if(slideMenu.active[1]!=-1){ slideMenu.hideChilds(slideMenu.active[1]); } 
}
