window.onload = init;

function init() {
	setLinks();
	flContentInit();
}

function setLinks() {
	if (document.getElementsByTagName) {
		var links = document.getElementsByTagName("a");
		for (var i=0;i<links.length; i++) {
			if (links[i].getAttribute("href") && links[i].getAttribute("rel") == "external") links[i].target = "_blank";
		}
	}
}

function getConsiglio(giorno) {
    var url = "./Consiglio.aspx?giorno=" + giorno;
    document.location.href = url;
}

function openInformativa() {
    window.open('/popup/privacy.html','privacy','width=580,height=300,scrollbars=yes,resizable=no');
}

function openInformativaEsperto() {
    window.open('/popup/privacy-esperto.html','privacyEsperto','width=580,height=300,scrollbars=yes,resizable=no');
}

function openInformativaContatti() {
    window.open('/popup/privacy-contatti.html','privacyContatti','width=580,height=300,scrollbars=yes,resizable=no');
}

function openInformativaDiLaTua() {
    window.open('/popup/privacy-dilatua.html','privacyDiLaTua','width=580,height=300,scrollbars=yes,resizable=no');
}

function openPrivacy() {
    window.open('/popup/privacy-sito.html','privacySito','width=580,height=300,scrollbars=yes,resizable=no');
}

function openPrivacyHome() {
    window.open('/popup/privacy-home.html','privacySito','width=580,height=300,scrollbars=yes,resizable=no');
}

function openDatiSocietari() {
    window.open('/popup/dati_societari.html','datiSocietari','width=580,height=300,scrollbars=yes,resizable=no');
}

function openCredits() {
    window.open('/popup/credits.html','credits','width=334,height=333,scrollbars=no,resizable=no');
}
function openRisultati() {
    window.open('/popup/risultati_concorso.html','risultati_concorso','width=580,height=300,scrollbars=yes,resizable=no');
}

function switchContent(id, total, name) {
    for (var i=0; i < total; i++) {
        document.getElementById(name + i).className = name + "Text hidden";
        document.getElementById("lnk" + i).className = "";
    }
    if (active != id) {
        document.getElementById(name + id).className = name + "Text";
        document.getElementById("lnk" + id).className = "active";
        active = id;
    } else {
        active = 999;
    }
}
/**
 * videoDemo player
 */
/**
 *(Number) waitStart variable timeout to start videoDemo
 */
var waitStart = -1;
/**
 *flContentInit function set "jsReady=true" if page is ready
 */
function flContentInit(){
	jsReady = true;
	if(getSWF("videoDemo") != null) waitStart = setInterval(startVideo , 1500);
}
/**
 *(Boolean) jsReady variable checked from flash to know if page is ready
 */
var jsReady = false;
/**
 *isReady function is called from flash to know if page is ready
 */
function isReady()
{
    return jsReady;
}
/**
 * startVideo function call flash "startVideo" exposed method
 */
function startVideo(){
	clearInterval(waitStart);
	var video = getSWF("videoDemo");
	if (video != null) {
		video.startVideo();
	}
}
/**
 * getSWF function
 * @param	(String) movieName:id of object/embed element
 * @return	(Object) DOM reference toobject/embed element
 */
function getSWF(movieName){
	return document.getElementById(movieName);
}