// JavaScript Document
document.top = 0;
document.top2 = 0;
document.attfoto = 0;
document.attevidenza = 0;
document.attbanner = 0;
document.arrayfoto = new Array();
document.arraydidascalie = new Array();
document.arraylink = new Array();
document.arraybanner = new Array();
function controllatotali() {
	if (!document.totalefoto) {
		nascondi('cont_foto');
		nascondi('cont_button_foto');
	} else {
		if (document.totalefoto == 1) {
			nascondi('cont_frecce_foto');
		}
	}
	if (!document.totaleevidenza) {
		nascondi('cont_evidenza');
		nascondi('cont_button_evidenza');
	} else {
		if (document.totaleevidenza == 1) {
			nascondi('cont_frecce_evidenza');
		}
	}
}
function caricaflash(file, w, h, ver, div) {
	var sofileflash = new SWFObject(file, "fileflash", w, h, ver, 'trasparent');
	sofileflash.addParam("wmode", "transparent");
	sofileflash.write(div);
}
function nascondi(iddiv){
  document.getElementById(iddiv).style.display = 'none';
  document.getElementById(iddiv).innerHTML += "";
}
function mostra(iddiv){
  document.getElementById(iddiv).style.display = 'inline';
  document.getElementById(iddiv).innerHTML += "";
}
function aggiornafoto(idimm, didascalia, idfoto){
  	document.arrayfoto.push(idimm);
  	document.arraydidascalie.push(didascalia);
  	if (idfoto == (document.totalefoto-1)) {
		$('fotoid0').appear({ afterFinish: function() {
			if (document.totalefoto>1) {
				loop_foto = setTimeout(muovifoto,6000);
			}
		} });
	}
}
function aggiornaevidenza(links, idevidenza){
  document.arraylink.push(links);
  if (idevidenza == (document.totaleevidenza-1)) {
		$('evidenzaid0').appear({ afterFinish: function() {
			if (document.totaleevidenza>1) {
				loop_evidenza = setTimeout(muovievidenza, 6000);
			}
		} });
	}
}
function aggiornabanner(links, idbanner){
  	document.arraybanner.push(links);
  	if (idbanner == (document.totalebanner-1)) {
		$('bannerid0').appear({ afterFinish: function() {
			if (document.totalebanner>1) {
				loop_banner = setTimeout(cambiabanner, 10000);
			}
		} });
	}
}
function cambiabanner(){
	var tot = document.totalebanner-1;
	if (tot > 0) {
		var att = document.attbanner;
		if (att+1 > tot) {
			var next_att = 0;
		} else {
			var next_att = att+1;
		}
		$('bannerid'+next_att).appear({ duration: 2.5, from: 0.0, to: 1.0 });
		$('bannerid'+att).fade({ duration: 3.0, afterFinish: function() { 
			document.attbanner = next_att;			
			loop_banner = setTimeout(cambiabanner,12000);
		} });
	}
}
function aprifoto() {
	var att = document.attfoto;
	var f = document.arrayfoto[att];
  	var d = document.arraydidascalie[att];
  	flashLightbox(f, d);
}
function aprievidenza() {
	var att = document.attevidenza;
  	var d = document.arraylink[att];
	window.open(d);
}
function aprilinkbanner() {
	var att = document.attbanner;
  	var d = document.arraybanner[att];
	if (d != '') window.open(d);
}
function muovifoto(dir) {
	if (!dir) dir = -1;
	var tot = document.totalefoto-1;
	if (tot > 0) {
		clearTimeout(loop_foto);
		var att = document.attfoto;
		var top = document.top;
		if (att-dir > tot) {
			var next_att = 0;
			var newtop = 0;
		} else if (att-dir < 0) {
			var next_att = tot;
			var newtop = (-180*tot);
		} else {
			var next_att = att-dir;
			var newtop = top+(dir*180);
		}
		document.top = newtop;
		document.attfoto = next_att;
		$('fotoid'+att).fade({ duration: 0.5, afterFinish: function() { 
			document.getElementById('lista_foto').style.marginTop=newtop+'px';
			$('fotoid'+next_att).appear({ from: 0.0, to: 1.0 });
		} });
		loop_foto = setTimeout(muovifoto,6000);
	}
}
function muovievidenza(dir) {
	if (!dir) dir = -1;
	var tot = document.totaleevidenza-1;
	if (tot > 0) {
		clearTimeout(loop_evidenza);
		var att = document.attevidenza;
		var top = document.top2;
		if (att-dir > tot) {
			var next_att = 0;
			var newtop = 0;
		} else if (att-dir < 0) {
			var next_att = tot;
			var newtop = (-180*tot);
		} else {
			var next_att = att-dir;
			var newtop = top+(dir*180);
		}
		document.top2 = newtop;
		document.attevidenza = next_att;
		$('evidenzaid'+att).fade({ duration: 0.5, afterFinish: function() { 
			document.getElementById('lista_evidenza').style.marginTop=newtop+'px';
			$('evidenzaid'+next_att).appear({ from: 0.0, to: 1.0 });
		} });
		loop_evidenza = setTimeout('muovievidenza(-1)',6000);
	}

}
function didascalia(sn) {
	if (sn == '1') {
		var att = document.attfoto;
		var di = document.arraydidascalie[att];
		document.getElementById('didascalia').innerHTML = di;
		mostra('didascalia');
	} else {
		document.getElementById('didascalia').innerHTML = "";
		nascondi('didascalia');
	}
}
function check_login(user, pwd) {
	var username = document.getElementById(user).value;
	var password = document.getElementById(pwd).value;
	if (username == "" || password == "") {
		alert ("Inserire il nome utente e la password!");
		document.valorediritorno = false;
	} else {
		document.valorediritorno = true;
	}
}