var mainPage = '<%=mainPage%>'



var totframe = 100
var totframe2 = 100
var iPos = 100
var iPos2 = 0

var xNow = 0;
var xNow2 = -3745;

var xFin = 0;
var xFin2 = -1605;

var xNowFin = 0;
var xNowFin2 = 0;

var s1 = "undefined"
var s2 = "undefined"

var fotoPos = 0;
var fotoPos2 = 5;

var nFoto = 0;
var nFoto2 = 0;
var timerSlide = 0;
var timerSlide2 = 0;
		

var divtest = false		

var sliderCmd
var sliderCmdObj = new Array()
var nFoto
var stopper = false

var fotObj

function initSlider(){
	
	fotObj = document.getElementById("sliderFull").getElementsByTagName("div");
	//alert(fotObj[0].offsetWidth)
	nFoto = 8;
	
	sliderCmd = document.getElementById('comd');
	
	
	for(z=0; z<nFoto; z++){
		sliderCmdObj[z] = document.createElement('div');
		sliderCmdObj[z].id=(z);
		sliderCmdObj[z].setAttribute('class','greydot');
		sliderCmdObj[z].className = 'greydot';
		sliderCmdObj[z].style.float = 'left';
		sliderCmdObj[z].style.width = '12px';
		sliderCmdObj[z].style.height = '12px';
		sliderCmdObj[z].style.margin = '5px';
		sliderCmdObj[z].style.cursor = 'pointer';
		//sliderCmdObj[z].setAttribute('onclick','move(this.id)');
		(sliderCmdObj[z].addEventListener) ? sliderCmdObj[z].addEventListener( 'click',movePre, false ) : sliderCmdObj[z].attachEvent("onclick",movePre);
		//sliderCmdObj[z].onClick = function(){move(this.id)}
		sliderCmd.appendChild(sliderCmdObj[z]);
		
	}
	
	aggCmd()
	
	functionAr[0] = function(){slider()}
}

function movePre(evento){
	
	if (! evento){evento = window.event}
	
	var target; 
	if (event.target){ 
		target = event.target; 
	}else if (event.srcElement){ 
		target = event.srcElement; 
	}
	move(target.id)
}

//FUNZIONE DEDICATA PER LA 

var slider = function() {
	
	timerSlide++
	timerSlide2++
	if(timerSlide>=600){
		timerSlide = 0;
		testav();
	}
	
	if(iPos<totframe+1){
	
		
		x = easeOutBack(iPos,xNow,xFin,totframe,s1);
		
		//y = runFunSel(iPos,yNow,yFin,totframe,s2);
		iPos++;
		//xNow = Math.round(x);
		//yNow = Math.round(y);		
		
		//document.getElementById("test").innerHTML = x+"<br/>"+iPos+" - "+xNow+" - "+xFin+" - "+totframe+" - "+s1+" - "+s2
		document.getElementById("sliderFull").style.left = Math.round(x)+"px";
		//document.getElementById("objMoved").style.top = Math.round(y)+"px";
		
		xNowFin = Math.round(x);
		//yNowFin = Math.round(y);
		if(iPos==totframe && divtest){
			divtest = false
			fade()
		}	
	}else{
		if(stopper){
			//functionAr[0] = null;
		}
	}
	
	
	if(timerSlide2>=100){
		
		if(iPos2<totframe2+1){
		
			
			x2 = easeOutBack(iPos2,xNow2,xFin2,totframe2,s1);
			
			//y = runFunSel(iPos,yNow,yFin,totframe,s2);
			iPos2++;
			//xNow = Math.round(x);
			//yNow = Math.round(y);		
			
			//document.getElementById("test").innerHTML = x+"<br/>"+iPos+" - "+xNow+" - "+xFin+" - "+totframe+" - "+s1+" - "+s2
			
			//document.getElementById("sliderTeamFull").style.left = Math.round(x2)+"px";
			//alert(x2+"<br/>"+iPos2+" - "+xNow2+" - "+xFin2+" - "+totframe2+" - "+s1+" - "+s2)
			//document.getElementById("objMoved").style.top = Math.round(y)+"px";
			
			xNowFin2 = Math.round(x2);
			
			
			
		}else{
			//nFoto2 = document.getElementById("sliderTeamFull").getElementsByTagName("div").length;
			fotoPos2--;
			if(fotoPos2<0){
				fotoPos2 = nFoto2-1;	
			}
			
			//if(fotoPos2>nFoto2-1){
			//	fotoPos2 = 0;	
			//}
			
			timerSlide2 = 0;
			iPos2 = 0;
			xNow2 = xNowFin2;
			xFin2 = (-(fotoPos2*535))-xNowFin2;
				
		}

			
	}
	
}

function aggCmd(){
	for(i=0;i<sliderCmdObj.length;i++){
		if(fotoPos == Number(sliderCmdObj[i].id)){
		   sliderCmdObj[i].className = "greendot";
		}else{
		   sliderCmdObj[i].className = "greydot";
		}
	}
}


function move(pos,set){
	//if(!stopper){
		iPos = 0;
		timerSlide = 0;
		fotoPos = pos;
		
		xFin = (-(fotoPos*(fotObj[0].offsetWidth)))-xNowFin;
		xNow = xNowFin; 
		aggCmd()
		if(!set){
			stopper = true
		}
	//}
}


function testav(){
	if(!stopper){
		fotoPos++;
		iPos = 0;
		timerSlide = 0;
		if(fotoPos>nFoto-1){
			fotoPos = 0;
			divtest = true
			fade()		
		}
		xFin = (-(fotoPos*(fotObj[0].offsetWidth)))-xNowFin;
		xNow = xNowFin; 
		aggCmd()
	}
}

function testind(){
	if(!stopper){
		fotoPos--;
		iPos = 0;
		timerSlide = 0;
		if(fotoPos<0){
			fotoPos = nFoto-1;	
			divtest = true
			fade()
		}
		xFin = (-(fotoPos*(fotObj[0].offsetWidth)))-xNowFin;
		xNow = xNowFin;
		aggCmd()
	}
}

//FUNZIONE CHE RESTITUISCE IL VALORE 
function easeOutBack(t, b, c, d, s, p){
	if (s == "undefined")
	{
		s = 1.701580E+000;
	} // end if
	return (c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b);
};


xalpha = 0;
function fade() {
	functionAr[5] = function(){
		if(divtest){
			if(xalpha<100){
				xalpha += 5 
				document.getElementById("testdiv").style.display="block"
				document.getElementById("testdiv").style.filter = "alpha(opacity="+xalpha+")" ;
				document.getElementById("testdiv").style.opacity = (xalpha*0.01); 
				if(xalpha<=0){
					document.getElementById("testdiv").style.display="none"	
				}
			}
		}else{
			if(xalpha>0){
				xalpha -= 5
				document.getElementById("testdiv").style.display="block"
				document.getElementById("testdiv").style.filter = "alpha(opacity="+xalpha+")" ;
				document.getElementById("testdiv").style.opacity = (xalpha*0.01); 
			}
		}
	}
}




