﻿function assegnaClasse(idLink) {
    try {
        eliminaClasse();
        //
        var num;
        if (idLink < 10)
            num = "0" + idLink;
        else
            num = idLink;
        var elemento = document.getElementById("link" + num);
        if (elemento != null) {
            //elemento.setAttribute("class", "selezionato");
            //elemento.className = "menu_sel";
            if(idLink < 9)
                elemento.style.backgroundImage = "url('/img/TastoMenuSelezionato.jpg')";
        }
        var elemento2 = document.getElementById("linkBasso" + num);
        var elemento3 = document.getElementById("tasto" + num);
        if (elemento2 != null) {
            switch(idLink) {
                case 9:
                    elemento3.style.backgroundImage = "url('/img/InternoTastoAltoMenuSecondarioSelezionato.jpg')";
                    var elemento4 = document.getElementById("angolo1");
                    var elemento5 = document.getElementById("angolo2");
                    elemento4.style.backgroundImage = "url('/img/SxTastoAltoMenuSecondarioSelezionato.jpg')";
                    elemento5.style.backgroundImage = "url('/img/DxTastoAltoMenuSecondarioSelezionato.jpg')";
                    break;
                case 10:
                    //Tasto interno
                    elemento3.style.backgroundImage = "url('/img/TastiInterniMenuSecondarioSelezionato.jpg')";
                    break;
                case 11:
                    //Tasto interno
                    elemento3.style.backgroundImage = "url('/img/TastiInterniMenuSecondarioSelezionato.jpg')";
                    break;
                case 12:
                    elemento3.style.backgroundImage = "url('/img/InternoTastoBassoMenuSecondarioSelezionato.jpg')";
                    var elemento6 = document.getElementById("angolo3");
                    var elemento7 = document.getElementById("angolo4");
                    elemento6.style.backgroundImage = "url('/img/SxTastoBassoMenuSecondarioSelezionato.jpg')";
                    elemento7.style.backgroundImage = "url('/img/DxTastoBassoMenuSecondarioSelezionato.jpg')";
                    break;
            }
            
            
            //elemento2.className = "menu_sel";
        }
        //
        var elemento3 = document.getElementById("imglink" + num);
        if (elemento3 != null) {
            if (idLink < 10)
                elemento3.className = "img_menuSelezionato";
            else
                elemento3.className = "img_menuBassoSelezionato";
        }

        if (idLink > 12) {
            var elemento8 = document.getElementById("menuServizio" + idLink);
            if (elemento8 != null)
                elemento8.style.color = "Red";
        }
    }
    catch (error) {
        //fai nulla
    }
}

function eliminaClasse() {
    try {
        for (i = 1; i <= 15; i++) {
            var num;
            if (i < 10)
                num = "0" + i;
            else
                num = i;
            var elemento = document.getElementById("link" + num);
            if (elemento != null)
                elemento.className = null;
            //
            /*
            var elemento2 = document.getElementById("linkBasso" + num);
            if (elemento2 != null)
                elemento2.className = null;
            */
            //
            var elemento3 = document.getElementById("imglink" + num);
            if (elemento3 != null)
                elemento3.className = "img_menu";
        }
    }
    catch (error) {
        //fai nulla
    }
}


function sistemaAltezze() {
    var elemento1 = document.getElementById("contenitorePrincipale");
    var elemento2 = document.getElementById("colonnaSx");
    var elemento3 = document.getElementById("colonnaDx");
    if ((elemento1 != null) & (elemento2 != null) & (elemento3 != null)) {
        elemento2.style.height = (elemento1.offsetHeight + 10) + 'px';
        elemento3.style.height = elemento1.offsetHeight + 'px';
    }
}


function selezionaElMenuSec(idLink, idElSelez) {
    deselezionaElMenuSec(idLink);
    assegnaClasse(idElSelez);
}

function deselezionaElMenuSec(idLink) {
    var elemento1 = document.getElementById("tasto09");
    var elemento2 = document.getElementById("tasto10");
    var elemento3 = document.getElementById("tasto11");
    var elemento4 = document.getElementById("tasto12");
    if (elemento1 != null) {
        elemento1.style.backgroundImage = "url('/img/InternoTastoAltoMenuSecondario.jpg')";
        elemento2.style.backgroundImage = "url('/img/TastiInterniMenuSecondario.jpg')";
        elemento3.style.backgroundImage = "url('/img/TastiInterniMenuSecondario.jpg')";
        elemento4.style.backgroundImage = "url('/img/InternoTastoBassoMenuSecondario.jpg')";
    }
    //

    var elemento6 = document.getElementById("angolo1");
    var elemento7 = document.getElementById("angolo2");
    if (elemento6 != null)
        elemento6.style.backgroundImage = "url('/img/SxTastoAltoMenuSecondario.jpg')";
    if (elemento7 != null)
        elemento7.style.backgroundImage = "url('/img/DxTastoAltoMenuSecondario.jpg')";
    var elemento8 = document.getElementById("angolo3");
    var elemento9 = document.getElementById("angolo4");
    if (elemento8 != null)
        elemento8.style.backgroundImage = "url('/img/SxTastoBassoMenuSecondario.jpg')";
    if (elemento9 != null)
        elemento9.style.backgroundImage = "url('/img/DxTastoBassoMenuSecondario.jpg')";
    //Infine, ripristina selezione tasti corretta
    assegnaClasse(idLink);

}



function seleziona(id, nomeDiv, nomeClasse) {
    var elemento = document.getElementById(nomeDiv + id);
    if (elemento != null) {
        elemento.className = nomeClasse;
    }
    var navigatore = navigator.appName;

    var boxGrigio = document.getElementById("box" + id);
    if (boxGrigio != null) {
        elemento.style.top = boxGrigio.offsetTop + 'px';
        if (nomeDiv != "ombra")
            elemento.style.left = boxGrigio.offsetLeft - 13 + 'px';
        else
            elemento.style.left = boxGrigio.offsetLeft - 10 + 'px';
        elemento.style.width = boxGrigio.offsetWidth + 'px';
        elemento.style.height = boxGrigio.offsetHeight + 'px';
    }
}

function deseleziona(nomeClasse) {
    try {
        var elemento = document.getElementsByTagName("div");
        for (i = 1; i < elemento.length; i++)
            if (elemento[i].className == nomeClasse)
                elemento[i].className = "trasparente";

        /*
        for (i = 1; i <= 20; i++) {
        var elemento = document.getElementById(nomeDiv + i);
        elemento.className = "trasparente";
        }
        */
    }
    catch (error) {
        //fai nulla
    }
}

function vaiapagina(pagina) {
    document.location.href = pagina;
}


//funzioni della pagina squadra

function visualizzaScheda(idScheda) {
    var el01 = document.getElementById("panel01");
    //
    var elemento = document.getElementById("panel0" + idScheda);
    if (elemento != null) {
        elemento.className = "visibile";
        //elemento.style.top = el01.style.top;
        elemento.style.height = "auto";
    }
    //contenitoreAjax
    //divDettaglioAtleta
    //contenitorePannelli
    var elemento2 = document.getElementById("contenitorePannelli");
    var elemento3 = document.getElementById("divDettaglioAtleta");
    var elemento4 = document.getElementById("contenitoreAjax");
    var elemento5 = document.getElementById("divDescrizDettaglio");
    
    try {

        try {
            if (idScheda == 1) {
                elemento5.style.height = "100%";
                var elemento6 = document.getElementById("divImmagineAtleta");
                elemento6.style.height = "100%";
            }
            else
                elemento5.style.height = "0";
        }
        catch (Error) { }
        /*
        if (idScheda == 4) {
        elemento.style.height = "650px";
        elemento2.style.height = "650px";
        elemento3.style.height = "950px";
        elemento4.style.height = "100%";
        }
        if (idScheda == 3) {
        elemento.style.height = "750px";
        elemento2.style.height = "750px";
        elemento3.style.height = "1050px";
        elemento4.style.height = "100%";
        }
        */
        if (idScheda < 5) {
            if (elemento2 != null) {
                elemento2.style.height = elemento.offsetHeight + 'px';
                elemento3.style.height = (elemento2.offsetHeight + elemento2.offsetTop) + 'px';
                elemento4.style.height = "110%";
            }

        }


    }
    catch (Error) {

    }
}


function tastoPremuto(idTasto) {
    deselezionaTasti("visibile");
    //
    var elemento2 = document.getElementById("btnDettaglio0" + idTasto);
    elemento2.className = "tastoSelezionato";
    //
    if (idTasto == 3)
        visualizzaFotografie();
    if (idTasto == 4)
        visualizzaFilmato();
    //
    visualizzaScheda(idTasto);
}

function deselezionaTasti(nomeClasse) {
    try {
        var elemento = document.getElementsByTagName("div");
        for (i = 1; i < elemento.length; i++)
            if (elemento[i].className == nomeClasse)
                elemento[i].className = "nascosto";
        //        
        for (i = 1; i <= 4; i++) {
        var elemento2 = document.getElementById("btnDettaglio0" + i);
        elemento2.className = "tastoDeselezionato";
        //elemento2.style.backgroundColor = "#e7e7dd";
        //elemento2.style.color = "#000000";
        }
    }
    catch (error) {
        //fai nulla
    }
}


//funzione per visualizzare il filmato video del corridore selezionato
/*
function visualizzaFilmato() {
    try
    {
        var nomeFilmFLV = document.getElementById("nomeFilmato");
        var nomeFileFLV = "";
        if (nomeFilmFLV != null) 
        {
            var spanFile = nomeFilmFLV.childNodes[0];
            if (spanFile != null)
            {
                nomeFileFLV = spanFile.innerHTML;
                //alert("Nome file FLV= " + spanFile.innerHTML);
            }
            else 
            {
                nomeFileFLV = "";
                //alert("spanFile nullo!");
            }
        }
        //alert(nomeFileFLV);
        var fo = new SWFObject("./flash/video/VideoFLV.swf", "VideoFLV", "455px", "320px", "9", "#ffffff");
        fo.addParam("wmode", "transparent");
        fo.addParam("allowfullscreen", "true");
        fo.addParam("bgcolor", "ffffff");
        fo.addParam("allowscriptaccess", "always");
        fo.addParam("FlashVars", "nomeFilmato=" + nomeFileFLV);
        fo.write("flash_gallery");
    }
    catch (error)
    {
        //fai nulla
    }
}
*/
function visualizzaFilmato() {
    try {
        var divFilmFLV = document.getElementById("variabiliFilmato");
        var variabiliFilmFLV = "";
        if (divFilmFLV != null) {
            //Nome cartella
            var spanFile = divFilmFLV.getElementsByTagName("span")[0]; //.childNodes[0];
            if (spanFile != null) {
                //alert(spanFile.innerHTML)
                variabiliFilmFLV += "nomeFilmato=/flash/video/" + spanFile.innerHTML;
            }

            //Titolo Filmato
            var spanFile = divFilmFLV.getElementsByTagName("span")[1]; //.childNodes[2];
            if (spanFile != null) {
                variabiliFilmFLV += "/" + spanFile.innerHTML;
                nomeFilm = spanFile.innerHTML;
                //alert("Nome file FLV= " + spanFile.innerHTML);
            }
            //Nomi capitoli
            for (i = 2; i <= 8; i++) {
                var spanFile = divFilmFLV.getElementsByTagName("span")[i]; //.childNodes[i * 2];
                if (spanFile != null) {
                    if (spanFile.innerHTML != "")
                        variabiliFilmFLV += "&titolo0" + (i - 1) + "=" + spanFile.innerHTML;
                    //alert("Nome file FLV= " + spanFile.innerHTML);
                }
                else
                    i = 18;
            }
        }
        //alert(nomeFileFLV);
        var fo = new SWFObject("./flash/VideoFLV.swf", "VideoFLV", "750px", "540px", "9", "#ffffff");
        fo.addParam("wmode", "transparent");
        fo.addParam("allowFullScreen", "true");
        //alert(variabiliFilmFLV);
        fo.addParam("FlashVars", variabiliFilmFLV);
        fo.write("flashContent");
    }
    catch (error) {
        //fai nulla
    }
}

function visualizzaFotografie() {
    try {
        var nomeFilmato = "Fotografie";
        //nomeGalleria
        var nomeGalleria = document.getElementById("nomeGalleria");
        var nomeFileGalleria = "";
        if (nomeGalleria != null) {
            var spanFile = nomeGalleria.childNodes[0];
            if (spanFile != null)
                nomeFileGalleria = spanFile.innerHTML;
            else
                nomeFileGalleria = "";
        }
        //tipoGalleria
        var tipoGalleria = document.getElementById("tipoGalleria");
        if (tipoGalleria != null) {
            var spanFile = tipoGalleria.childNodes[0];
            if (spanFile != null)
                tipoGalleria = spanFile.innerHTML;
            else
                tipoGalleria = "";
            if (tipoGalleria == "Nuovo")
                nomeFilmato = "FotografieNew"
        }
        //percorsoGalleria
        var percorsoGalleria = document.getElementById("percorsoGalleria");
        var percorsoFileGalleria = "";
        if (percorsoGalleria != null) {
            var spanFile2 = percorsoGalleria.childNodes[0];
            if (spanFile2 != null)
                percorsoFileGalleria = spanFile2.innerHTML;
            else
                percorsoFileGalleria = "";
        }
        //
        var dimAltezza = "500px";
        if (tipoGalleria == "Nuovo")
            dimAltezza = "650px";
        var fo = new SWFObject("/flash/" + nomeFilmato + ".swf", nomeFilmato, "455px", dimAltezza, "9", "#ffffff");
        fo.addParam("wmode", "transparent");
        fo.addParam("bgcolor", "ffffff");
        if (tipoGalleria == "Nuovo") {
            fo.addParam("allowfullscreen", "true");
            fo.addParam("allowscriptaccess", "always");
            fo.addParam("FlashVars", "galleryURL=" + percorsoFileGalleria + nomeFileGalleria);
        }
        else {
            fo.addParam("FlashVars", "nomeGalleria=" + nomeFileGalleria + "&percorsoGalleria=" + percorsoFileGalleria);
            fo.addParam("allowfullscreen", "true");
        }
        fo.write("divFotografie");
    }
    catch (error) {
        //fai nulla
    }
}

function visualizzaGalleriaFotografica() {

    //try {
        var fo = new SWFObject("./flash/FotografieNew.swf", "viewer", "900px", "1060px", "8", "#ffffff");

        //percorsoGalleria
        var percorsoGalleria = document.getElementById("percorsoGalleria");
        var percorsoFileGalleria = "";
        if (percorsoGalleria != null) {
            var spanFile2 = percorsoGalleria.childNodes[0];
            if (spanFile2 != null)
                percorsoFileGalleria = spanFile2.innerHTML;
            else
                percorsoFileGalleria = "";
        }

        // SIMPLEVIEWER CONFIGURATION OPTIONS
        // To use an option, uncomment it by removing the "//" at the start of the line
        // For a description of config options, go to: 
        // http://www.airtightinteractive.com/simpleviewer/options.html

        //fo.addVariable("xmlDataPath", "gallery.xml");
        //fo.addVariable("firstImageIndex", "5");	
        //fo.addVariable("langOpenImage", "Open Image in New Window");
        //fo.addVariable("langAbout", "About");
        //fo.addVariable("preloaderColor", "0x000000");
        fo.addParam("allowfullscreen", "true");
        fo.addVariable("preloaderColor", "0x000000");
        fo.addVariable("xmlDataPath", percorsoFileGalleria);
        fo.addParam("wmode", "transparent");
        fo.write("flash_gallery");
    //}
    //catch (error) {
        //fai nulla
    //}
}
