// Animation
var modeAff= Array();
modeAff['initmenu']=false;
modeAff['squizzy']=false;

var tStyle= Array();

var tA= Array();
tA['timerID'] = 0;
tA['tCote'] = 0;
tA['tStart']  = null;
tA['tTimer'] = 75;
tA['tPas'] = 4;
tA['tSens'] =1;

var mA= Array();
mA['mPas1']=2;
mA['mPas-1']=1;
mA['mMax']=8;
mA['mBorder']='Px solid #edb449';

var titlteencours;
var titlteencourspos;

function initmenu(){
	if(document.getElementById('ulmenu')){
		modeAff['initmenu']=!modeAff['initmenu'];
		if(modeAff['initmenu']){
			tmp=document.getElementById('ulmenu').getElementsByTagName('li');
			mA['mNb']=tmp.length;
			for(var i=0;i<mA['mNb'];i++) {
				tmp[i].id='ulmenuli'+i;
				tmp[i].onmouseover=function(){mA[this.id+'sens']=1;movediv(this);this.style.background="#F3F3F3";}
				tmp[i].onmouseout=function(){mA[this.id+'sens']=-1;movediv(this);this.style.background="none";}
				tmp[i].onclick=function(){document.location.href=this.getElementsByTagName('a')[0].href;}
				tmp[i].style.cursor='pointer';
				mA[tmp[i].id]=false;
				tStyle[tmp[i].id]='';
			}
		}else{
			for(var i=0;i<mA['mNb'];i++) {
				tmp[i].onmouseover=null;
				tmp[i].onmouseout=null;
			}
			
		}
		
	}
}
var tp= Array();
tp['b1']='1px solid #CCCCCC';
tp['b2']='1px solid #333333';
tp['m1']='1px 0px 1px 1px';
tp['m2']='2px -1px 0px 2px';
tp['max']=10;
tp['sm']=Array();
tp['ss']=Array();

function inittopsel(){
	if(document.getElementById('topselint')){
		tp['elt']=document.getElementById('topselint');
		a=tp['elt'].getElementsByTagName('div');
		for(var i=0;i<a.length;i++) {
			a[i].id='tpd'+i;
			a[i].style.margin=tp['m1'];
			a[i].style.border=tp['b1'];
			a[i].onmouseover=function(){
				this.style.border=tp['b2'];
				this.style.margin=tp['m2'];
			};
			a[i].onmouseout=function(){this.style.border=tp['b1']; this.style.margin=tp['m1']};
		}
	}
}
var somtdbact="#EAEAEA";

function initpage(){
	document.getElementById('pleasewaitScreen').style.visibility='hidden';
	switchdivbaspagepre(false);
	for(var i=1;i<=4;i++) {
		eval("document.getElementById('nav"+i+"').onmouseover=function(){ navmouv(this,1);}");
		eval("document.getElementById('nav"+i+"').onclick=function () {navclick(this);}");
		eval("document.getElementById('nav"+i+"').onmouseout=function(){ navmouv(this,-1);}");
	}
	if(document.getElementById('divtimer')){
		document.getElementById('divtimer').innerHTML+='<div id="divcpt">&nbsp;</div>'
		+'<div style="float:left;clear:both; width:100%; text-align:center">'
		+'<a href="#" onclick="(tA[\'tStart\']==null)?StartTimer():StopTimer();return(false);">'
		+'Web Présence Plus</a>'
		+'<div id="autres">' //<a href="#" onclick="initmenu();return(false);">&gt; anim. menu</a>'
		+'<a href="#" onclick="modeAff[\'squizzy\']=!modeAff[\'squizzy\'];return(false);">&gt; anim. squizzy</a>'+
		'<a href="#" onClick="SetCookie(\'kitgr\',\'2\');window.location.reload(); return(false);">&gt; changer de kit</a>'+
		//'<a href="#" onClick="framepage(); return(false);">&gt; Le Labo (bétâ)</a>'+
		'</div></div>';	
		document.getElementById('divtimer').onmouseover=function(){
			document.getElementById('autres').style.display="block";
		}		
		document.getElementById('divtimer').onmouseout=function(){
			document.getElementById('autres').style.display="none";
		}
		StartTimer();
		initmenu();
		setTimeout("inittopsel()",500);
	}
	if(document.getElementById('ptitre')){
		document.getElementById('ptitreban').innerHTML=document.getElementById('ptitre').innerHTML;
		document.getElementById('ptitre').style.display="none";
		CSBfleXcroll("cttctt");
	}
	if(document.getElementById('tablesommaire')){
		var tmp=document.getElementById('tablesommaire').getElementsByTagName('a');
		var tmphtml='<a name="tablesommairefcs" id="tablesommairefcs"></a><table cellpadding="0" cellspacing="0"><tr>';
		for(var i=0;i<tmp.length;i++) 
			tmphtml+='<td width="'+Math.floor(100/tmp.length)+
			'%" id="tablesomtd'+i+'" height="22"><a href="#" onClick="ptxtaff('+i+'); return(false);">'+
			tmp[i].innerHTML+'</a></td>';
		tmphtml+='</tr></table>';
		document.getElementById('tablesommaire').innerHTML=tmphtml;
		ptxtaff(0);
	}
	var tmp=document.getElementById('cttctt').getElementsByTagName('table');
	if(tmp[0].className=="p_txt navrech" || tmp[0].className=="p_txt  navrech"){
		var tmphtml='<div id="divnavrech" class="p_txt navrech">';
		var tmp2=tmp[0].getElementsByTagName('td');
		for(var i=0;i<tmp2.length;i++) {
			tmphtml+='<div>'+tmp2[i].innerHTML+'</div>';
			tmp2[i].innerHTML='<img src="./common/t.gif" height="5">';
		}
		tmphtml+='</div>';
		document.getElementById('ptitrebanctt').innerHTML+=tmphtml;
		//tmp[0].style.display='none';
		//CSBfleXcroll("cttctt");
	};
	
		// récupérer les liens
	var tabliens=document.getElementsByTagName('a');
	//alert(tabliens.length);
	// on parcourt tout les liens
	for(var i=0; i<tabliens.length;i++)	{
		if(tabliens[i].title.length>0){
			tabliens[i].onmouseover=function(){
				titlteencours=this.title;
				this.title='';
				afficheInfoBulle(titlteencours);
			}
			tabliens[i].onmousemove=Bulle;
			tabliens[i].onmouseout=function(){
				if(titlteencours.length>0) this.title=titlteencours;
				masqueinfoBulle();
			}
		}
	}
	if(document.getElementById('infosbasdepage')){
		var tabliens=document.getElementById('infosbasdepage').getElementsByTagName('a');
		for(var i=0; i<tabliens.length;i++)	{
			if(tabliens[i].title.length>0){
				tabliens[i].onmouseover=null;
				tabliens[i].onmousemove=null;
				tabliens[i].onmouseout=null;
				tabliens[i].title='';
			}
		}
	}
	titlteencours='';
	titlteencourspos=Array();
}
function movediv(elt){
	if(mA[elt.id]==false) mA[elt.id]=(mA[elt.id+'sens']==1)?0:mA['mMax'];
	mA[elt.id]+=mA[elt.id+'sens']*mA['mPas'+mA[elt.id+'sens']];
	if(mA[elt.id]<0) mA[elt.id]=0;
	if(mA[elt.id]>mA['mMax']) mA[elt.id]=mA['mMax'];
	elt.getElementsByTagName('a')[0].style.borderLeft=mA[elt.id]+mA['mBorder'];
	if(mA[elt.id]==0 && mA[elt.id+'sens']==-1 || mA[elt.id]==mA['mMax'] && mA[elt.id+'sens']==1) mA[elt.id]=false;
}

function StartTimer() {
   tA['tStart']   = 0;
   document.getElementById('divcpt').style.width = "1%";
   document.getElementById('divcpt').className="classleft";
   tA['timerID']  = setTimeout("UpdateTimer()", tA['tTimer']);
}
function StopTimer() {
   if(tA['timerID']) {
      clearTimeout(tA['timerID']);
      timerID  = 0;
   }
   tA['tStart'] = null;
}
function UpdateTimer() {
   if(tA['timerID']) {
      clearTimeout(tA['timerID']);
   }
   tA['tStart']+=tA['tPas']*tA['tSens'];
   if(tA['tStart']>=99) {tA['tCote']++;tA['tStart']=99;tA['tSens']=-1;}
   if(tA['tStart']<=1) {tA['tCote']++;tA['tStart']=1;tA['tSens']=1;}
   if(tA['tStart']==99 || tA['tStart']==0) {
		if(tA['tCote']==5) tA['tCote']=1;
		if(tA['tCote']==1) document.getElementById('divcpt').className="classright";
		if(tA['tCote']==3) document.getElementById('divcpt').className="classleft";
	}
   document.getElementById('divcpt').style.width = tA['tStart']+"%";
   
	if(modeAff['initmenu']) {
		for(var i=0;i<mA['mNb'];i++) {
			if(mA['ulmenuli'+i]!=false) movediv(document.getElementById('ulmenuli'+i)); 
			if(!modeAff['squizzy'] && tStyle['ulmenuli'+i].length>0) {
				eval("document.getElementById('ulmenuli'+i).style."+tStyle['ulmenuli'+i]+";");
				tStyle['ulmenuli'+i]='';
			}
		}
	}
	if(modeAff['squizzy']) squizzy();
   tA['timerID']  = setTimeout("UpdateTimer()", tA['tTimer']);
}


function ptxtaff(pav){
	var tmp=document.getElementById('tablesommaire').getElementsByTagName('td');
	for(var i=0;i<tmp.length;i++){
		if(i==pav){
			tmp[i].style.background=somtdbact+" url(./css/tablesomtdactfd.gif) bottom center no-repeat";
			tmp[i].onmouseover=function(){}
			tmp[i].onmouseout=function(){}
		}else{
			tmp[i].style.background='transparent';
			tmp[i].onmouseover=function(){this.style.background=somtdbact;}
			tmp[i].onmouseout=function(){this.style.background="transparent";}
		}
		tmp[i].onclick=function(){ptxtaff(this.id.substr(this.id.length-1,this.id.length)); return(false);}
	}
	tmp=document.getElementById('cttctt').getElementsByTagName('table');
	var tmptbl= new Array();
	for(var i=1;i<tmp.length;i++)
		if(tmp[i].className=="tablep_txt") tmptbl.push(tmp[i]);
	for(var i=0;i<tmptbl.length;i++){
/*		if(i==pav){
			tmptbl[i].style.visibility="visible";
			tmptbl[i].style.position="relative";
		}else {
			tmptbl[i].style.visibility="hidden";
			tmptbl[i].style.position="absolute";
			tmptbl[i].style.top="0px";
			tmptbl[i].style.left="2px";
			tmptbl[i].style.width="479px";
		}*/
		if(i==pav)
			tmptbl[i].style.display="block";
		else tmptbl[i].style.display="none";
		tmp=tmptbl[i].getElementsByTagName('p')[0]||false;
		if(tmp!=false) 
			tmp.style.display="none";//tmp.innerHTML='<img src="./common/t.gif" height="5">';
		
	}
	CSBfleXcroll("cttctt");
	document.getElementById('tablesommairefcs').focus();	
}
function squizzy(){
	for(var i=0;i<mA['mNb'];i++) {
		tStyle['ulmenuli'+i]="borderTop='1px solid transparent'";
		tmp=160+parseInt(Math.random()*71);
		document.getElementById('ulmenuli'+i).style.borderTop="1px solid rgb("
			+tmp+","+tmp+","+tmp+")";
	}
	movebandimg();
}
function navmouv(elt,dep){
	t=elt.style;
	t.margin=(parseInt(t.marginTop)+dep)+"Px "+
	 (parseInt(t.marginRight)-dep)+"Px "+
	 (parseInt(t.marginBottom)-dep)+"Px "+
	 (parseInt(t.marginLeft)+dep)+"Px";
}
function navclick(elt){
	document.location.href=elt.getElementsByTagName('a')[0].href;
}

function switchdivbaspagepre(etat){
	if(etat){
		document.getElementById('divbaspage').style.display='block';
		document.getElementById('divbaspagepre').style.display='none';	
	}else{
		document.getElementById('divbaspage').style.display='none';
		document.getElementById('divbaspagepre').style.display='block';	
	}
}

function framepage(){
	//alert(document.childNodes[0].innerHTML);
	if(typeof(document.childNodes[1].childNodes[2])=='undefined') //ie
		tmpfr=document.childNodes[0];
	else tmpfr=document.childNodes[1].childNodes[2]; //firefox
	var fset = document.createElement("frameset");
	fset.setAttribute("cols","*, 180");
	fset.setAttribute("border","0");
	fset.setAttribute("noresize",1);
	var f1 = document.createElement("frame");
	f1.setAttribute("src",document.location.href);
	f1.setAttribute("name","f1");
	var f2 = document.createElement("frame");
	f2.setAttribute("src","./css/labo.html");
	f2.setAttribute("name","f2");
	f2.setAttribute("border",0);
	f2.setAttribute("scrolling","no");
	fset.appendChild(f1);
	fset.appendChild(f2);
	document.childNodes[1].replaceChild(fset,tmpfr);
	if(document.frames){
		document.frames[0].name="f1";
		document.frames[1].name="f2";
		fset.frameborder="none";
		//parent.frames[0].style.border="none";
		parent.frames[0].noresize="noresize";
		//parent.frames[1].style.border="none";
		parent.frames[1].noresize="noresize";
		document.frames[0].document.location.href=document.location.href;
		//document.frames[1].refresh();
	}else{
		parent.frames[0].document.location.href=document.location.href;
		parent.frames[1].name='f2';
	}
}

function movebandimg(){
	document.getElementById('divbandeau2').getElementsByTagName('img')[0].style.marginRight=parseInt(Math.random()*10)+"Px";
}

function Bulle(e) { // Pour afficher l'infobulle sur différents navigateurs
	if (navigator.appName!="Microsoft Internet Explorer") { // Firefox
		document.getElementById("infobulle").style.left=e.pageX + 15+"px";
		document.getElementById("infobulle").style.top=e.pageY + 20+"px";
	}else{ // Agis sur IE 7
		document.getElementById("infobulle").style.left=10+event.clientX+document.body.scrollLeft+"px";
		document.getElementById("infobulle").style.top=20+event.clientY+document.body.scrollTop+"px";
	}
}
function afficheInfoBulle(txt) {
	 document.getElementById("infobulle").style.visibility="visible";
	 document.getElementById("infobulletxt").innerHTML = txt;
}
 
function masqueinfoBulle() {
	 document.getElementById("infobulle").style.visibility="hidden";
	 document.getElementById("infobulletxt").innerHTML = '';
}