/* swap
********************/
var swapList = new Array();

function initSwap(){
	var pureText = document.getElementById("puretext");
	if(!pureText) return;
	var triggers = pureText.getElementsByTagName("h2");
	var targets = pureText.getElementsByTagName("div");
	var loopI = (triggers.length>=targets.length)?(triggers.length):(targets.length);
	for (var i=0; i<loopI; ++i){
		swapList.push([triggers[i], targets[i]]);
		triggers[i].onclick = swap;
		triggers[i].style.cursor = "pointer";
		targets[i].style.height = "0";
		targets[i].style.overflow = "hidden";
	}
}

function swap(){
	for (var i=0; i<swapList.length; ++i){
		if (swapList[i][0]==this){
			(swapList[i][1].style.height !== 'auto')?(swapList[i][1].style.height = 'auto'):(swapList[i][1].style.height = '0');
		}else{
			swapList[i][1].style.height = '0';
		}
	}
}

/* clearOnFocus
********************/
function clearOnFocus(el){
	var toClear = document.getElementById(el);
	if(!toClear) return;
	toClear.onfocus = function(){ this.value=""; };
}

/* swapPic
********************/
function swapPic(){
	document.getElementById("big").src = this;
}

function initSwapPic(){
	var swapZone = document.getElementById("imgprod");
	if(!swapZone) var swapZone = document.getElementById("plusimgprod");
	if(!swapZone) return;
	var triggers = swapZone.getElementsByTagName("a");
	for (var i=0; i<triggers.length; ++i){
		if(triggers[i].id == "popmore"){
			triggers[i].onclick = function(){
				var popup = window.open('plusdimages.php','pics','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,width=440,height=550,left=50,top=50');
				return false;
			};
		} else {
			triggers[i].onclick = function(){ return false; };
			triggers[i].onmouseover = swapPic;
		}
	}
}

/* flowScroll
********************/
function flowScroll(goLeft){
	var offset = (goLeft)?-2:2;
	var flowCut = document.getElementById("flowcut");
	flowCut.scrollLeft += offset;
}
function initFlowScroll(){
	var flow = document.getElementById("flow");
	if(!flow) return;
	document.getElementById("defilgauche").onmouseover = function(){ scrollDirection = setInterval("flowScroll(true)", 4); };
	document.getElementById("defildroite").onmouseover = function(){ scrollDirection = setInterval("flowScroll(false)", 4); };
	document.getElementById("defilgauche").onmouseout = function(){ clearInterval(scrollDirection); };
	document.getElementById("defildroite").onmouseout = function(){ clearInterval(scrollDirection); };
	var items = flow.getElementsByTagName("a");
	flow.style.width = items.length*52 + 4 + "px";
}

/* init
********************/
window.onload = function(){
	initFlowScroll();
	initSwapPic();
	clearOnFocus("qte");
	clearOnFocus("searchinput");
	initSwap();
};
