/* auteur: Nadim Saikali */
/* Date de création: 19/05/2008 */
//|--------------| Up & Down Slider for elements with skinned Scroll
function udslider(divName, bloc, sbloc){
	var blocs = new Array;
	var fixedBlocHeight = false;
	this.oDiv = document.getElementById(divName);//conteneur principal

	this.oDivBloc = this.oDiv.getElementsByTagName(bloc);
	this.countoDivBloc = this.oDivBloc.length;


	this.obj = function (sousBloc, i){

		var firstDivId = new Array;
		var secondDivId = new Array;
		var skinnnedScroller = (skinnnedScroller!=undefined)? false: true;
		
		if (sousBloc[0]!=undefined) {
			this.firstDiv = sousBloc[0];// on prend le 1er element du bloc (titre cliquable)
			firstDivId[i] = this.firstDiv.id;
	
			this.secondDiv = sousBloc[1];// on prend le 2eme element du bloc (texte scrollable)
			var secondDivClass = this.secondDiv.className;
			secondDivId[i] = this.secondDiv.id;

			if (skinnnedScroller!=false) {
				if (i!=0) this.secondDiv.className = secondDivClass+" off"; // cache les autres
				else {
					fixedBlocHeight = parseFloat(this.secondDiv.offsetHeight);// on recupere la hauteur (fixe) d'un element ouvert
					skinScroll.add(secondDivId[i]); // skin sur le scroll du premier
				}
			}

			this.firstDiv.onclick = function(){
				var thisClassName = this.className;
				if (thisClassName.indexOf(" on") <1) {
					closeAllBlocs();
					openOneBlock(sousBloc[1]);
					this.className = thisClassName+" on";
					sousBloc[1].className = sousBloc[1].className.replace(' off','');
				}
			}
		}

	}

	function openOneBlock(sendObj){

		var timeoutVarOpen;
		if (!sObj) var sObj = sendObj;

		var timeoutVarClose;
		var thisClsName = sObj.className;

		sObj.style.overflow = "hidden";

		var i=1;
		this.slowOpen = function(){
			var actualHeight = sObj.offsetHeight;
			var dx =  (fixedBlocHeight - actualHeight);
			var doMath = Math.ceil(fixedBlocHeight-(0.80*dx));
			if (actualHeight!=fixedBlocHeight) {
				sObj.style.height = doMath+"px";
				timeoutVarOpen = setTimeout( 'slowOpen()', 10);
			} else {
				clearInterval(timeoutVarOpen);
				sObj.style.overflow = "";
				skinScroll.add(sObj.id);
			}
		}
		slowOpen();

	}

	function closeAllBlocs(){
		
		for(var k=0;k<blocs.length;k++) {
			var timeoutVarClose;
			if (blocs[k][0]!=undefined) {
				var fb1 = blocs[k][0];
				fb1.className = fb1.className.replace(' on','');

				var fb2 = blocs[k][1];
				if (fb2.className.indexOf(' off')<1){
					var fb2workon = fb2;

					var fb2id = (fb2workon.id)+"_over";// id de la div creee par le skin scroll

					if (document.getElementById(fb2id)!=null) {
//						if (isIE) {// IE plante avec le innerHTML de fb2workon.
							var copy = document.getElementById(fb2id).childNodes;
							var scrapAllElmt = fb2workon.childNodes;

							for(var ch =0; ch<fb2workon.childNodes.length; ch++){
								if (scrapAllElmt[ch] !=undefined) fb2workon.removeChild(scrapAllElmt[ch]);
								if (fb2workon.childNodes.length >0) ch =-1;
							}
							for (var ch=0; ch<copy.length; ch++) {
								if (copy[ch] !=undefined) fb2workon.insertBefore(copy[ch], null);
								if (copy.length >0) ch =-1;
							}
/*						} else {
							var copy = document.getElementById(fb2id).innerHTML; // copie du contenu de la div creee par le skin scroll 
							fb2workon.innerHTML = copy;// on le replace dans l'element
						}*/
					}

					this.slowClose = function () {
						var actualHeight = fb2workon.offsetHeight;
						var dx =  (0 - actualHeight);
						var doMath = Math.floor(0-(0.80*dx));
						if (actualHeight!=0) {
							fb2workon.style.height = doMath+"px";
							timeoutVarClose = setTimeout( 'slowClose()', 10);
						} else {
							clearInterval(timeoutVarClose);
							fb2workon.className = fb2workon.className+' off';
						}
					}
					slowClose();
				}
			}
		}
	}

	for(var i=0;i<this.countoDivBloc;i++) {
		blocs[i] = this.oDivBloc[i].getElementsByTagName(sbloc);
		var sousBloc = blocs[i];
		new this.obj(sousBloc, i);
	}

}