var url = document.URL;
var ThisPage='';
var min = 1;
var max = 248;

function italiano(){
	var file_name = document.location.href;
    	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	var nomefile=file_name.substring(file_name.lastIndexOf("/")+1, end);
	if(nomefile==""){nomefile='index'}
	else{
		nomefile=nomefile.substring(0,nomefile.lastIndexOf("."));
		estensione=nomefile.substring(nomefile.length-2,nomefile.length);
		if(estensione=="EN" || estensione=="ES" || estensione=="FR" ){
			nomefile=nomefile.substring(0,nomefile.length-2);
		}
	}
	nomefile=nomefile+".html";
	location.href=nomefile;
}

function inglese(){
	var file_name = document.location.href;
    	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	var nomefile=file_name.substring(file_name.lastIndexOf("/")+1, end);
	if(nomefile==""){nomefile='index'}
	else{
		nomefile=nomefile.substring(0,nomefile.lastIndexOf("."));
		estensione=nomefile.substring(nomefile.length-2,nomefile.length);
		if(estensione=="EN" || estensione=="ES" || estensione=="FR" ){
			nomefile=nomefile.substring(0,nomefile.length-2);
		}
	}
	nomefile=nomefile+"EN.html";
	location.href=nomefile;
}

function francese(){
	var file_name = document.location.href;
    	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	var nomefile=file_name.substring(file_name.lastIndexOf("/")+1, end);
	if(nomefile==""){nomefile='index'}
	else{
		nomefile=nomefile.substring(0,nomefile.lastIndexOf("."));
			estensione=nomefile.substring(nomefile.length-2,nomefile.length);
		if(estensione=="EN" || estensione=="ES" || estensione=="FR" ){
			nomefile=nomefile.substring(0,nomefile.length-2);
		}
	}
	nomefile=nomefile+"FR.html";
	location.href=nomefile;
}

function spagnolo(){
	var file_name = document.location.href;
    	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	var nomefile=file_name.substring(file_name.lastIndexOf("/")+1, end);
	if(nomefile==""){nomefile='index'}
	else{
		nomefile=nomefile.substring(0,nomefile.lastIndexOf("."));
			estensione=nomefile.substring(nomefile.length-2,nomefile.length);
		if(estensione=="EN" || estensione=="ES" || estensione=="FR" ){
			nomefile=nomefile.substring(0,nomefile.length-2);
		}
	}
	nomefile=nomefile+"ES.html";
	location.href=nomefile;
}

function caricaImmagine(){
	if(navigator.userAgent.indexOf('MSIE')<0){
		parametri();
		document.immagineCentrale.src="Schede2011\/"+ThisPage+"p.jpg";
	}else{ 
		parametri();
		immagineCentrale.src="Schede2011\/"+ThisPage+"p.jpg";
	}
	document.getElementById('destra').style.visibility = "Visible";
	document.getElementById('sinistra').style.visibility = "Visible";
	document.getElementById('home').style.visibility = "Visible";
}
function modificaParametro(lato){
	if (lato=='destra' && ThisPage<max){ThisPage++;
	}	
	if (lato=='sinistra' && ThisPage>min){	ThisPage--;
	}
}
function cambia(lato,immagine){
	if(ThisPage>=min-1 && ThisPage<max+1){
		modificaParametro(lato);
		immagine.src="Schede2011\/"+ThisPage+"p.jpg";
	}
	if((ThisPage>min) && (ThisPage<max) ){
		window.setTimeout("document.getElementById('sinistra').style.visibility = 'visible'",100);
		window.setTimeout("document.getElementById('destra').style.visibility   = 'visible'",100);
		window.setTimeout("document.getElementById('home').style.visibility   = 'visible'",100);
	}else{
		if((ThisPage<=min) ){
			document.getElementById(lato).style.visibility = "hidden";
		}else{
			document.getElementById(lato).style.visibility   = "hidden";
		}
	}
}


function seguiScroll(event){
    var altezza = 1;
	document.getElementById('destra').style.left       = 960+'px';
	document.getElementById('sinistra').style.left     = 10+'px';
	document.getElementById('home').style.left	   = 41+'px';
	document.getElementById('destra').style.position   = "Absolute";
	document.getElementById('sinistra').style.position = "Absolute";
	document.getElementById('home').style.position 	   = "Absolute";

	if(navigator.userAgent.indexOf('MSIE')<0){
	  altezza=document.documentElement.scrollTop;
	}else{ 
	  altezza=document.body.scrollTop;
	}
		document.getElementById('destra').style.top        = altezza+'px';
		document.getElementById('sinistra').style.top      = altezza+'px';
		document.getElementById('home').style.top          = altezza+'px';
}

function seguiMouse(event) {
		seguiScroll(event);
		
    var altezza = 1;
	if(navigator.userAgent.indexOf('MSIE')<0){
	  altezza=document.documentElement.scrollTop;
	}else{ 
	  altezza=document.body.scrollTop;
	}
// Col movimento del mouse mette le icone in cima alla pagina. Se voglio metterle al centro dividere per 2 anzichè 200
// 			document.getElementById('destra').style.top        = altezza+document.documentElement.clientHeight/200+'px';
// 			document.getElementById('sinistra').style.top        = altezza+document.documentElement.clientHeight/200+'px';
// 			document.getElementById('home').style.top        = altezza+document.documentElement.clientHeight/200+'px';

// Le icone seguono il movimento del mouse
			document.getElementById('destra').style.top        = altezza+event.clientY - 20 +'px';
			document.getElementById('sinistra').style.top        = altezza+event.clientY - 20 +'px';
			document.getElementById('home').style.top        = altezza+event.clientY - 20 +'px';
}

function parametri(){
	var param = [], coppiaValori;
	var arrayCoppie = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < arrayCoppie.length; i++)
	{
		coppiaValori = arrayCoppie[i].split('=');
		//alert('coppiaValori = '+coppiaValori);
		param.push(coppiaValori[0]);
		param[coppiaValori[0]] = coppiaValori[1];
	} 
	ThisPage=param['id'];
}

 function crea_tabella(lang){
	prodotti1= new Array("Turtle","Antares","Ufo","Sky","Thunder","Moon","Sun","Land","Bellatrix","Rain","Ciop","Ciops","Cip","Cips","Space","Ice","Fat","Vega","Sirio","Fog","Fogs","Aledan","Aledans","Storm","Alien","Teti","Pegaso","Lux");
	prodotti2 = new Array("Light","Rigel mini","Rigel maxi","Green","Carlux","Walklux","Steplux","Waylux","Star","Urano","Saturno","Plutone","Nettuno","Eye","Drop","Cloud","Rainbow","Eclipse","Globolux","Globolight","Globolens","Cometa","Iadi","Ellisse","Luna","Venere");
	numerazione1= new Array(9,12,15,18,20,22,24,26,31,34,37,40,43,49,55,65,70,75,81,87,93,99,105,111,121,128,134,141);
	numerazione2= new Array(145,148,154,161,167,170,175,178,182,185,189,193,197,201,204,210,215,221,226,228,229,230,231,243,245,247);
	genera_tabella(prodotti1,numerazione1,'tab1',0,lang);
	genera_tabella(prodotti2,numerazione2,'tab2',prodotti1.length,lang);
 }
 
 function genera_tabella(prodotti,numerazione,tab,incremento,lang){
	if(lang=="IT"){lang='';}
	var tabella=document.createElement("TABLE");
	var corpo=document.createElement("TBODY");
	tabella.setAttribute('width','70%');
	tabella.setAttribute('id','tabella3');
	for(var i=1;i<=prodotti.length;i++)
        {
			riga=document.createElement("TR");
			colonna=document.createElement("TD");
			colonna.setAttribute('id','etichetta');
			colonna.innerHTML="<a href=\"Pagina"+lang+".html?id="+numerazione[i-1]+"\">"+prodotti[i-1]+"<\/a>";
			riga.appendChild(colonna);
			colonna=document.createElement("TD");
			colonna.setAttribute('id','immagine');
			colonna.innerHTML="<a href=\"Pagina"+lang+".html?id="+numerazione[i-1]+"\">"+"<img src=\"icone/"+(i+incremento)+"i.jpg\" \/>"+"<\/a>";
			riga.appendChild(colonna);
			corpo.appendChild(riga);
         }
	 tabella.appendChild(corpo);
	 document.getElementById(tab).appendChild(tabella);
  }

