/*
	START - FONCTION SCROLLER 
*/

/* IE COMPLIANT */

//var globalScope = new Array();

//function ieIntervalHandler( id, strFunc )
//{
//	var scope = globalScope[id];
//	eval( "scope." + strFunc + "()" );
//}


function ScrollerH(divId,elWidth,elHeight)
{
	currentEl = document.getElementById(divId);
	
	if(!currentEl) return 0;
	
	this.uniqueId 	= divId;
	this.cont 			= currentEl;
	
	this.elWidth 		= elWidth?elWidth:100;
	this.elHeight 	= elHeight?elHeight:-1;
	this.elSpacer 	= 0;
	//this.elStep 		= elStep?elStep:3;
	//this.elDelay 		= elDelay?elDelay:50;
	
	// Pause
	this.elStep 		= currentEl.getAttribute('step')?currentEl.getAttribute('step'):3;
	this.elDelay 		= currentEl.getAttribute('delay')?currentEl.getAttribute('delay'):50;
	this.elPause 		= currentEl.getAttribute('pause')?currentEl.getAttribute('pause'):5000;
	this.elNav 			= currentEl.getAttribute('nav')?currentEl.getAttribute('nav'):1;
	
	//alert(this.elWidth);
	
	this.marker 		= this.elWidth;
	this.first			= 1;
	
	this.startScrollH();
}

ScrollerH.prototype.startScrollH = function ()
{
	// ZONE VISIBLE PAR L UTILISATEUR
	viewNode = document.createElement('DIV');
	viewNode.setAttribute("class", "cmsScrollUserView");
	viewNode.setAttribute("className", "cmsScrollUserView");
	viewNode.style.top = '0px';
	viewNode.style.left = '0px';
	if(this.elHeight == -1)
		viewNode.style.height = '100%';
	else
		viewNode.style.height = this.elHeight + 'px';
	viewNode.style.width = this.elWidth + 'px';
	viewNode.style.position = 'relative';
	viewNode.style.overflow = 'hidden';
	// DEBUG viewNode.style.border = "1px solid red";
	//viewNode.style.border = "1px solid red";
	
	
	
	
	// ZONE QUI CONTIENT TOUT ET DEFILE
	containerNode = document.createElement('DIV');
	containerNode.setAttribute("class", "cmsSliderCache");
	containerNode.setAttribute("className", "cmsSliderCache");
	containerNode.style.top = '0px';
	containerNode.style.left = '0px';
	containerNode.style.width = '100%';
	containerNode.style.height = this.elHeight + 'px';
	containerNode.style.position = 'absolute';
	// DEBUG containerNode.style.border = "5px solid yellow";
	//containerNode.style.border = "1px dashed black";
	
	textList = currentEl.childNodes;
	
	countValidDiv = 0;
	
	for(y=0;y<textList.length;y++)
	{
		if(textList[y].tagName == 'DIV')
		{
			
			//	Node : une zone de texte qui défile
			
			contentPartNode = document.createElement('DIV');
			//contentPartNode.id = 'd' + y;
			contentPartNode.id = 'scrollcontent_' + countValidDiv;
			contentPartNode.setAttribute("class", "cmsSliderText");
			contentPartNode.setAttribute("className", "cmsSliderText");
			//contentPartNode.style.top = (this.elHeight + (this.elHeight*y)+(this.elSpacer*y)) + 'px';
			//contentPartNode.style.width = '100%';

			contentPartNode.style.left = ((this.elWidth*countValidDiv)+(this.elSpacer*countValidDiv)) + 'px';
			//alert(y + ' ' + contentPartNode.style.left + ' ' + this.elSpacer);
			contentPartNode.style.height = '100%';

			contentPartNode.style.width = this.elWidth + 'px';
			contentPartNode.innerHTML = textList[y].innerHTML;
			contentPartNode.style.position = "absolute";
			// DEBUG contentPartNode.style.border = "5px solid blue";
			//contentPartNode.style.border = "1px solid blue";



			//	Node : espace entre les zones de texte qui défilent
			
			spacerPartNode = document.createElement('DIV');
			//spacerPartNode.id = 'spacer' + y;
			spacerPartNode.id = 'spacer' + y;
			spacerPartNode.setAttribute("class", "cmsSliderSpacer");
			spacerPartNode.setAttribute("className", "cmsSliderSpacer");
			spacerPartNode.style.left = (this.elWidth + (this.elWidth*countValidDiv)) + 'px';
			spacerPartNode.style.height = '100%';
			spacerPartNode.style.width = this.elSpacer + 'px';
			// DEBUG spacerPartNode.style.border = "5px solid purple";
			spacerPartNode.style.position = "absolute";
			//spacerPartNode.style.border = "1px solid purple";
			
			containerNode.appendChild(contentPartNode);
			containerNode.appendChild(spacerPartNode);

			countValidDiv++;
		}
	}
	
	this.ValidDivs = countValidDiv;
	//alert(' nb de div detect : ' + countValidDiv +  ' ' + this.ValidDivs);
	
	// Reajustement de la taille du container
	containerNode.style.width = (this.elWidth*countValidDiv) + 'px';
	
	this.cont.innerHTML = '';
	
	viewNode.appendChild(containerNode);
	this.cont.appendChild(viewNode);
	
	// A NE FAIRE QU APRES LE APPEND DU BLOC CONTAINER
	//alert(document.getElementById('scrollcontent_' + (countValidDiv-1)));
	
	this.cont.style.visibility = 'visible';
	
	this.container = containerNode;
	
	if(countValidDiv > 1)
		this.translateH();
}

ScrollerH.prototype.translateH = function ()
{
	// CAS PARTICULIER : START
	if(this.first == 1)
	{
		//alert('first pause');
		this.first = 0;
		
		if( document.all )
		{
			// Version IE
			globalScope[ this.uniqueId ] = this;
			setTimeout( 'ieIntervalHandler("' + this.uniqueId + '","translateH")', this.elPause );
		}
		else
		{
			// Version FF
			setTimeout(function(thisObj) { thisObj.translateH(); }, this.elPause, this);
		}
		
		return 0;
	}
	
	curLeft = parseInt(this.container.style.left);
	
	if(this.marker > 0 && this.marker < 50)
		this.curstep = 2;
	else
		this.curstep = this.elStep;
	
	this.marker 		= this.marker - this.curstep;	
	newLeft 				= curLeft - this.curstep;
	
	
	if(Math.abs(newLeft) >= (((this.ValidDivs) * this.elWidth) + ((this.ValidDivs) * this.elSpacer)))
	{
		//alert('o ' + this.uniqueId + ' ' + countValidDiv +  ' ' + this.ValidDivs);
		//alert(" Spacer :" + this.elSpacer + " this.elWidth " + this.elWidth + " DIV COUNT " + this.ValidDivs + ' newleft' + newLeft + " : " + Math.abs(newLeft) + " > " + (((this.ValidDivs) * this.elWidth) + ((this.ValidDivs) * this.elSpacer)));
		
		this.container.style.left = this.elWidth + 'px';
		this.marker = this.elWidth;
	}
	else
	{
		this.container.style.left = newLeft + 'px';
	}
	
	if(this.marker <= 0)
	{
		this.first = 0;
		this.marker = this.elWidth + this.elSpacer;
		
		if( document.all )
		{
			// Version IE
			globalScope[ this.uniqueId ] = this;
			setTimeout( 'ieIntervalHandler("' + this.uniqueId + '","translateH")', this.elPause );
		}
		else
		{
			// Version FF
			setTimeout(function(thisObj) { thisObj.translateH(); }, this.elPause, this);
		}
		return 0;
	}
	else
	{
		if( document.all )
		{
			// Version IE
			globalScope[ this.uniqueId ] = this;
			setTimeout( 'ieIntervalHandler("' + this.uniqueId + '","translateH")', this.elDelay );
		}
		else
		{
			// Version FF
			setTimeout(function(thisObj) { thisObj.translateH(); }, this.elDelay, this);
		}
		return 0;
	}
}

/*

	END - FONCTION SCROLLER 

*/
