﻿$(document).ready(function() {
    $("a[rel='external']").attr("target", "_blank");

    $(".voce_menu:first").click(function() {
        $(".voci_sottomenu").toggle("normal");
        $("#riquadro_dettaglio").hide("normal");
        $("#riquadro_help").hide();
    });


    $(".help").click(function() {
        $(".voci_sottomenu").hide("normal");
        $("#riquadro_dettaglio").hide();
        $("#riquadro_help").show();
    });

    $(".link_dettaglio a").click(function(ev) {
        ev.preventDefault();
        var strPath = $(this).attr('href') + '.xml';
        var strTesto = "";

        $("#immagine_dettaglio").attr('src', '');
        $("#immagine_dettaglio").attr('alt', '');
        $("#titolo_dettaglio").text('');
        $("#testo_dettaglio").text('');
        $("#link_dettaglio").attr('href', '');
        $("#link_dettaglio").text('');

        $(".duecolonne").hide();
        $("#loading").show();
        
        $.ajax({
            type: "GET",
            url: strPath,
            dataType: "xml",
            success: function(xml) {

                var nome = $("nome", xml).text();
                var immagine = $("immagine", xml).text();
                var descrizione = $("descrizione", xml).text();
                var link = $("link", xml).text();

                if (document.images)
                {
                  preload_image = new Image();
                  preload_image.src = 'http://localhost:58671/' + immagine; 
                }

                $("#immagine_dettaglio").attr('src', immagine);
                $("#immagine_dettaglio").attr('alt', nome);
                $("#titolo_dettaglio").text(nome);
                $("#testo_dettaglio").text(descrizione);

                $("#link_dettaglio").attr('href', 'http://' + link);
                $("#link_dettaglio").text(link);

                $("#loading").hide();
                $(".duecolonne").show();
                $("#riquadro_dettaglio").show("normal");
            }
        });
    });

});

function chiudidettaglio()
{
    $("#riquadro_dettaglio").hide("normal");
}

function chiudihelp() {
    $("#riquadro_help").hide("normal");
}
