/* 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){
	//alert(goLeft+" * "+index);
	var offset = (goLeft)?-2:2;
	var flowCut = document.getElementById("flowcut" + index);
	flowCut.scrollTop += offset;
}
function initFlowScroll(){
	var i = 0;
	while (document.getElementById("flow" + i))
	{
		var flow = document.getElementById("flow" + i);
		if(!flow) return;
		strFunction1 = "flowScroll(true)";
		strFunction2 = "flowScroll(false)";
		//alert(strFunction1);
		eval("document.getElementById(\"defilgauche" + i + "\").onmouseover = function(){index = " + i +"; scrollDirection = setInterval(strFunction1, 7); };");
		eval("document.getElementById(\"defildroite" + i + "\").onmouseover = function(){index = " + i +"; scrollDirection = setInterval(strFunction2, 7); };");
		//alert(document.getElementById("defilgauche" + i).onmouseover.toString());
		document.getElementById("defilgauche" + i).onmouseout = function(){ clearInterval(scrollDirection); };
		document.getElementById("defildroite" + i).onmouseout = function(){ clearInterval(scrollDirection); };
		var items = flow.getElementsByTagName("a");
		flow.style.height = items.length*90 + "px";
		i++;
	}
}
/* init
********************/
window.onload = function(){
	initFlowScroll();
	initSwapPic();
	initSwap();
};
