
function start_all() {

	Start_insegne_lights();

}




function Start_insegne_lights() {

		var struct = new Array(); //viene creato l'array
		struct [0]= document.getElementById("bannerA");
		struct [1]= document.getElementById("bannerB");
		fader(struct, 10000, 1000, 0);
		
}



/*
 * Fader funzionante - Costruttore
 */
function fader(struct, timeout, speed, random_speed)
{
	var rand_no = Math.random();
	rand_no = (rand_no * random_speed) + timeout;
	
	var index = 1;
	var length = struct.length;

	if (length > 1) {


		window.setTimeout(function(){fader_fade(struct, timeout, speed, random_speed, index, length);},rand_no);
	}
}
/*
 * Fader funzionante - esecutore
 */
function fader_fade(struct, timeout, speed, random_speed, index, length) {
	
	var old;
	var act;		
	if (index == 0) {
		old = struct[length - 1];
		act = struct[index];
		
	} else {
		old = struct[index - 1];
		act = struct[index];
	}
	
	var fx = new Fx.Styles(act, {duration:speed, wait:false});
	fx.start({ 'opacity': 1 });
	
	var fx2 = new Fx.Styles(old, {duration:speed, wait:false});
	fx2.start({ 'opacity': 0 });
	
	index = index + 1;
	if (index >= length) {
		index = 0;
	}
	
	var rand_no = Math.random();
	rand_no = (rand_no * random_speed) + timeout;
	window.setTimeout(function(){fader_fade(struct, timeout, speed, random_speed, index, length);},rand_no);
	
}


/**
 * switcher senza sfumatura con opacità.
 */
function initialize(struct, timeout)
	{
		//struct = structure;		
		//index = 0;
		var length = struct.length;

		if (length > 1) {


			window.setTimeout(function(){animate(timeout,0,struct,length);},0);
		}
	}
 
function animate(timeout,indx,struct,length)
	{
		shift1 = Math.floor(length / 2);
		shift2 = Math.floor(2 * (length / 3));
		var index = indx;
		var index_2 = ((indx+shift1) % length);
		var index_3 = ((indx+shift2) % length);
		var old;
		var act;
		var old_2;
		var act_2;
		var old_3;
		var act_3;	
		if (index == 0) {
			old = struct[length - 1];
			act = struct[index];
			
		} else {
			old = struct[index - 1];
			act = struct[index];
		}
		
		if (index_2 ==  0) {
			old_2 = struct[length - 1];
			act_2 = struct[index_2];
			
		} else {
			old_2 = struct[index_2 - 1];
			act_2 = struct[index_2];
		}
		
		if (index_3 ==  0) {
			old_3 = struct[length - 1];
			act_3 = struct[index_3];
			
		} else {
			old_3 = struct[index_3 - 1];
			act_3 = struct[index_3];
		}
		
		index = index + 1;
		if (index >= length) {
			index = 0;
		}

		old.style.visibility = "hidden";
		act.style.visibility = "visible";
		old_2.style.visibility = "hidden";
		act_2.style.visibility = "visible";
		/*old.style.opacity = 0;
		act.style.opacity = 1;
		old_2.style.opacity = 0;
		act_2.style.opacity = 1;*/
		/*old_3.style.opacity = 0.30;
		act_3.style.opacity = 1;*/
		
		var rep = "animate("+timeout+")";
		window.setTimeout(function(){animate(timeout,index,struct,length);},timeout);

		//window.setTimeout(function(){animate(timeout)}, timeout);
		
		//window.setTimeout(this.animate(),3000);
		
	}

/**
 * switcher senza sfumatura senza opacità.
 */
function initialize_windows(struct, timeout, amount)
	{
		//struct = structure;		
		//index = 0;
		var length = struct.length;

		if (length > 1) {


			window.setInterval(function(){animate_windows(timeout,1,struct,length,amount);},timeout);
		}
	}
 
function animate_windows(timeout,indx,struct,length,amount)
	{
		if (amount < 1) {
			amount = 1;
		} else if (amount > length) {
			amount = length;
		}
		for (var i= 1; i<amount; i++) {
			switch_windows(timeout,indx,struct,length);
		}
	}
function switch_windows(timeout,indx,struct,length)
{
	var index = indx;
	
	var rand_no = Math.random();
	rand_no = rand_no * length;
	rand_no = Math.floor(rand_no);

	act = struct[rand_no];

	
	/*if (act.style.visibility == "visible") {
		act.style.visibility = "hidden";
	} else {
		act.style.visibility = "visible";
	}*/
	if (act.style.display == "none") {
		act.style.display = "block";
	} else {
		act.style.display = "none";
	}
}



