/**********************************************\
| funzioni per versione AGANOOR  -  15-06-2009 |
\**********************************************/


var posi = 0, l = "";
//var imgbottoni = parent.document.images;
var imgbottoni = parent.document;

function dove(cosa) {
	percorso = new String(document.URL);
	lung = percorso.length;
	var c = 0;
	if (percorso.lastIndexOf("/it/") != -1) {
		c = percorso.lastIndexOf("/it/");
		l = "/it/";
	}
	if (percorso.lastIndexOf("/en/") != -1) {
		c = percorso.lastIndexOf("/en/");
		l = "/en/";
	}
	if (percorso.lastIndexOf("/es/") != -1) {
		c = percorso.lastIndexOf("/es/");
		l = "/es/";
	}
	if (c == 0) {
		parte = percorso.lastIndexOf("/"); //cerca l'ultima barra
		primaparte = percorso.substring(0,parte); //togli il nome di questo documento
		pagina = percorso.substring(parte,lung); //solo il nome di questo documento
		//alert("c = 0 : tutto meno nome doc");
	} else {
		if (posi != 0) {
			primaparte = percorso.substring(0,posi);
			//alert("posi != 0 : posi=\n" + posi);
		} else {
			primaparte = percorso.substring(0,c);
			//primaparte = percorso.lastIndexOf(0,c);
			//alert("nelle cartelle, da 0 a c: "+c);
			pagina = percorso.substring(c,lung);
		}
		//ultima = percorso.substring(c,lung); //ultima parte meno la cartella percorso
		//alert("si trova nella cartelle IT \n>" + c + "\n\n>" + primaparte); // + "\n\n>>" + ultima
		//alert("percorso:\n" +percorso+ "\n\n pos it: " +c+ "\n\n posi= " + posi + "\n\n>" + primaparte);
	}
	if (cosa == "pagina") {
		return pagina;
	} else {
		return primaparte;
	}
}



function sopra() {
	var sopra, fascione, seiqui, apriPagina;
	sopra = new String(window.parent.location);
	//fascione = sopra.lastIndexOf("index.");
	fascione = (sopra.substring(sopra.length-1) != "/") ? sopra.lastIndexOf("bbaganoor.") : sopra.lastIndexOf("/");
	if (fascione == -1) {
		seiqui = dove("cartella"); //cartella del sito
		apriPagina = dove("pagina"); //pagina da far aprire
		if (window.parent.location.protocol == "file:") {
			window.parent.location = seiqui + "/index.html?pag=" + apriPagina;	//IN LOCALE
		} else {
			//SUL SERVER
			var rf = document.referrer;
			if (rf.lastIndexOf("?") != -1) {
				dato = escape(rf); // + "&RF=" + history.length);
			} else {
				dato = escape(rf); // + "/RF" + history.length);
			}
			document.cookie = "provrf=" + dato + "; path=/";	
			
			window.parent.location = seiqui + "/bbaganoor.html?pag=" + apriPagina;
		}
	}
}
sopra();

/*
function strisciaBottoni(im,mappa) {
	f=parent.document.forms;
	rif = f[0].pag.value;
	if (rif != im + l) {
		ind = dove(0);
		//alert("ind:\n" + ind);
		
		imgbottoni[1].src = ind + l + "pulsanti/" + im + ".jpg";
		if (mappa == "") {
			imgbottoni[1].useMap = "";
		} else imgbottoni[1].useMap = mappa;
		
		f[0].pag.value = im + l;
		
		switch (im) {
			case "Benvenuti" :
				imgmenu[0].src = ind + "/Immagini/corniceLegno/AganoorJURASSIC-sopra.jpg";
				imgbottoni[1].src = ind + "/it/pulsanti/Benvenuti.jpg";
				break;
			case "Cantine" :
				imgmenu[0].src = ind + "/Immagini/corniceLegno/CantineJURASSIC-sopra.jpg";
				imgbottoni[1].src = ind + "/it/pulsanti/Benvenuti-cantine.jpg";
				break;
			//default :
				//imgmenu[0].src = ind + "/Immagini/corniceLegno/JURASSIC-logo_thule.jpg";
				//imgbottoni[0].src = ind + "/Immagini/corniceLegno/sl3.gif";
		}
	}
}*/
function strisciaBottoni(im,mappa) {
	f=parent.document.forms;
	rif = f[0].pag.value;
	if (rif != im + l) {
		ind = dove("cartella");
		//alert("ind:\n" + ind);
		//imgbottoni = parent.document.images;
		//imgbottoni[1].src = ind + l + "pulsanti/" + im + ".jpg";
		if (mappa == "") {
			imgbottoni.getElementById("fascione").useMap = "";
		} else {
			sigla = l.substring(1, 3);
			imgbottoni.getElementById("pulsanti").useMap = mappa + "_" + sigla;
		}
		f[0].pag.value = im + l;
		switch (im) {
			case "Benvenuti" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/AganoorJURASSIC-sopra.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Benvenuti.jpg";
				break;
			case "Cantine" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/CantineJURASSIC-sopra.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Cantine.jpg";
				break;
			case "Nahual" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/NAHUAL.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/NAHUAL.jpg";
				break;
			case "Woermann" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/WOERMANN.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Woermann.jpg";
				break;
			case "Setten" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/SETTEN.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Setten.jpg";
				break;
			case "Baite" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/BAITE.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Baite.jpg";
				break;
			case "Rizzetto" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/RIZZETTO.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Rizzetto.jpg";
				break;
			case "Dare" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/DARE.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Dare.jpg";
				break;
			case "Alme" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/ALME.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Alme.jpg";
				break;
			case "Fantasia" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/FANTASIA.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Fantasia.jpg";
				break;
			case "Liz" :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/LIZ.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + l + "pulsanti/Liz.jpg";
				break;
			default :
				imgbottoni.getElementById("fascione").src = ind + "/Immagini/corniceLegno/AganoorJURASSIC-sopra.jpg";
				imgbottoni.getElementById("pulsanti").src = ind + "/it/pulsanti/Benvenuti.jpg";
		}
	}
}


function cambiaMenu(quale) {
	switch (quale) {
		case "Benvenuti" :
			strisciaBottoni(quale,"#mappa");
			break;
		case "Cantine" :
			strisciaBottoni(quale,"#mappaCantine");
			break;
		case "Nahual" :
			strisciaBottoni(quale,"#mappaNahual");
			break;
		case "Woermann" :
			strisciaBottoni(quale,"#Woermann");
			break;
		case "Setten" :
			strisciaBottoni(quale,"#mappaCantine");
			break;
		case "Baite" :
			strisciaBottoni(quale,"#mappaCantine");
			break;
		case "Rizzetto" :
			strisciaBottoni(quale,"#mappaCantine");
			break;
		case "Dare" :
			strisciaBottoni(quale,"#mappaCantine");
			break;
		case "Alme" :
			strisciaBottoni(quale,"#mappaCantine");
			break;
		case "Fantasia" :
			strisciaBottoni(quale,"#Fantasia");
			break;
		case "Liz" :
			strisciaBottoni(quale,"#Liz");
			break;
		//default : 
			//parent.document.images['bf'].src = "Immagini/mappa.gif"; 
	} 
	
}


function cartellaImmagini() {
	ind_img = new String(document.images[0].src);
	//l_ind = ind_img.length;
	posCartella = ind_img.lastIndexOf("/Immagini/");
	cartella = ind_img.substring(0,posCartella+10);
	return cartella;
}

function attesaCaricamento(n) {
	if (n == 1) {
		parent.document.getElementById("caricaFoto").style.visibility = "visible";
	} else {
		parent.document.getElementById("caricaFoto").style.visibility = "hidden";
	}
}

function fotoSfondo(nome,numero) {
	pimg = cartellaImmagini();
	var nrimg = -10;
	if (numero > 0) {
		attesaCaricamento(1);
		while (nrimg <= 0) {
			nrcs = Math.random();
			nrimg = Math.round(nrcs * numero);
		}
		click = (numero == 1) ? ' usemap="#Sfondo"' : 'onclick="altrafoto()" title="click per vedere un\'altra foto\nclick to view more photos"';
		//document.write('<img id="fsfondo" name="fsfondo" src="' + pimg + 'sfondi/' + nome + nrimg + '.jpg" usemap="#Sfondo" border="0">'); // height="332" width="763">');
		document.write('<img id="fsfondo" name="fsfondo" src="' + pimg + 'sfondi/' + nome + nrimg + '.jpg" '+click+' border="0">');
		//
		parent.document.getElementById("imgsfondo").value = pimg + "sfondi/" + nome + ";" + numero;
		parent.document.getElementById("numfoto").value = nrimg;
		//document.forms[0].nomefoto.value = nome;
		//document.forms[0].numerofoto.value = numero;
		//var t = setTimeout("attesaCaricamento(0)",5000);
		var attesainiz = (numero == 1) ? '' : setTimeout("girafoto()",6000);
	} else {
		//document.write('<img src="' + pimg + 'sfondi/' + nome + '.jpg">');
		document.write('<img id="fsfondo" name="fsfondo" src="' + pimg + 'sfondi/' + nome + '.jpg" usemap="#Sfondo" border="0">');
		//width="791" height="333"
	}
	if (window.parent.location.protocol == "http:") {
		//per aganoor.it
		//document.writeln('<br><img src="http://stat.superstat.info/spider.php?u=9947" width="1" height="1"> <script type="text/javascript" language="JavaScript"  src="http://stat.superstat.info/counter.php?user=9947"> <\/script>');
	}
}


function SuccessivaFotoSfondo() {
	imgsfondo = parent.document.getElementById("imgsfondo").value;
	numfoto = parseInt(parent.document.getElementById("numfoto").value);
	urlimg = imgsfondo.substring(0,imgsfondo.lastIndexOf(";"));
	numero = parseInt(imgsfondo.substring(imgsfondo.lastIndexOf(";")+1,imgsfondo.length));
	nrimg = (numfoto == numero) ? 1 : numfoto+1;
	parent.document.getElementById("numfoto").value = nrimg;
	return (urlimg + nrimg + ".jpg");
}



//******************************************************************************************************
// IXF1.11 :: Image cross-fade 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
//******************************************************
//global object
var ixf = { 'clock' : null, 'count' : 1 }
/*******************************************************



/*****************************************************************************
 List the images that need to be cached
*****************************************************************************/
var nFotoSfondo = SuccessivaFotoSfondo();
ixf.imgs = [
	nFotoSfondo,
	nFotoSfondo+1,
	nFotoSfondo+2
	];

//ixf.imgs = ['/Immagini/sfondi/Info/Infoit1.jpg'];

/*****************************************************************************
*****************************************************************************/



//cache the images
ixf.imgsLen = ixf.imgs.length;
ixf.cache = [];
for(var i=0; i<ixf.imgsLen; i++)
{
	ixf.cache[i] = new Image;
	ixf.cache[i].src = ixf.imgs[i];
}


//crossfade setup function
function crossfade()
{
	//if the timer is not already going
	if(ixf.clock == null)
	{
		//copy the image object 
		ixf.obj = arguments[0];
		
		//copy the image src argument 
		ixf.src = arguments[1];
		
		//store the supported form of opacity
		if(typeof ixf.obj.style.opacity != 'undefined')
		{
			ixf.type = 'w3c';
		}
		else if(typeof ixf.obj.style.MozOpacity != 'undefined')
		{
			ixf.type = 'moz';
		}
		else if(typeof ixf.obj.style.KhtmlOpacity != 'undefined')
		{
			ixf.type = 'khtml';
		}
		else if(typeof ixf.obj.filters == 'object')
		{
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			ixf.type = (ixf.obj.filters.length > 0 && typeof ixf.obj.filters.alpha == 'object' && typeof ixf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			ixf.type = 'none';
		}
		
		//change the image alt text if defined
		if(typeof arguments[3] != 'undefined' && arguments[3] != '')
		{
			ixf.obj.alt = arguments[3];
		}
		
		//if any kind of opacity is supported
		if(ixf.type != 'none')
		{
			//create a new image object and append it to body
			//detecting support for namespaced element creation, in case we're in the XML DOM
			ixf.newimg = document.getElementsByTagName('body')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));

			//set positioning classname
			ixf.newimg.className = 'idupe';
			
			//set src to new image src
			ixf.newimg.src = ixf.src

			//move it to superimpose original image
			ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
			ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
			
			//copy and convert fade duration argument 
			ixf.length = parseInt(arguments[2], 10) * 1000;
			
			//create fade resolution argument as 20 steps per transition
			ixf.resolution = parseInt(arguments[2], 10) * 20;
			
			//start the timer
			ixf.clock = setInterval('ixf.crossfade()', ixf.length/ixf.resolution);
		}
		
		//otherwise if opacity is not supported
		else
		{
			//just do the image swap
			ixf.obj.src = ixf.src;
		}
		
	}
};


//crossfade timer function
ixf.crossfade = function()
{
	//decrease the counter on a linear scale
	ixf.count -= (1 / ixf.resolution);
	
	//if the counter has reached the bottom
	if(ixf.count < (1 / ixf.resolution))
	{
		//clear the timer
		clearInterval(ixf.clock);
		ixf.clock = null;
		
		//reset the counter
		ixf.count = 1;
		
		//set the original image to the src of the new image
		ixf.obj.src = ixf.src;
	}
	
	//set new opacity value on both elements
	//using whatever method is supported
	switch(ixf.type)
	{
		case 'ie' :
			ixf.obj.filters.alpha.opacity = ixf.count * 100;
			ixf.newimg.filters.alpha.opacity = (1 - ixf.count) * 100;
			break;
			
		case 'khtml' :
			ixf.obj.style.KhtmlOpacity = ixf.count;
			ixf.newimg.style.KhtmlOpacity = (1 - ixf.count);
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			ixf.obj.style.MozOpacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
			ixf.newimg.style.MozOpacity = (1 - ixf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			ixf.obj.style.opacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
			ixf.newimg.style.opacity = (1 - ixf.count);
	}
	
	//now that we've gone through one fade iteration 
	//we can show the image that's fading in
	ixf.newimg.style.visibility = 'visible';
	
	//keep new image in position with original image
	//in case text size changes mid transition or something
	ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
	ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
	
	//if the counter is at the top, which is just after the timer has finished
	if(ixf.count == 1)
	{
		//remove the duplicate image
		ixf.newimg.parentNode.removeChild(ixf.newimg);
	}
};



//get real position method
ixf.getRealPosition = function()
{
	this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
	this.tmp = arguments[0].offsetParent;
	while(this.tmp != null)
	{
		this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
		this.tmp = this.tmp.offsetParent;
	}
	
	return this.pos;
};
//******************************************************************************************************


function girafoto() {
	var fotosuccessiva = SuccessivaFotoSfondo();
	crossfade(document.getElementById('fsfondo'), fotosuccessiva, '4', 'ciao')
	tempogiro = setTimeout("girafoto()",10000);
}

function attesaCaricamento(n) {
	if (n == 1) {
		parent.document.getElementById("caricaFoto").style.visibility = "visible";
	} else {
		parent.document.getElementById("caricaFoto").style.visibility = "hidden";
	}
}

function altrafoto() {
	attesaCaricamento(1);
	clearTimeout(tempogiro);
	imgsfondo = parent.document.getElementById("imgsfondo").value;
	numfoto = parseInt(parent.document.getElementById("numfoto").value);
	urlimg = imgsfondo.substring(0,imgsfondo.lastIndexOf(";"));
	numero = parseInt(imgsfondo.substring(imgsfondo.lastIndexOf(";")+1,imgsfondo.length));
	
	nrimg = (numfoto == numero) ? 1 : numfoto+1;
	parent.document.getElementById("numfoto").value = nrimg;
	//document.getElementById("fsfondo").src = urlimg + nrimg + ".jpg";
	
	var successiva = urlimg + nrimg + ".jpg";
	crossfade(document.getElementById('fsfondo'), successiva, '4', 'Aganoor')
	
	var t = setTimeout("attesaCaricamento(0)",5000);
	
	/*
	pimg = cartellaImmagini();
	var nrimg = -10;
	if (numero > 0) {
		while (nrimg <= 0) {
			nrcs = Math.random();
			nrimg = Math.round(nrcs * numero);
		}
	}
	alert(pimg + "sfondi/" + nome + nrimg + ".jpg")
	alert("img= " + document.images["fsfondo"].src); //document.images
	*/
	//window.location.reload();
}

function mostra(n_info) {
	document.getElementById(n_info).style.visibility = "visible";
}


function nascondi(n_info) {
	document.getElementById(n_info).style.visibility = "hidden";
}





/*
function cambia(lingua) {
	percorso = new String(parent.frames[2].document.URL);
	lung = percorso.length;
	var l = 0;
	if (percorso.search("/it/") != -1) l = percorso.search("/it/");
	if (percorso.search("/en/") != -1) l = percorso.search("/en/");
	if (percorso.search("/es/") != -1) l = percorso.search("/es/");
	primaparte = percorso.substring(0,l+1);
	pag = percorso.substring(l+3,lung);
	
	imgmenu[1].src = primaparte + lingua + "/pulsanti/menu_" + lingua + ".jpg";   //it/pulsanti/menu_it.jpg
	imgmenu[1].useMap = "#MENU" + lingua;
	parent.document.getElementById("pag").src = primaparte + lingua + pag;
	parent.document.getElementById("strisciapulsanti").src = primaparte + lingua + "/pulsanti_" + lingua + ".html";
	//imgbottoni[0].useMap =
	
}
*/

function aprimlist(paginaml) {
	window.open(paginaml, "mailinglist", "status=no,toolbar=no,location=no,directories=no,resizable=yes,scrollbars=yes,menubar=no,height=345,width=550");
	
}




