// JavaScript Document

var timeout = 0;
var posit = 0;
function NM_roller () {
	var Id_content = "news_content";
	var Id_wrap = "news_mask";
	clearTimeout( timeout );
	if (document.getElementById( Id_content )) {
		var h_cont = document.getElementById( Id_content ).offsetHeight;
		var h_wrap = document.getElementById( Id_wrap ).offsetHeight;
		var mov_max = (h_cont + posit);
		var returnPosit = h_wrap;
	//controllo se la posizione è la massima o no
		if (mov_max <= 0) {
		//alert ('sono a fondo');
			posit = returnPosit;
			document.getElementById( Id_content ).style.top = posit + 'px';
		} else {
			posit = (posit - 1);
			document.getElementById( Id_content ).style.top = posit + 'px';
		}
	}
	timeout = setTimeout( "NM_roller()", 60 );
}

function NM_roll_stop () {
	clearTimeout( timeout );
	attesa = setTimeout ( "NM_roller()", 4000 );
}

function NM_roll_go () {
	clearTimeout( attesa );
	timeout = setTimeout( "NM_roller()", 0 );
}

// Elenchi prodotti
nastro = new Array();
nastro[0]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 AL", "articolo_09a.html");
nastro[1]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 SUPER D", "articolo_09d.html");
nastro[2]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 US", "articolo_09k.html");
nastro[3]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 COBALT", "articolo_09e.html");
nastro[4]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 COBALT", "articolo_09esm.html");
nastro[5]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 COBALT", "articolo_09u.html");
nastro[6]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M42 COBALT", "articolo_09f.html");
nastro[7]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - M51 SPECIAL", "articolo_09b.html");
nastro[8]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - AURORA FOUNDRY", "articolo_AF.html");
nastro[9]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - AURORA XT", "articolo_AX.html");
nastro[10]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - AURORA THREE", "articolo_A3.html");
nastro[11]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - AURORA FIVE", "articolo_A5.html");
nastro[12]= new Array("images/home_slaider/nastro.jpg", "SEGHE A NASTRO - CARBONIO", "articolo_08b.html");
nastro[13]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - AURORA SPECIAL", "articolo_AS.html");
nastro[14]= new Array("images/home_slaider/nastro.jpg", "LAME A NASTRO - BLACK AURORA", "articolo_AB.html");

circolare = new Array();
circolare[0]= new Array("images/home_slaider/circolari.jpg", "LAME CIRCOLARI - VAPORIZZATO", "articolo_651.html");
circolare[1]= new Array("images/home_slaider/circolari.jpg", "LAME CIRCOLARI - TiN", "articolo_652.html");
circolare[2]= new Array("images/home_slaider/circolari.jpg", "LAME CIRCOLARI - TiCN", "articolo_653.html");
circolare[3]= new Array("images/home_slaider/circolari.jpg", "LAME CIRCOLARI - TiAIN", "articolo_655.html");
circolare[4]= new Array("images/home_slaider/circolari.jpg", "LAME CIRCOLARI - A SETTORI", "articolo_70.html");
circolare[5]= new Array("images/home_slaider/circolari.jpg", "LAME CIRCOLARI - VELOCI", "articolo_50.html");

circHM = new Array();
circHM[0]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 702", "articolo_702.html");
circHM[1]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 691 ", "articolo_691.html");
circHM[2]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 40N", "articolo_40n.html");
circHM[3]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 41P", "articolo_41.html");
circHM[4]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 751 HMAL", "articolo_751.html");
circHM[5]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 752 HMC", "prod_seghe_circolari_hm.html#");
circHM[6]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 761 HMT", "articolo_761.html");
circHM[7]= new Array("images/home_slaider/circolariHM.jpg", "LAME CIRCOLARI HM - art. 771 HMC", "articolo_771.html");

LameMM = new Array();
LameMM [0]= new Array("images/home_slaider/mano.jpg", "LAME A MANO - BIMETALLICA", "articolo_3.html");
LameMM [1]= new Array("images/home_slaider/mano.jpg", "LAME A MANO - FLEX MOLIBDENO", "articolo_5.html");
LameMM [2]= new Array("images/home_slaider/mano.jpg", "LAME A MANO - HSS DMo5", "articolo_10.html");
LameMM [3]= new Array("images/home_slaider/mano.jpg", "LAME A MANO - SPECIAL INOX", "articolo_20.html");

categ = new Array();
categ[0]= nastro;
categ[1]= circolare;
categ[2]= circHM;
categ[3]= LameMM;
categ[4]= new Array("testo", "<p><a href=\"http://www.riccardofrascio.com/prod_seghe_nastro.html\">Seghe a nastro in HSS indicate per il taglio di elementi metallici in alluminio</a><br><br><a href=\"http://www.riccardofrascio.com/prod_seghe_nastro.html\">Seghe a nastro in HSS Molibdeno per il taglio di profili e tubi</a><br><br><a href=\"http://www.riccardofrascio.com/prod_seghe_nastro.html\">Sega a nastro HM con dente negativo per il taglio di materiali temprati</a><br><br><a href=\"http://www.riccardofrascio.com/prod_seghe_circolari.html\">Seghe circolari per impiego su acciai medio dolci, duri e molto duri</a><br><br><a href=\"http://www.riccardofrascio.com/prod_seghe_circolari.html\">Seghe circolari HM per il taglio di metalli, materie plastiche, materiali compositi e legno</a><br><br></p>");

// Definizione variabili valori movimento e millisecondi
var movTimer = 0;
var movTimer2 = 0;
var t = 1;
var movimento = 8;
var millisec = 50;
var pause = 5000;
var primo = 0;

function randomBanner (nomeArray) {
	maxValue = nomeArray.length;
	numProd = Math.floor(Math.random()*maxValue);
	return numProd;
	//alert (numProd);
}

function bannerBuilder () {
	//alert (categ[0]);
	//randomBanner (categ[3]);
	left = 663;
	for (i=0; i<categ.length; i++) {
		randomBanner (categ[i]);
		//alert (categ[i][numProd][1]);
		if (i == 4) {
			if (primo == 0) {
				$("#slaider").append('<div id="banner_' + categ[i][0] + '" style="display:none;">' + categ[i][1] + '</div>');
				primo++;
			}
			else {
				$("#slaider").append('<div id="banner_' + categ[i][0] + '" style="">' + categ[i][1] + '</div>');
			}	
		} else {
			$("#slaider").append('<div id="banner_' + i + '" class="banner" style="background-image:url(' + categ[i][numProd][0] + '); left: ' + left + 'px;"><table><tr><td height="148px" valign="bottom" ><a href="' + categ[i][numProd][2] + '"><div class="titolo">' + categ[i][numProd][1] + '<br /><span class="link">Link &raquo;</span><div style="clear:both;"></div></div></a></td></tr></table></div>');
		}
		left = left+20;
	}
	bannerMoover ();
}

function bannerMoover () {
	posizione3 = document.getElementById('banner_3').style.left;
	posizione3 = posizione3.replace("px", "");
	if (posizione3 != 88) {
		bannerMoover0 ();
		if (t > 10) bannerMoover1 ();
		if (t > 20) bannerMoover2 ();
		if (t > 30) bannerMoover3 ();
		if (t > 20) $("#banner_testo").fadeOut("slow");
		t++;
		movTimer = setTimeout( "bannerMoover()", millisec );
		//alert (movTimer);
	}
	if (posizione3 == 88) {
		t = 1;
		movTimer2 = setTimeout( "bannerReMoover()", pause );
	}
}

function bannerMoover0 () {
	if (document.getElementById('banner_0')) {
		posizione = document.getElementById('banner_0').style.left;
		posizione = posizione.replace("px", "");
		if (posizione > 28) {
			left = posizione - movimento;
			document.getElementById('banner_0').style.left = left + 'px';
		} else {
			left = 28;
			document.getElementById('banner_0').style.left = left + 'px';
		}
	}
}

function bannerMoover1 () {
	if (document.getElementById('banner_1')) {
		posizione = document.getElementById('banner_1').style.left;
		posizione = posizione.replace("px", "");
		if (posizione > 48) {
			left = posizione - movimento;
			document.getElementById('banner_1').style.left = left + 'px';
		} else {
			left = 48;
			document.getElementById('banner_1').style.left = left + 'px';
		}
	}
}

function bannerMoover2 () {
	if (document.getElementById('banner_2')) {
		posizione = document.getElementById('banner_2').style.left;
		posizione = posizione.replace("px", "");
		if (posizione > 68) {
			left = posizione - movimento;
			document.getElementById('banner_2').style.left = left + 'px';
		} else {
			left = 68;
			document.getElementById('banner_2').style.left = left + 'px';
		}
	}
}

function bannerMoover3 () {
	if (document.getElementById('banner_3')) {
		posizione = document.getElementById('banner_3').style.left;
		posizione = posizione.replace("px", "");
		if (posizione > 88) {
			left = posizione - movimento;
			document.getElementById('banner_3').style.left = left + 'px';
		} else {
			left = 88;
			document.getElementById('banner_3').style.left = left + 'px';
		}
	}
}

function bannerReMoover () {
	clearTimeout( movTimer2 );
	posizione3 = document.getElementById('banner_3').style.left;
	posizione3 = posizione3.replace("px", "");
	if (posizione3 <= 88 && posizione3 > -547) {
		bannerReMoover0 ();
		if (t > 10) bannerReMoover1 ();
		if (t > 20) bannerReMoover2 ();
		if (t > 30) bannerReMoover3 ();
		if (t > 70) $("#banner_testo").fadeIn("slow");
		t++;
		movTimer = setTimeout( "bannerReMoover()", millisec );
		//alert (movTimer);
	} else {
		//$("#banner_testo").fadeOut("slow");
		//movTimer = setTimeout( "bannetClear()", 2000 );
		$("#banner_testo").remove();
		$("#banner_0").remove();
		$("#banner_1").remove();
		$("#banner_2").remove();
		$("#banner_3").remove();
		clearTimeout ( movTimer );
		t = 1;
		bannerBuilder();
	}
}

function bannerReMoover0 () {
	if (document.getElementById('banner_0')) {
		posizione = document.getElementById('banner_0').style.left;
		posizione = posizione.replace("px", "");
		if (-607 < posizione <= 28) {
			left = posizione - movimento;
			document.getElementById('banner_0').style.left = left + 'px';
		} else {
			left = -607;
			document.getElementById('banner_0').style.left = left + 'px';
		}
	}
}

function bannerReMoover1 () {
	if (document.getElementById('banner_1')) {
		posizione = document.getElementById('banner_1').style.left;
		posizione = posizione.replace("px", "");
		if (-587 < posizione <= 48) {
			left = posizione - movimento;
			document.getElementById('banner_1').style.left = left + 'px';
		} else {
			left = -587;
			document.getElementById('banner_1').style.left = left + 'px';
		}
	}
}

function bannerReMoover2 () {
	if (document.getElementById('banner_2')) {
		posizione = document.getElementById('banner_2').style.left;
		posizione = posizione.replace("px", "");
		if (-567 < posizione <= 68) {
			left = posizione - movimento;
			document.getElementById('banner_2').style.left = left + 'px';
		} else {
			left = -567;
			document.getElementById('banner_2').style.left = left + 'px';
		}
	}
}

function bannerReMoover3 () {
	if (document.getElementById('banner_3')) {
		posizione = document.getElementById('banner_3').style.left;
		posizione = posizione.replace("px", "");
		if (-547 < posizione <= 88) {
			left = posizione - movimento;
			document.getElementById('banner_3').style.left = left + 'px';
		} else {
			left = -547;
			document.getElementById('banner_3').style.left = left + 'px';
		}
	}
}
