// ------ Interactivité du site Iberbook ------------------------------------------------------------------------------------
// ------ Chaine = fx(langue utilisateur) ------
// chooseLanguage("fr", "Texte en Français", "es", "Texto en Español",.......);
function chooseLanguage(){
	var langue= new Array();
	var textAff= new Array();
	var toAff="";
	if (typeof(navigator.language)!="undefined")var currentLanguage=navigator.language
		else if (typeof(navigator.userLanguage)!="undefined")var currentLanguage=navigator.userLanguage
				else if (typeof(navigator.browserLanguage)!="undefined")var currentLanguage=navigator.browserLanguage
					else	var currentLanguage="en";
	currentLanguage=(currentLanguage.substring(0,2));	
	for(i=0;i<chooseLanguage.arguments.length;i=i+2){
		if(currentLanguage==chooseLanguage.arguments[i]){
			toAff=chooseLanguage.arguments[i+1];	
		}
	}
	if(!toAff){toAff=chooseLanguage.arguments[1];};
	document.write(toAff);
}

// ------ Affichage automatique du Titre ------
function changeTitle(obj){
	var newTitle=obj.document.title;
	window.top.frames.titulo.Ltitulo.innerHTML=newTitle;
}

// ----- RollOver des Listes dans tableaux ----------------------------------------------------------------------------------
// rollOVer(this, new_Style);
function rollOver(obj,stl){
	 obj.className=stl;
}

// ------ Scrolling Layer ---------------------------------------------------------------------------------------------------
// ------ Initialisation des calques ------
//scrollInit(lName, posX, posY, tX, tY, indZ, lStyle, stepX, delay, innerText)
// lName		: new layer namer
// posX		: absolute left position of the new layer
// posY		: absolute top position of the new layer
// tX		: new layer width
// tY		: new layer height
// indZ 		: z-idex of the new layer
// lStyle		: CSS style of the new layer
// stepX		: shift definition for the new layer
// delay		: time between two shifts
// innerText	: displayed html in the new layer

function scrollInit(lName, posX, posY, tX, tY, indZ, lStyle, stepX, delay, innerText){
	// ------ Création des calques ------
	document.write('<DIV ID="'+lName+'A" STYLE="position:absolute; left:'+posX+'px; top:'+posY+'px; width:'+tX+'px; height:'+tY+'px; z-index:'+indZ+'; visibility: visible;" CLASS="'+lStyle+'">');
	document.write(innerText);
	document.write('</DIV>');	
	document.write('<DIV ID="'+lName+'B" STYLE="position:absolute; left:'+(posX+tX)+'px; top:'+posY+'px; width:'+tX+'px; height:'+tY+'px; z-index:'+indZ+'; visibility: visible;" CLASS="'+lStyle+'">');
	document.write(innerText);
	document.write('</DIV>');
	// ------ Appel de la fonction de scrolling ------
	scrolLay(lName+"A", stepX, delay);
	scrolLay(lName+"B", stepX, delay);
}

// ------ Scrolling des calques ------
//scrollInit(lName, posX, posY, tX, tY, indZ, lStyle, stepX, delay, innerText)
// lName		: new layer namer
// stepX		: shift definition for the new layer
// delay		: time between two shifts
function scrolLay(Lname, stepX, delay){
	ShortL=document.all[Lname].style;
	maxX=ShortL.width;	
	maxX=Number(maxX.slice(0,maxX.length-2));
	minX=-1*maxX;
	if(ShortL.pixelLeft-stepX>minX){
		ShortL.pixelLeft-=stepX;	
	}
	else{
		ShortL.pixelLeft=maxX;
	}
	setTimeout("scrolLay('"+Lname+"',"+stepX+","+delay+")",delay);
}

// ------ Menu --------------------------------------------------------------------------------------------------------------
// ------ Ajout d'une rubrique comportant des sous rubriques------
function DynamicMenu_addParent(strName,strURL) {
	var strID = 'ID' + intCount++;
	var strTemp = '<DIV ID="' + strID + '" CLASS="parent"';
	strTemp += 'STYLE="width:'+menuWidth+'"';
	strTemp += ' onClick="openClose(this);window.top.frames[menuTarget].location=\''+strURL+'\'"  onMouseOver="rollOver(this,\'parentON\')" onMouseOut="rollOver(this,\'parent\')">';
	strTemp += '<IMG SRC="images/fldroite.gif">';
	strTemp += '&nbsp;' + strName ;
	strTemp += '<DIV STYLE="display: none; width:'+menuSubWidth+'" CLASS="child"></DIV>';
	strTemp += '</DIV>';
	this.div.innerHTML += strTemp;
	this.currentChild = document.getElementById(strID);
}

// ------ Ajout d'une rubrique vide------		  
function addEmptyParent(strName,strURL) {
	var strID = 'ID' + intCount++;
	var strTemp = '<DIV ID="' + strID + '" CLASS="parent"';
	strTemp += 'STYLE="width:'+menuWidth+'px;" onClick="openClose(\'\');window.top.frames[menuTarget].location=\''+strURL+'\'" onMouseOver="rollOver(this,\'parentON\')" onMouseOut="rollOver(this,\'parent\')">';
	strTemp += '<IMG SRC="images/dummy.gif" WIDTH="12">';
	strTemp += '&nbsp;' + strName+'</DIV>';	
	this.div.innerHTML += strTemp;
}

// ------Ajout de liens dans le menu ------
function DynamicMenu_addChild(strName,strURL) {
	var strTemp = '<TABLE WIDTH="'+(2*menuSubWidth-menuWidth+12)+'" BORDER="0" CELLSPACING="0" CELLPADDING="0" ALIGN="CENTER"><TR>';
	strTemp += '<TD HEIGHT="'+menuSubHeight+'" VALIGN="MIDDLE" ALIGN="LEFT" CLASS="child"';
	strTemp += 'onMouseOver="rollOver(this,\'childON\')" onMouseOut="rollOver(this,\'child\')" onClick="cancelBubble(arguments[0]);window.top.frames[menuTarget].location=\''+strURL+'\'">';
	strTemp += menuDecal+strName+'</TD></TR></TABLE>';
	if (document.all) {
		this.currentChild.children[1].innerHTML += strTemp;
	} else {
		this.currentChild.childNodes[2].innerHTML += strTemp;
	}
}

// ------ Inhibe la cascade d'évènements au DIV conteneur ------
function cancelBubble(netEvent) {
	if (document.all) {
		window.event.cancelBubble = true;
	} else {
		netEvent.cancelBubble = true;
	}
}

// ------ Contracte ou expanse le menu ------
function expandCollapse(nextObjElement) {	
	if (document.all) {
		var imgIconNext = nextObjElement.children[0];
		nextObjElement = nextObjElement.children[1];		
	} else {
		var imgIconNext = nextObjElement.childNodes[0];
		nextObjElement = nextObjElement.childNodes[2];
	}		
	if (nextObjElement.style.display == "none") {  
		nextObjElement.style.display = "block" ;
		imgIconNext.src = "images/flbas.gif" ;
	} else {
		nextObjElement.style.display = "none" ;
		imgIconNext.src = "images/fldroite.gif" ;
	}
}

// ------ Gestion type de deroulement du menu ------
function openClose(thisItem){
	if(aloneItem==1){
		if(toCollapse!=""){
			expandCollapse(toCollapse);	
		}
		if(thisItem!=""){		
			if(toCollapse==thisItem){
				toCollapse="";
			} else {
				expandCollapse(thisItem);
				toCollapse=thisItem;
			}
		} else {
			toCollapse="";
		}
	} 
	if(aloneItem!=1 && thisItem!=""){
			expandCollapse(thisItem);
	}
}

// ------ Création de menu dynamique ------
function DynamicMenu() {
	var id = "Menu" + intCount++;
	document.write('<DIV Id="' + id + '"></DIV>');
	this.div = document.getElementById(id);
	this.currentChild = null;
	this.addParent = DynamicMenu_addParent;
	this.addChild = DynamicMenu_addChild;
	this.addEmptyParent = addEmptyParent;
}
