// JavaScript Document
sFadePeriod = 20; 
mainmenu_fade_step=0.1;
firstfade_step=0.003;

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()
var px = bw.ns4||window.opera?"":"px";

function makeObj(obj,nest){
	nest=(!nest) ? "":'document.'+nest+'.'		
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;		
	this.height=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.x = bw.ns4?this.css.left:this.el.offsetLeft;
	this.y = bw.ns4?this.css.top:this.el.offsetTop;
	return this
}

function UpdateOneObject(obj,new_ms)
{
	delta=obj.delta_fade*(new_ms-obj.start_ms);
	if (delta<1 && delta>-1)
		delta = (obj.delta_fade>0) ? 1 : -1;
	obj.fade+=delta;
		if (obj.fade>100)
			obj.fade=100;
		if (obj.fade<0)
			obj.fade=0;
	if (obj.fade==0 || obj.fade==100)
		obj.delta_fade=0;

		obj.obj.css.filter="alpha(opacity="+obj.fade+")";
		obj.obj.css.opacity=obj.fade/100;
}
function UpdateDisplay(new_ms)
{
	for (var i=0;i<nb_list;i++)
		if (list[i].delta_fade!=0) UpdateOneObject(list[i],new_ms);

}
function DisplayTimer()
{
	UpdateDisplay();

    tim = setTimeout("DisplayTimer()",sFadePeriod);
}
list=new Array();
nb_list=0;
function new_fadein_obj()
{
	this.obj=null;
	this.loaded=false;
	this.delta_fade=0;
	this.fade=0;
	list[nb_list++]=this;
	return this;
}
nb_menus=12;
function pre_init()
{
	menu=new Array();
	menu_back=new Array();
	for (var i=0;i<nb_menus;i++)
	{
		menu[i]=new new_fadein_obj();
		menu_back[i]=new new_fadein_obj();
	}
}

pre_init();

function initfade_obj(_obj,name)
{
	_obj.obj=new makeObj(name,'');
	_obj.obj.css.filter="alpha(opacity=0)";
	_obj.obj.css.opacity=0;
	_obj.fade=0;
	_obj.delta_fade=0;
}

function initfade_ref(_obj,ref)
{
	_obj.obj=ref;
	_obj.obj.css.filter="alpha(opacity=0)";
	_obj.obj.css.opacity=0;
	_obj.fade=0;
	_obj.delta_fade=0;
}

function internal_init()
{
	for (var i=0;i<nb_menus;i++)
	{
		initfade_obj(menu[i],'menu'+i);
		initfade_obj(menu_back[i],'menu'+i+'_back');
	}
}

function initFade()
{
	internal_init();
	
	DisplayTimer();
}

function initFadeManu()
{
	internal_init();
}

function start_fade_in_ms(obj,step,ms)
{
	obj.delta_fade=step;
	obj.start_ms=ms;
}
function start_fade_out_ms(obj,step,ms)
{
	obj.delta_fade=step;
	obj.start_ms=ms;
}

function start_fade_in(obj,step)
{
	var new_date=new Date();
	var ms=new_date.getTime();
	obj.delta_fade=step;
	obj.start_ms=ms;
}
function start_fade_out(obj,step)
{
	var new_date=new Date();
	var ms=new_date.getTime();
	obj.delta_fade=step;
	obj.start_ms=ms;
}


function GotoFrench()
{
	i=document.URL.lastIndexOf("_en.");
	new_name=document.URL.substr(0,i);
	new_name=new_name+"_fr.html";
	window.location.href=new_name;
}

function GotoEnglish()
{
	i=document.URL.lastIndexOf("_fr.");
	new_name=document.URL.substr(0,i);
	new_name=new_name+"_en.html";
	window.location.href=new_name;
}


