// file global.js

function get_window_size() {
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	arrayWindowSize = new Array(windowWidth, windowHeight);
	return(arrayWindowSize);
}

function hide_all_submenu() {
	for(var i = 1; i <= num_link; i++) {
		if ($('submenu_' + i)) Element.hide('submenu_' + i);
	}

	if ($('link_id_' + active_submenu)) {
		if (Element.hasClassName('link_id_' + active_submenu, 'over')) {
			Element.removeClassName('link_id_' + active_submenu, 'over');
		}
	}
}

function show_submenu(number) {
	if ($('submenu_' + number)) {
		Element.show('submenu_' + number);
		active_submenu = number;

		if ($('link_id_' + active_submenu)) {
			if (Element.hasClassName('link_id_' + active_submenu, 'over')) {
				Element.removeClassName('link_id_' + active_submenu, 'over');
			}
		}

		if ($('link_id_' + number)) {
			if (!Element.hasClassName('link_id_' + number, 'over')) {
				Element.addClassName('link_id_' + number, 'over');
			}
		}
	}
}

function hide_submenu(number) {
	if ($('submenu_' + number)) {
		Element.hide('submenu_' + number);
	}
}

var active_submenu = 0;
var revert_delay = 1000;
var revert_timeout = 500;
var revert_time = 0;
var timeout_id;

function start_revert() {
	revert_time = revert_delay;
	timeout_id = window.setTimeout('do_revert()', revert_timeout);
}

function do_revert() {
	revert_time = revert_time - revert_timeout;

	if (revert_time < 0) {
		hide_submenu(active_submenu);
		if ($('link_id_' + active_submenu)) {
			if (Element.hasClassName('link_id_' + active_submenu, 'over')) {
				Element.removeClassName('link_id_' + active_submenu, 'over');
			}
		}
		active_submenu = 0;
	}
	else {
		timeout_id = window.setTimeout('do_revert()', revert_timeout);
	}
}

function stop_revert() {
	if (timeout_id) window.clearTimeout(timeout_id);
}

function setHtmlLayer(layer, html) {

	if (document.layers) eval('document.'+layer+'.document.writeln("'+html+'")');
	else if (document.all) eval('document.all.'+layer+'.innerHTML="'+html+'"');
	else {
		var span_el = document.getElementById(layer);
		var new_txt = document.createTextNode(html);
		span_el.replaceChild(new_txt, span_el.childNodes[0]);
	}

	return(0);

}

function setClock() {

	var months=new Array();
	months[0]='01';
	months[1]='02';
	months[2]='03';
	months[3]='04';
	months[4]='05';
	months[5]='06';
	months[6]='07';
	months[7]='08';
	months[8]='09';
	months[9]='10';
	months[10]='11';
	months[11]='12';

	var days=new Array();
	days[0]='domenica';
	days[1]='lunedì';
	days[2]='martedì';
	days[3]='mercoledì';
	days[4]='giovedì';
	days[5]='venerdì';
	days[6]='sabato';
	
	var data=new Date();

	var anno=data.getFullYear();
	var mese=months[data.getMonth()];
	var giorni=data.getDate();
	var giorno=days[data.getDay()];
	var ore=data.getHours();
	var minuti=data.getMinutes();
	var secondi=data.getSeconds();

	anno=anno.toString();
	
	giorni=giorni.toString();
	for (i=giorni.length;i<2;i++) giorni="0"+giorni;

	ore=ore.toString();
	for (i=ore.length;i<2;i++) ore="0"+ore;

	minuti=minuti.toString();
	for (i=minuti.length;i<2;i++) minuti="0"+minuti;

	var dataHtml = 'Roma ' + giorni + '/' + mese + '/' + anno + ' ' + ore + ':' + minuti;

	setHtmlLayer('clock', dataHtml);

	document.getElementById('clockContainer').title='la data corrente è ' + dataHtml;
	
	window.setTimeout("setClock()", 60000 - (secondi * 1000));

	return(0);

}

