var timer_sub;
timer_sub=new Array(7);

function hide_submenu(i) {
	obj='sub'+i;
	if (timer_sub[i]!=null) {clearTimeout(timer_sub[i]); timer_sub[i]=null;}
	timer_sub[i]=setTimeout("timer_sub["+i+"]=null; $('sub"+i+"').style.display='none'",300);
}

function show_submenu(i) {
	if ($('sub'+i).style.display=='none') Effect.BlindDown('sub'+i,{duration:0.5});
}

function hide(oggetto) {
	$(oggetto).style.display='none';
}
function show(oggetto,classe) {
	$(oggetto).style.display='block';
}

function oscura() {
	for (i=1;i<=4;i++) {
		obj=$('top'+i);
		obj.className='oscurato';
	}
}

function sfuma(id) {
	new Effect.Fade($('top'+id),{duration:3.0, from:1.0, to:0.5});
	
	id++;
	if (id>4) id=1;
	window.setTimeout("slideshow("+id+")",3000);
}

function slideshow(id) {
	oscura();
	obj=$('top'+id);
	obj.className='';
	new Effect.Appear(obj,{duration:3.0, from:0.5, to:1.0});

	window.setTimeout("sfuma("+id+")",7000);
}

function init() {
//	oscura();
//	$('top1').className='';
//	sfuma(1);
}

// dissolvenza homepage
conta=1;
tot=0;

function offusca() {
	temp=$$('.foto_hp')[(conta-1)];
	new Effect.Fade(temp,{duration:1.0});
	conta++;
	if (conta==tot+1) conta=1;
	window.setTimeout("hp_show()",1000);
}

function hp_show() {
	i=1;
	$$('.foto_hp').each (function(element) {
		if (conta==i) temp=element;
		else element.style.display='none';
		i++;
	});
	if (tot==0) tot=i-1;
	new Effect.Appear(temp,{duration:1.0});
	window.setTimeout("offusca()",4000);
}

function add_category() {
	var nome  = Prompt.show('Inserire nome nuova societa\'');
	if (nome!='')
	var myAjax = new Ajax.Request(
		'add_societa.php', 
		{method: 'get', parameters: 'action=create&nome='+nome, onComplete: add_category_return});
}

function change_category() {
	nome_old=$('societa_nomi').options[$('societa_nomi').selectedIndex].text;
	value_old=$('societa_nomi').options[$('societa_nomi').selectedIndex].value;
	var nome  = Prompt.show('Inserire il nuovo nome per la societa\' "'+nome_old+'"');
	if (nome!='')
	if (window.confirm('Confermi il nuovo nome "'+nome+'" in sostizione a "'+nome_old+'"?')) {
		var myAjax = new Ajax.Request(
			'add_societa.php', 
			{method: 'get', parameters: 'action=change&old='+value_old+'&nome='+nome, onComplete: add_category_return});
	}
}

function add_category_return(originalRequest) {
	var risposta=originalRequest.responseText;
	$('elenco_societa').innerHTML=risposta;
}

var timerB;

function test2(cont) {
	$('foto_animato').src='images/home'+cont+'.jpg';
	Effect.Grow('foto_animato',{duration:1});
	timerB=setTimeout("test("+cont+")",7000);
}

function test(cont) {
	Effect.Shrink('foto_animato',{duration:1});
	cont++; if (cont>4) cont=1;
	timerB=setTimeout("test2("+cont+")",1100);
}

function banner_animato(cont) {
	cont++; if (cont>3) cont=1;
	$('b1').className='spento'; $('b2').className='spento'; $('b3').className='spento';
	$('b'+cont).className='';
	timerA=window.setTimeout('banner_animato('+cont+')',1000);
}
