function identifyBrowser(){
	var uaTests =
	{
		'op':/opera/i,
		'ie':/MSIE/,
		'moz':/gecko/i,
		'ns':/netscape/i
	};
	this.type = '';
	for (var n in uaTests)
	{
		if (uaTests[n].test(navigator.userAgent))
		{
			this.type = n;
			break;
		}
	}
	window.ie = (this.type=='ie');
	window.moz = (this.type=='moz');
	
}

function vtpScroller(){
	this.pages		= new vtpPageCollection();
	this.slider 	= null;
	this.tim		= new Timer(10);
	this.conHeight	= 0;
	this.waitTime	= 0;
	this.inPause	= false;
	this.step		= 1;
	this.oldMod		= 0;
	this.speedStep	= 6;
	
	// definition de Methode : this.create = function (){...};
	this.create = function (){
		identifyBrowser();
		// On duplique la 1ere en derniÃ¨re position pour avoir l'impression d'un suivi
		this.pages.add(this.pages.item(0).url);
		
		var html = '<table border=0>';
		html	+= '<tr>';
		html	+= '	<td>';
		html	+= '		<div id="scrollContener" class="scrollContener">';
		for(var i=0; i < this.pages.count(); i++){
			html	+= '		<div class="scrollIframe">';
			html	+= ajaxGet(this.pages.item(i).url);
			html	+= '		</div>';
		}
		html	+= '		</div>';
		html	+= '	</td>';
		html	+= '	<td>';
		html	+= '		<table class="scrollContenerBtns">';
		html	+= '			<tr><td><img src="images/icoUp.gif"	id="scerUp"		onClick="scroller.goPrev();"/></td></tr>';
		html	+= '			<tr><td><img src="images/icoPause.gif" id="scerPause"	onClick="scroller.switchPause();"/></td></tr>';
		html	+= '			<tr><td><img src="images/icoDown.gif"	id="scerDown"	onClick="scroller.goNext();"/></td></tr>';
		html	+= '		</table>';
		html	+= '	</td>';
		html	+= '</tr>';
		html	+= '</table>';

		document.write(html);
		
		// Taille de la bande dÃ©roulante
		var scrollContener	= document.getElementById("scrollContener");
		this.conHeight		= scrollContener.clientHeight;
		// Bug ie qui ne crÃ©e pas l'affichage pdt le document.write(html);
		//if(this.conHeight == 0)
		this.conHeight = 140;
		
		var scrollingHeight	= (this.pages.count() * this.conHeight) - this.conHeight;
		
		// CrÃ©ation
		this.slider = new Range();// Slider(document.getElementById("slider"), document.getElementById("sliderInput"), "vertical");
		this.slider.setMinimum(0);
		this.slider.setMaximum(scrollingHeight);
		this.slider.setValue(0);
		
		this.slider.onchange = function () {
			// on est deja ds le context slider
			scrollContener.scrollTop = this.getValue();
		};
		
		// DÃ©filement
		this.tim.start();
	};
	
	// pour le forcer a appeller le prototype
	var oThis = this;
	this.tim.ontimer = function () {
		oThis.ontimer();
	};

	this.switchPause = function (forceOff) {
		var img = document.getElementById('scerPause');
		
		if(this.inPause || forceOff){
			this.inPause = false;
			img.src = 'images/icoPause.gif';
		}else{
			this.inPause = true;
			img.src = 'images/icoPlay.gif';
		}
	};
	
	this.goNext = function () {
		this.step = this.speedStep;
		this.switchPause(true);
		// marche mais 1 en retard.... this.oldMod = 0;
	};
	this.goPrev = function () {
		this.step = -this.speedStep;
		this.switchPause(true);
		// marcherais mais en retard.... this.oldMod = this.conHeight;
	};
};

vtpScroller.prototype.ontimer = function () {
	var slv		= this.slider.getValue();
	var mod		= slv % this.conHeight;
	
	//recallage avant
	if( (this.step == this.speedStep) && (this.oldMod > mod) ){
	//	alert('recallAV, om:'+this.oldMod+' mod:'+mod);
		var curPage = Math.round(slv / this.conHeight);
		slv = curPage * this.conHeight;
		this.slider.setValue(slv);
		this.step = 1;
		mod = 0;
	}
	//recallage arriÃ¨re
	if( (this.step == -this.speedStep) && (this.oldMod < mod) ){
	//	alert('recallAR, om:'+this.oldMod+' mod:'+mod);
		var curPage = Math.round(slv / this.conHeight);
		if(curPage < 0)	curPage = this.pages.count();
		slv = curPage * this.conHeight;
		this.slider.setValue(slv);
		this.step = -1;
		mod = 0;
	}
	
	this.oldMod = mod;
	
	if(mod == 0){ // on est en arret sur une page
		if( ((this.step == this.speedStep) || (this.step == -this.speedStep)) && this.waitTime != 0){// avance rapide & click pdt waitTime
		if(this.step == this.speedStep)
			this.oldMod = 0;
		else
			this.oldMod = this.conHeight;
	//	alert('pause, om:'+this.oldMod+' mod:'+mod);
			this.slider.setValue(slv + this.step); // on le fait continuer en gardant la vitesse, reinit timer
			this.waitTime = 0;
		}else{
			this.waitTime ++;
			if(this.waitTime == 500){
				this.waitTime = 0;
				if(!this.inPause)
					this.slider.setValue(slv + this.step);
			}
			// reinit du step
			if(this.step > 0) // on avancait
				this.step = 1;
			else
				this.step = -1;
		}
	}else{
		if(this.inPause) // on le fait reculer ^^
			this.slider.setValue(parseFloat(slv) - 1);
		else
			this.slider.setValue(parseFloat(slv) + this.step);
	}
	
	this.tim.start(); // doit etre appelÃ© a chaq fois
};
