﻿// JScript File
function CalculateFadePages(p, a, l, f){
	p.innerHTML= '';
	if (a>0){
		p.innerHTML+='<a href="#" onclick="' + f + '(' + (a-1) + '); return false;"><img src="../../img/web/icon_prev.gif" height="16" width="16"></a>';
	}else{
		p.innerHTML+='<img src="../../img/web/icon_prevd.gif" height="16" width="16" >';
	}
	p.innerHTML+='<a href="#" onclick="StopPlay(\'' + f.substr(4) + '\'); return false;" style="margin:0 6px;"><img id="ImgPlay' + f.substr(4) + '" src="../../img/web/icon_pause.gif" height="16" width="16"></a>';
	if (a<(l-1)){
		p.innerHTML+='<a href="#" onclick="' + f + '(' + (a+1) + '); return false;"><img src="../../img/web/icon_next.gif" height="16" width="16"></a>';
	}else{
		p.innerHTML+='<img src="../../img/web/icon_nextd.gif" height="16" width="16" >';

	}
}
function StopPlay(s){
	var img=document.getElementById('ImgPlay' + s);
	if (img.src.indexOf('pause')>0){
		switch (s){
			case 'Gs': clearTimeout(GsT); break;
			case 'Pa': clearTimeout(PaT); break;
			case 'Pc': clearTimeout(PcT); break;
		}
		img.src='../../img/web/icon_play.gif';
	}else{
		switch (s){
			case 'Gs': gsFade(); break;
			case 'Pa': paFade(); break;
			case 'Pc': pcFade(); break;
		}
		img.src='../../img/web/icon_pause.gif';
	}
}

var ActualGs=-1, PrevGs=-1, GsFade=100, GsT, GsClicked=-2500;
function gsFade(){
	var g=document.getElementsByName('GsBox'), gn=document.getElementById('GsNumber');
	if (g.length==0){
		var gsc = document.getElementById('GsContainer');
		if (gsc) gsc.innerHTML='<div class="absolute RollingCarsEmptyBox" style="top:60px; left:40px;">Nessuna promozione Green-Star attualmente presente.</div>'; return;
	}
	if (ActualGs==-1){
		ActualGs=0; g[0].style.display='block';
		if (g.length==1) return;
		CalculateFadePages(gn, 0, g.length, 'SkipGs')
	}			
	if (GsFade==100){
		if (PrevGs>=0) g[PrevGs].style.display='none';
		PrevGs=ActualGs;
		ActualGs++; ActualGs=ActualGs % g.length;
		g[ActualGs].style.zIndex=-1; g[PrevGs].style.zIndex=1;
		GsFade=0; g[ActualGs].style.opacity=0;
		if (document.all) g[ActualGs].filters[0].opacity=0;
		g[ActualGs].style.display='block';
		GsT=setTimeout('gsFade()', 4500 + GsClicked);
		GsClicked=0;
	}else{
		g[ActualGs].style.zIndex=0; g[PrevGs].style.zIndex=1;
		GsFade+=20;
		g[ActualGs].style.opacity=GsFade/100; g[PrevGs].style.opacity=1-GsFade/100;
		if (document.all){
			g[ActualGs].filters[0].opacity=GsFade; g[PrevGs].filters[0].opacity=100 - GsFade;
		}
		GsT=setTimeout('gsFade()', 80);
	}
	if (GsFade==40)CalculateFadePages(gn, ActualGs, g.length, 'SkipGs')
}
function SkipGs(i){
	clearTimeout(GsT); ActualGs=i;	GsFade=0; GsClicked=1500;
	var g=document.getElementsByName('GsBox')
	g[ActualGs].style.opacity=0;
	if (document.all) g[ActualGs].filters[0].opacity=0;
	g[ActualGs].style.display='block';
	gsFade();
}

var ActualPa=-1, PrevPa=-1, PaFade=100, PaT, PaClicked=-1300;
function paFade(){
	var g=document.getElementsByName('PABox'), gn=document.getElementById('PaNumber');
	if (g.length==0){
		var pac = document.getElementById('PaContainer');
		if (pac) pac.innerHTML='<div class="absolute RollingCarsEmptyBox" style="top:60px; left:25px;">Nessun veicolo presente negli Usato premium autovetture.</div>'; return;
	}
	if (ActualPa==-1){
		ActualPa=0; g[0].style.display='block';
		if (g.length==1) return;
		CalculateFadePages(gn, 0, g.length, 'SkipPa')
	}
	if (PaFade==100){
		if (PrevPa>=0) g[PrevPa].style.display='none';
		PrevPa=ActualPa;
		
		ActualPa++; ActualPa=ActualPa % g.length;
		g[ActualPa].style.zIndex=-1; g[PrevPa].style.zIndex=1;
		PaFade=0; g[ActualPa].style.opacity=0;
		if (document.all) g[ActualPa].filters[0].opacity=0;
		g[ActualPa].style.display='block';
		PaT=setTimeout('paFade()', 4500 + PaClicked);
		PaClicked=0;
	}else{
		g[ActualPa].style.zIndex=0; g[PrevPa].style.zIndex=0;
		PaFade+=20;
		g[ActualPa].style.opacity=PaFade/100; 
		g[PrevPa].style.opacity=1-PaFade/100;
		if (document.all){
			g[ActualPa].filters[0].opacity=PaFade; g[PrevPa].filters[0].opacity=100 - PaFade;
		}
		PaT=setTimeout('paFade()', 80);
	}
	if (PaFade==40)CalculateFadePages(gn, ActualPa, g.length, 'SkipPa')
}
function SkipPa(i){
	clearTimeout(PaT); ActualPa=i;	PaFade=0; PaClicked=1500;
	var g=document.getElementsByName('PABox')
	g[ActualPa].style.opacity=0;
	if (document.all) g[ActualPa].filters[0].opacity=0;
	g[ActualPa].style.display='block';
	paFade();
}

var ActualPc=-1, PrevPc=-1, PcFade=100, PcT, PcClicked=0;
function pcFade(){
	var g=document.getElementsByName('PCBox'), gn=document.getElementById('PcNumber');
	if (g.length==0){
		var pcc = document.getElementById('PcContainer');
		if (pcc) pcc.innerHTML='<div class="absolute RollingCarsEmptyBox" style="top:60px; left:30px;">Nessun veicolo presente negli Usato premium autocarri.</div>'; 
		return;
	}
	if (ActualPc==-1){
		ActualPc=0; g[0].style.display='block';
		if (g.length==1) return;
		CalculateFadePages(gn, 0, g.length, 'SkipPc')
	}
	if (PcFade==100){
		if (PrevPc>=0) g[PrevPc].style.display='none';
		PrevPc=ActualPc;
		
		ActualPc++; ActualPc=ActualPc % g.length;
		g[ActualPc].style.zIndex=-1; g[PrevPc].style.zIndex=1;
		PcFade=0; g[ActualPc].style.opacity=0;
		if (document.all) g[ActualPc].filters[0].opacity=0;
		g[ActualPc].style.display='block';
		PcT=setTimeout('pcFade()', 4500 + PcClicked);
		PcClicked=0;
	}else{
		g[ActualPc].style.zIndex=0; g[PrevPc].style.zIndex=0;
		PcFade+=20;
		g[ActualPc].style.opacity=PcFade/100; g[PrevPc].style.opacity=1-PcFade/100;
		if (document.all){
			g[ActualPc].filters[0].opacity=PcFade; g[PrevPc].filters[0].opacity=100 - PcFade;
		}
		PcT=setTimeout('pcFade()', 80);
	}
	if (PcFade==40)CalculateFadePages(gn, ActualPc, g.length, 'SkipPc')
}
function SkipPc(i){
	clearTimeout(PcT); ActualPc=i;	PcFade=0; PcClicked=1500;
	var g=document.getElementsByName('PCBox')
	g[ActualPc].style.opacity=0;
	if (document.all) g[ActualPc].filters[0].opacity=0;
	g[ActualPc].style.display='block';
	pcFade();
}
