function installControl (contValue) {
  if (document.getElementById("p_control")){
		document.getElementById("p_control").firstChild.nodeValue = contValue;
	} else {
		var newControl = document.createElement('p');
		var newConText = document.createTextNode(contValue);
		newControl.setAttribute("id", "p_control");
		newControl.appendChild(newConText);
		document.getElementById("produitTextes").style.fontSize = "8pt";
		document.getElementById("produitTextes").appendChild(newControl);
	}
}
function pDetailsLinks (Bildweite, n, rectWidth) {
	LinksCorr = 325 + (n*rectWidth); 
	if (Bildweite > rectWidth) {
		switch (n) {
			case 0:
				LinksCorr = LinksCorr;
				break;
			case 3:
				LinksCorr = LinksCorr - Bildweite + rectWidth;
				break;
			default:
				LinksCorr = LinksCorr - Math.floor((parseInt(Bildweite) + rectWidth)/2) + rectWidth;
		}
	}
return corr = LinksCorr + 'px';
}
function pTitleLinks (Bildweite, n, rectWidth) {
	LinksCorr = (n*rectWidth); 
	if (Bildweite > rectWidth) {
		switch (n) {
			case 0:
				LinksCorr = LinksCorr;
				break;
			case 3:
				LinksCorr = LinksCorr - Bildweite + rectWidth;
				break;
			default:
				LinksCorr = LinksCorr - Math.floor((parseInt(Bildweite) + rectWidth)/2) + rectWidth;
		}
	}
return corr = LinksCorr + 'px';
}
function hibande (thisOne) {
	// alert("hibande(): thisOne " +thisOne);
  if (document.getElementById){
    document.getElementById("bande"+thisOne).style.backgroundColor = hiColor;
	}else{
	alert("hibande(): else");
	}
}
function lowbande (thisOne) {
	if (document.getElementById){
    document.getElementById("bande"+thisOne).style.backgroundColor = lowColor;
	}else{
	alert("lowbande(): else");
	}
}
function getImgNumber(){
	rawNum = isBig + listPosition;
	if (fileHere == "multi") {
		while (rawNum >= io.length ){
			rawNum = rawNum - io.length;
		}
	} else {
		while (rawNum >= iq.length ){
			rawNum = rawNum - iq.length;
		}
	}
return rawNum;
}
function show (thisOnePos) {
	getthisonePos = thisOnePos;
	if (actualChapter == 'historique') rectWidth = 69; else rectWidth = 103;
	if( io[thisOnePos] ){
		if( hell=io[thisOnePos].src.match(/pics\/produits\/empty.gif/)!= 'pics/produits/empty.gif'){
			if (document.getElementById){
				document.getElementById("produitDetails").style.visibility = "hidden";
				document.getElementById("produitTextes").style.visibility = "hidden";
				isBig = thisOnePos;
				thisOne = getImgNumber();
				if( thisOnePos < a_title.length){
					if (fileHere == "multi") {
						document.getElementById("produitDetails").style.left=pDetailsLinks (ipW[thisOne], thisOnePos, rectWidth);
						document.getElementById("produitTextes").style.left=pDetailsLinks (ipW[thisOne], thisOnePos, rectWidth);
						document.getElementById("imgBig").width=ipW[thisOne];  //ipW to iqW
						document.getElementById("imgBig").src=ip[thisOne].src;  //ipW to iqW
						if ((actualChapter == 'historique' && rub == 1) || (actualChapter == 'thompson' && rub == 2)) {
							document.getElementById("p_title").style.position='relative';
							document.getElementById("p_title").style.left=pTitleLinks (ipW[thisOne], thisOnePos, rectWidth);
						document.getElementById("produitTextes").style.left='321px';
						} else document.getElementById("produitTextes").style.left=pDetailsLinks (ipW[thisOne], thisOnePos, rectWidth);
					}
					if (fileHere == "single") {
						document.getElementById("imgBig").style.width= iqW[thisOne]  + 'px';
						bugsy = (parseInt(iqW[thisOne] ) + 30);
						document.getElementById("produitDetails").width=0 + px; 
						document.getElementById("imgBig").width=iqW[thisOne];  //ipW to iqW
						document.getElementById("imgBig").src=iq[thisOne].src;  //ipW to iqW
					}
					document.getElementById("p_title").firstChild.nodeValue= a_title[thisOne];
					document.getElementById("p_texte").firstChild.nodeValue= a_des[thisOne];
					if (actualChapter != 'historique' && actualChapter != 'thompson') document.getElementById("p_fin").firstChild.nodeValue= a_fin[thisOne];
				}
			}else{
				alert("show(): else");
			}
			document.getElementById("produitDetails").style.visibility = "visible";
			document.getElementById("produitTextes").style.visibility = "visible";
		}
	}
}
function makeParas (nodeId, txtArray) {
  var newBr = new Array();
	var newText = new Array	();
	for (var inum = 0; inum < txtArray.length; inum++){
		newBr[inum] = document.createElement("br");
		newText[inum] = document.createTextNode(txtArray[inum]);
		if (inum == 0) document.getElementById(nodeId).firstChild.nodeValue= txtArray[inum];
		else {
		document.getElementById(nodeId).appendChild(newBr[inum]) ;
		document.getElementById(nodeId).appendChild(newText[inum]) ;
		}
	}
}
function showP (thisOnePos) {
	if (document.getElementById){
			document.getElementById("produitDetails").style.visibility = "hidden";
			isBig = thisOnePos;
			thisOne = getImgNumber();
			if( thisOnePos < a_title.length){
				if (fileHere == "multi") {
					document.getElementById("produitDetails").style.left=pDetailsLinks (ipW[thisOne], thisOnePos, 103);
					document.getElementById("imgBig").width=ipW[thisOne];  //ipW to iqW
					document.getElementById("imgBig").src=ip[thisOne].src;  //ipW to iqW
				}
				if (fileHere == "single") {
					document.getElementById("imgBig").style.width = iqW[thisOne]  + 'px';
					bugsy = (parseInt(iqW[thisOne] ) + 72);
					document.getElementById("firefox1").style.width = bugsy+ 'px'; 
					if(document.getElementById("flecheDroite"))document.getElementById("flecheDroite").style.left = bugsy - 25 + 'px'; 
					document.getElementById("imgBig").width=iqW[thisOne];  //ipW to iqW
					document.getElementById("imgBig").src=iq[thisOne].src;  //ipW to iqW
				}
				document.getElementById("p_title").firstChild.nodeValue= a_title[thisOne];
				makeParas("p_texte",a_des[thisOne]);
				if (actualChapter != 'historique' && actualChapter != 'thompson') document.getElementById("p_fin").firstChild.nodeValue= a_fin[thisOne];
			}
		}else{
			alert("show(): else");
		}
		document.getElementById("produitDetails").style.visibility = "visible";
}
function showM (thisOnePos) {
	if (document.getElementById){
		isBig = thisOnePos;
		thisOne = getImgNumber();
		document.getElementById("illus_img").src=io[thisOne].src;
	}else{
		alert("showM(): else");
	}
}
function buildImgBande (nofive) {
  if ( ! nofive) nofive = 4; 
	if (document.getElementById){
		x = listPosition;
		z = 1;
		y = 0;
		for (i=x; i<x+nofive; i++){
			if (i < io.length) {
				document.getElementById("product"+(z++)).src= io[i].src; 
			} else {
				document.getElementById("product"+(z++)).src= io[y++].src; 
			}
		}
	}else{
		alert("buildImgBande(): else");
	}
}
function changePage () {
window.location.href = "magasins.php?actualChapter=actualites&rub=" + rub +"&listPosition=" + listPosition;
}
function listUpM () {
	switch (actualChapter) {
		case 'actualites':
			if (rub < rub.length-1) rub++; else rub = 0;
				changePage();
			break;
		case 'magasins':
			if (listPosition < io.length - 1) listPosition = listPosition +1; else listPosition = 0;
			showM(isBig);
			break;
	}
}
function listDwnM () {
	switch (actualChapter) {
		case 'actualites':
			if (listPosition > 0) listPosition = listPosition -1; else listPosition = vrubLien.length-1;
				changePage();
			break;
		case 'magasins':
			if (listPosition > 0) listPosition = listPosition -1; else listPosition = io.length-1;
			showM(isBig);
			break;
	}
}
counter = 0;
function listUp (theImgArray) {
if (fileHere == "multi" ) {
		if (listPosition < theImgArray.length - 1) listPosition = listPosition +1; else listPosition = 0;
		buildImgBande();
		show(isBig);
	} else {
		if (isBig < (theImgArray.length - 1)) isBig = isBig + 1; else isBig = 0;
		showP(isBig);
	}
}
function listDwn (theImgArray) {
	if (fileHere == "multi" ) {
		if (listPosition > 0) listPosition = listPosition -1; else listPosition = theImgArray.length-1;
		buildImgBande();
		show(isBig);
	} else { 
		if (isBig > 0) isBig = isBig -1; else isBig = theImgArray.length-1;
		showP(isBig);
	}
}
function toggleImgView (whichFile) {
	isBig= getImgNumber (isBig + listPosition);
	listPosition = 0;
	if (fileHere == "single" ) {
		if (iq.length<4){
			listPosition = 0;
			isBig= isBig;
		}else{
			listPosition = isBig;
			isBig= 0;
		}
		window.location.href = whichFile + "?actualChapter=" + actualChapter + "&lang=" + lang + "&rub=" + rub + "&listPosition=" + listPosition+ "&isBig=" + isBig;
	} else { 
	isBig= getImgNumber (isBig + listPosition);
	listPosition = 0;
	window.location.href = whichFile + "?actualChapter=" + actualChapter + "&lang=" + lang  + "&rub=" + rub + "&isBig=" + isBig;
	}
}
function toggleImgViewProducts (whichFile) {
	isBig= getImgNumber (isBig + listPosition);
	listPosition = 0;
	if (fileHere == "single" ) {
		if (iq.length<4){
			listPosition = 0;
			isBig= isBig;
		}else{;
			listPosition = isBig;
			isBig= 0;
		}
		window.location.href = whichFile + "?actualChapter=" + actualChapter + "&lang=" + lang + "&rub=" + rub + "&rubPosition=" + rubPosition + "&listPosition=" + listPosition+ "&isBig=" + isBig;
	} else { 
	isBig= getImgNumber (isBig + listPosition);
	listPosition = 0;
	window.location.href = whichFile + "?actualChapter=" + actualChapter + "&lang=" + lang  + "&rub=" + rub + "&rubPosition=" + rubPosition + "&isBig=" + isBig;
	}
}
function initiate (nofive) {
	if (fileHere == "multi" ) {
		buildImgBande(nofive);
		show(isBig);
	} else {
		showP (isBig);
	}
}
function preparePage(nofive){
	if (document.getElementById){
		initiate(nofive);
	}else{
		alert("preparePage(): else");                                                       
	}
}
