var is_NN4_ = false;
var is_IE4_ = false;
var is_IE5_ = false;
if ( parseInt(navigator.appVersion) >= 4 ) {
	is_IE4_ = ( navigator.appName.indexOf("Microsoft") != -1 );
	is_NN4_ = ( navigator.appName.indexOf("Netscape")	 != -1 );
	is_IE5_ = ( (navigator.appVersion.indexOf("MSIE") != -1) && (navigator.appVersion.indexOf("5.0") != -1) );
}

function show() { 
	this.layer.visibility = "visible";
}

function hide() { 
	this.layer.visibility = "hidden";
}

function mouseOver() { 
	if ( this.state < 2 ){
		this.idle.hide();
		this.active.show(); 
		this.state = 1;
	}
}

function mouseOut() { 
	if ( this.state < 2 ){
		this.active.hide();
		this.idle.show();
		this.state = 0;
	}
}

function unselect() { 
	if ( this.state == 2 ){
		this.active.hide();
		this.idle.show();
		this.state = 0;
	}
}

function itemClick() { 
	if ( this.state < 2 ) {
		this.menu.selectItem(this);
		this.state = 2;
		this.idle.customclick();
	}
	return(true);	
}

function genstyle(d,id) {
	if( ! is_NN4_ ) return; 
	d.writeln(	  '<STYLE TYPE="text/css">'
			+ '#' + id 
			+ ' {position: absolute; visibility: hidden;}'
			+ '</STYLE>' );
}

function genhtml(classObj, doc, obj, divId, cssClass, bgcolor, labelprefix) {
	var instance =	classObj + ".instances['" + obj.id + "']";
	var deltax   =  0;		
	var width;				
	if ( classObj == 'Item' ) {
		deltax = obj.menu.deltax;
		width = obj.menu.width - 5;
	} else {
		width = obj.width - 5;
	}
	width -= deltax;
	var	html;
	if( is_NN4_ ) {
		html = '<span id="' + divId + '">';
	} else {
		html = '<div id="' + divId + '" style="position:absolute; visibility:hidden;">';
	}
	html += '<table width="' + width +'" border="0" cellspacing="0" cellpadding="0"><tr>'
		+ '<td'
		+ (bgcolor? (' bgcolor="' + bgcolor + '"') : '')
		+ ' class="'	+ cssClass + '">';
	html += '<a class="'	+ cssClass + '" href="'	+ obj.url	+ '" '
		+ (obj.target ? ('target="'	+ obj.target+ '" ') : '')
		+ 'onClick="return(' + instance + '.click());" '
		+ 'onMouseOver="return(' + instance + '.over());" '
		+ 'onMouseOut="return(' + instance + '.out());">'
		+ labelprefix + obj.label
		+ '</a>';
	html += '</td></tr></table>';
	if( is_NN4_ ) {
		html += '</span>';
	} else {
		html += '</div>';
	}
	doc.writeln(html);
	return(is_NN4_ ? (doc[divId] ? doc[divId] : doc.getElementById(divId).style) : doc.all[divId].style );
}

Item.instances = new Array();
Item.prototype.dump = function() {
	var texte = 'itemdump(' + this.id + ')\n';
	texte += 'visibility(idle): ' + this.idle.layer.visibility + '\n';
	if ( is_NN4_ ) {
		texte += 'top(idle): ' + this.idle.layer.top +'\n';
		texte += 'left(idle): ' + this.idle.layer.left +'\n';
	} else {
		texte += 'top(idle): ' + this.idle.layer.pixelTop +'\n';
		texte += 'left(idle): ' + this.idle.layer.pixelLeft	 +'\n';
	}
	texte += 'visibility(active): ' + this.active.layer.visibility + '\n';
	if ( is_NN4_ ) {
		texte += 'top(active): ' + this.active.layer.top +'\n';
		texte += 'left(active): ' + this.active.layer.left +'\n';
	} else {
		texte += 'top(active): ' + this.active.layer.pixelTop +'\n';
		texte += 'left(active): ' + this.active.layer.pixelLeft +'\n';
	}
	confirm(texte);
}

function Item(menu, id, label, url, target, customclick, bgcolor, cssClass) {
	this.menu	=	menu;
	this.window	=	menu.window;
	this.id		=	id;
	this.label	=	label;
	var nbreaks =	label.match(/<br>/gi);
	this.nlines	=	( nbreaks != null ) ?  nbreaks.length + 1 : 1;
	this.url	=	url;
	this.customclick=function(){( customclick && eval(customclick)) || 'true' };
	this.target	=	target;
	this.state	=	0;		
	this.css	=	cssClass + 'Idle';
	this.bgcolor=	bgcolor;
	Item.instances[id] = this;
	var d		= 	window.document;
	genstyle(d,id);
	var active	=	new Object();
	active.id	=	id + "over";
	genstyle(d,active.id);
	active.state=	0;
	active.css	=	cssClass + 'Active';
	active.bgcolor=	bgcolor;
	active.show =	show;
	active.hide =	hide;
	active.dump =	Item.prototype.dump;
	active.over		=	mouseOver;
	active.out		=	mouseOut;
	active.click	=	itemClick;
	active.unselect	=	unselect;
	this.idle		=	this;
	this.active		=	active;
	active.idle		=	this;
	active.active	=	active;
	return(this);
}

Item.prototype.output = function() {
	var doc = this.window.document;	
	this.idle.layer = genhtml('Item', doc, this, this.id, this.css, this.bgcolor, '&nbsp;');
	this.idle.hide();
	this.active.layer = genhtml('Item',
					doc,
					this,
					this.active.id,
					this.active.css,
					this.active.bgcolor,
					'&gt;');
	this.active.hide();
}

Item.prototype.show = show;
Item.prototype.hide = hide;
Item.prototype.over = mouseOver;
Item.prototype.out = mouseOut;
Item.prototype.click = itemClick;
Item.prototype.unselect	= unselect;
Item.prototype.setLocation = function(x,y) {
	if (is_NN4_) {
		this.idle.layer.left	= x;
		this.idle.layer.top		= y;
		this.active.layer.left	= x;
		this.active.layer.top	= y;
	} else {
		this.idle.layer.pixelLeft	= x;
		this.idle.layer.pixelTop	= y;
		this.active.layer.pixelLeft	= x;
		this.active.layer.pixelTop	= y;
	}
}

Menu.instances = new Array();
Menu.prototype.dump = function() {
	var texte = 'menudump(' + this.id + ')\n';
	texte += 'expanded: ' + this.expanded + '\n'
	texte += 'visibility(idle): ' + this.idle.layer.visibility + '\n';
	if ( is_NN4_ ) {
		texte += 'top(idle): ' + this.idle.layer.top +'\n';
		texte += 'left(idle): ' + this.idle.layer.left +'\n';
	} else {
		texte += 'top(idle): ' + this.idle.layer.pixelTop +'\n';
		texte += 'left(idle): ' + this.idle.layer.pixelLeft	 +'\n';
	}
	texte += 'visibility(active): ' + this.active.layer.visibility + '\n';
	if ( is_NN4_ ) {
		texte += 'top(active): ' + this.active.layer.top +'\n';
		texte += 'left(active): ' + this.active.layer.left +'\n';
	} else {
		texte += 'top(active): ' + this.active.layer.pixelTop +'\n';
		texte += 'left(active): ' + this.active.layer.pixelLeft +'\n';
	}
	confirm(texte);
	if ( this.items != null ) {
		for (var i=0; i < this.items.length; i++) {
			var item = this.items[i];
			item.dump();
		}
	}
}

function Menu(	window, id, label, url, target, customclick, bgcolor, width, cssMenu, cssItem, menuhl, itemhl, deltax, deltay) {
	this.window	=	window;
	this.id		=	id;
	this.label	=	label;
	var nbreaks =	label.match(/<br>/gi);
	this.nlines	=	( nbreaks != null ) ?  nbreaks.length + 1 : 1;
	this.url	=	url;
	this.target	=	target;
	this.customclick=function(){( customclick && eval(customclick)) || 'true' };
	this.bgcolor=	bgcolor;
	this.width  =	width;
	this.css	=	cssMenu + 'Idle';
	this.menuhl	=	menuhl;
	this.itemhl	=	itemhl;
	this.deltax	=	deltax;
	this.deltay	=	deltay;
	this.expanded	=	0;
	this.state	=	0;		
	this.height_expanded	=	
	this.height_schrunk	=	menuhl * this.nlines;	
	Menu.instances[id] = this;
	var d		= 	window.document;
	genstyle(d,id);
	var active	=	new Object();
	active.id	=	id + "over";
	active.state=	0;
	active.bgcolor	=	bgcolor;
	active.css	=	cssMenu + 'Active';
	active.show =	show;
	active.hide =	hide;
	active.dump =	Menu.prototype.dump;
	active.over			=	mouseOver;
	active.out			=	mouseOut;
	active.click		=	menuClick;
	active.unselect		=	unselect;
	genstyle(d,active.id);
	this.idle		=	this;
	this.active		=	active;
	active.idle		=	this;
	active.active	=	active;
	this.items	=	new Array();
	for (var i=14; i < arguments.length; i+=5) {
		var n = this.items.length;
		this.items[n] = new Item(
					this,
					arguments[i],	
					arguments[i+1],	
					arguments[i+2],	
					arguments[i+3],	
					arguments[i+4],	
					bgcolor,
					cssItem
					);
		this.height_expanded += deltay + (this.items[n].nlines * itemhl);
	}
	this.actifItem = null;	
	return(this);
}

Menu.prototype.output = function() {
	var doc = this.window.document;	
	this.idle.layer = genhtml('Menu', doc, this, this.id, this.css, this.bgcolor, '&nbsp;');
	this.idle.hide();
	this.active.layer = genhtml('Menu',
					doc,
					this,
					this.active.id,
					this.active.css,
					this.active.bgcolor,
					'&gt;');
	this.active.hide();
	for ( var i=0; i < this.items.length; i++ ) {
		this.items[i].output();
	}
}

Menu.prototype.show			=	show;
Menu.prototype.hide			=	hide;
Menu.prototype.over			=	mouseOver;
Menu.prototype.out			=	mouseOut;
Menu.prototype.unselect		=	unselect;
Menu.prototype.setLocation	=	function(x,y) {
	if ( is_NN4_ ) {
		this.idle.layer.top		= y;
		this.idle.layer.left	= x;
		this.active.layer.top	= y;
		this.active.layer.left	= x;
	} else {
		this.idle.layer.pixelTop		= y;
		this.idle.layer.pixelLeft	= x;
		this.active.layer.pixelTop	= y;
		this.active.layer.pixelLeft	= x;
	}
	x += this.deltax;
	y += (this.menuhl * this.nlines) + this.deltay;
	for ( var i=0; i < this.items.length; i++ ) {
		this.items[i].setLocation(x,y);
		y += (this.itemhl * this.items[i].nlines) + this.deltay;
	}
}

Menu.prototype.selectItem	=	function (item) {
	if ( this.state == 2 ) {
		this.unselect();
	} else {
		if ( this.actifItem ) this.actifItem.unselect();
	}
	this.actifItem = item;
}

Menu.prototype.expand	=	function(x,y) {
	if (arguments.length > 1) this.setLocation(x,y);
	if ( ! this.expanded ) {
		for ( var i=0; i < this.items.length; i++ ) {
			this.items[i].show();
		}
		this.expanded = 1;
	}
}

Menu.prototype.schrink	=	function() {
	if ( this.expanded ) {
		if ( this.actifItem ) { 
			this.actifItem.unselect();
			this.actifItem = null;
		}
		for ( var i=0; i < this.items.length; i++ ) {
			this.items[i].hide();
		}
		this.unselect();
		this.expanded = 0;
	}
}

Menu.prototype.getheight =	function() {
	var height = this.expanded ? this.height_expanded : this.height_schrunk;
	return(height);
}

function menuClick() {
	if ( ! this.expanded ) {
		this.menuset.selectMenu(this);
		this.over();
		this.state = 2;
		this.idle.customclick();
		this.actifItem = null;
	} else {
		if ( this.state != 2 ) {
			if ( this.actifItem ) { 
				this.actifItem.unselect();
				this.actifItem = null;
			}
			this.state = 2;
			this.idle.customclick();
		}
	}
}

Menu.prototype.click	=	menuClick;
Setmenus.instances = new Array();
function Setmenus (id, topx, topy, deltay) {
	this.id		= id;
	this.topx	= topx;
	this.topy	= topy;
	this.deltay	= deltay;
	Setmenus.instances[id] = this;
	this.menus = new Array();
	for (var i=4; i < arguments.length; i++) {
		var menu = arguments[i];
		menu.menuset = this;	
		this.menus[this.menus.length] = menu;
	}
	this.actifMenu = null;
	return(this);
}

Setmenus.prototype.selectMenu	= function(menu) {
	if ( menu != this.actifMenu ) {
		var i, m, x, y;
		for ( i=0 ; i < this.menus.length ; i++ ) {
			m = this.menus[i];
			m.schrink();
			m.hide();
		}
		x = this.topx;
		y = this.topy;
		for ( var i=0 ; i < this.menus.length ; i++ ) {
			var m = this.menus[i];
			m.setLocation(x,y);
			m.show();
			if ( m == menu ) {
				m.expand();
			}
			y += m.getheight() + ( this.deltay * 2);
		}
		this.actifMenu = menu;
	}
}

Setmenus.prototype.output	= function() {
	
	for ( var i=0 ; i < this.menus.length ; i++ ) {
		this.menus[i].output();
	}
}

Setmenus.prototype.debug = function() {
	win = window.open('','Debug','resizable,scrollbars,height=450,width=500');
	win.document.open( 'text/plain' );
	win.document.writeln( debug );
	win.document.close();
	win.focus();
}

Setmenus.prototype.dump	= function() {
	var i, m, x, y;
	for ( i=0 ; i < this.menus.length ; i++ ) {
		m = this.menus[i];
		m.dump();
	}
}

function banner(rubrique,chapitre,logo) {
	if (top) {
		if ( top.banner ) {
			var bannerdoc = top.banner.document;
			if (rubrique) {
				bannerdoc.rubrique.src = rubrique;
			}
			if (chapitre) {
				bannerdoc.chapitre.src =  chapitre;
			}
			if (logo) {
				bannerdoc.logo.src =  logo;
			}
		} 
	} 
}


