$(document).ready(function() {
	init(menu);
	


})



function apri_chiudi_layer(nomelayer) {
	
	if (document.getElementById(nomelayer).style.display == "none") {
		document.getElementById(nomelayer).style.display = "block";
	} else {
		document.getElementById(nomelayer).style.display = "none";
	}
	
}

//INIZIO  BANNER  RANDOM,  GESTIONE  CASUALE

var banners = new Array();
var bannersprovv = new Array();


banners[0] = "<a href='http://www.creditocooperativo.it' target='_blank' title='Vai al sito del Credito Cooperativo'><object type='application/x-shockwave-flash' data='../images/banner_728x90_1.swf' width='647' height='80'><param name='movie' value='../images/banner_728x90_1.swf' /><param name='wmode' value='opaque'><\/object></a>";
banners[1] = "<a href='http://www.creditocooperativo.it' target='_blank' title='Vai al sito del Credito Cooperativo'><object type='application/x-shockwave-flash' data='../images/banner_728x90_1.swf' width='647' height='80'><param name='movie' value='../images/banner_728x90_1.swf' /><param name='wmode' value='opaque'><\/object></a>";
banners[2] = "<a href='http://www.creditocooperativo.it' target='_blank' title='Vai al sito del Credito Cooperativo'><object type='application/x-shockwave-flash' data='../images/banner_728x90_1.swf' width='647' height='80'><param name='movie' value='../images/banner_728x90_1.swf' /><param name='wmode' value='opaque'><\/object></a>";


function ricreaarray() {
	for (i = 0; i < banners.length; i++) {
		var temp = banners[i];
		bannersprovv[i] = temp;
	}
}

function generarandom(max) {
	var casuale = Math.floor(Math.random() * max);
	return casuale;
}

function randombanner() {

	if (bannersprovv.length == 0) {
		ricreaarray();
	}

	var numerogenerato = generarandom(bannersprovv.length);
	document.getElementById('bannerareabcc').innerHTML = bannersprovv[numerogenerato];
	bannersprovv.splice(numerogenerato,1);

}

// FINE  BANNER  RANDOM,  GESTIONE  CASUALE

window.onload=function() {
if(document.getElementsByTagName && document.getElementById){
    document.getElementById("navigation").className="jsenable";
    BuildList();
    }
}

function BuildList(){
var hs=document.getElementById("navigation").getElementsByTagName("h3");
var ss=document.getElementById("navigation").getElementsByTagName("div");

for(var i=0;i<hs.length;i++){
    hs[i].onclick=function(){
        this.parentNode.className=(this.parentNode.className=="show") ? "hide" : "show";
        }
    }

for(var i=0;i<ss.length;i++){
    ss[i].onclick=function(){
        this.parentNode.parentNode.parentNode.className="hide";
        this.parentNode.parentNode.parentNode.getElementsByTagName("a")[0].focus();
        }
    }

} 

function showdiv(div){	
	if (document.getElementById(div).style.display == 'none')	{
		document.getElementById(div).style.display='block';
	} else {
		document.getElementById(div).style.display='none';
	}
}

function portasu() {document.body.scrollTop; scrollTo(0,0);
}

function  controlla_contatti() {
var contatti=document.contatti;
var msg="Alcuni campi non sono completi!";
	if ((document.getElementById('email').value!="") && ((document.getElementById('email').value.indexOf('@') == -1) || (document.getElementById('email').value.indexOf('.') == -1))) {alert("Il campo -- E-mail -- non contiene un indirizzo valido!"); document.getElementById('email').focus(); return false;};
	if (contatti.nome.value=="") {alert(msg); contatti.nome.focus();return false;};
	if (contatti.commenti.value=="")	{alert(msg); contattis.commenti.focus();return false;};
	
	return true;
}





function setActiveStyleSheet(title) {
	for (var i=0; i<document.getElementsByTagName("link").length; i++) {
		var a=document.getElementsByTagName("link")[i];
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		 a.disabled=true;
		 if(a.getAttribute("title") == title) a.disabled=false;
		}
	}
}

function getActiveStyleSheet() {

	for (var i=0; i<document.getElementsByTagName("link").length; i++) {
		var a=document.getElementsByTagName("link")[i];
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && (a.disabled == false)) {
			cssattivo=a.getAttribute("title");
			break;
		}
	}
	return cssattivo;
}

function swapstyle(css) {
	setActiveStyleSheet(css);
}


function gallerychiuditutto(numerofoto) {
	
	for (i=1; i <=numerofoto; i++) {
		document.getElementById('gallery'+i).style.display='none';	
	}
}
								
				
function aprichiudigallery(numerofoto,id) {

	if (document.getElementById(id).style.display=='block'){
		document.getElementById(id).style.display='none';
		gallerychiuditutto(numerofoto);				
	} else {
		document.getElementById(id).style.display='block';
	}
}
