/*
	START - FONCTION SCROLLER 
*/

/* IE COMPLIANT */

var globalScope = new Array();

function ieIntervalHandler( id, strFunc )
{
	var scope = globalScope[id];
	eval( "scope." + strFunc + "()" );
}

function Scroller(divId,elWidth,elHeight,elSpacer,elStep,elDelay,elPause)
{
	currentEl = document.getElementById(divId);
	
	if(!currentEl) return 0;
	
	this.uniqueId 	= divId;
	this.cont 			= currentEl;
	
	this.elWidth 		= elWidth?elWidth:-1;
	this.elHeight 	= elHeight?elHeight:100;
	this.elSpacer 	= elSpacer?elSpacer:0;
	this.elStep 		= elStep?elStep:3;
	this.elDelay 		= elDelay?elDelay:50;
	this.elPause 		= elPause?elPause:3000;
	
	this.marker 		= this.elHeight;
	
	this.startScroll();
}

Scroller.prototype.startScroll = function ()
{
	viewNode = document.createElement('DIV');
	viewNode.setAttribute("class", "cmsScrollUserView");
	viewNode.setAttribute("className", "cmsScrollUserView");
	viewNode.style.top = '0px';
	viewNode.style.left = '0px';
	if(this.elWidth == -1)
		viewNode.style.width = '100%';
	else
		viewNode.style.width = this.elWidth + 'px';
	viewNode.style.height = this.elHeight + 'px';
	viewNode.style.position = 'relative';
	viewNode.style.overflow = 'hidden';
	// DEBUG viewNode.style.border = "1px solid red";
	
	containerNode = document.createElement('DIV');
	containerNode.setAttribute("class", "cmsSliderCache");
	containerNode.setAttribute("className", "cmsSliderCache");
	containerNode.style.top = this.elHeight + 'px';;
	containerNode.style.left = '0px';
	containerNode.style.width = '100%';	
	containerNode.style.position = 'absolute';
	// DEBUG containerNode.style.border = "5px solid yellow";
	
	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.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.height = this.elHeight + 'px';
			contentPartNode.innerHTML = textList[y].innerHTML;
			// DEBUG contentPartNode.style.border = "5px solid blue";
		
			//	Node : espace entre les zones de texte qui défilent
			spacerPartNode = document.createElement('DIV');
			spacerPartNode.id = 'spacer' + y;
			spacerPartNode.setAttribute("class", "cmsSliderSpacer");
			spacerPartNode.setAttribute("className", "cmsSliderSpacer");
			spacerPartNode.style.top = (this.elHeight + (this.elHeight*y)) + 'px';
			spacerPartNode.style.width = '100%';
			spacerPartNode.style.height = this.elSpacer + 'px';
			// DEBUG spacerPartNode.style.border = "5px solid purple";
			
			containerNode.appendChild(contentPartNode);
			containerNode.appendChild(spacerPartNode);

			countValidDiv++;
		}
	}
	
	this.cont.innerHTML = '';
	
	viewNode.appendChild(containerNode);
	this.cont.appendChild(viewNode);
	
	this.cont.style.visibility = 'visible';
	
	this.container = containerNode;
	this.translate();
}

Scroller.prototype.translate = function ()
{
	curTop = parseInt(this.container.style.top);
	
	if(this.marker > 0 && this.marker < 15)
		this.curstep = 1;
	else
		this.curstep = this.elStep;
	
	this.marker 	= this.marker - this.curstep;	
	newTop 				= curTop - this.curstep;
	
	this.container.style.top = newTop + 'px';
	
	if(Math.abs(newTop) > ((countValidDiv * this.elHeight) + ((countValidDiv - 1) * this.elSpacer)))
	{
		this.container.style.top = this.elHeight + 'px';
		this.marker = this.elHeight;
	}
	
	if(this.marker <= 0)
	{
		this.marker = this.elHeight + this.elSpacer;
		
		if( document.all )
		{
			// Version IE
			globalScope[ this.uniqueId ] = this;
			setTimeout( 'ieIntervalHandler("' + this.uniqueId + '","translate")', this.elPause );
		}
		else
		{
			// Version FF
			setTimeout(function(thisObj) { thisObj.translate(); }, this.elPause, this);
		}
	}
	else
	{
		if( document.all )
		{
			// Version IE
			globalScope[ this.uniqueId ] = this;
			setTimeout( 'ieIntervalHandler("' + this.uniqueId + '","translate")', this.elDelay );
		}
		else
		{
			// Version FF
			setTimeout(function(thisObj) { thisObj.translate(); }, this.elDelay, this);
		}
	}
}

/*

	END - FONCTION SCROLLER 

*/