Shadowbox.init({
    // let's skip the automatic setup because we don't have any
    // properly configured link elements on the page
    
    });




$(document).ready(function(){


  
 

    //funzione per i toggle generale
    var id_class=".testata";
    $(id_class).next().hide();
    $(id_class).click(function(){
        //aggiunge o toglie la classe active se presente o meno
        $(this).hasClass("active")?$(this).removeClass("active"):$(this).addClass("active");
        //rimuove le classi live da ogni elemento
        $(id_class).removeClass("live");
        //accoda la classe live a questo elemento
        $(this).addClass("live");
        //toglie tutte le classi active dagli elementi non live
        $(id_class+":not(.live)").removeClass("active");
        //chiude tutti gli elementi che non hanno la classe live
        $(id_class+":not(.live)").next().slideUp("slow");
        //intercetto questo elemento
        var elemento=$(this)
        //apro o chiudo questo elemento e scrollo al termine
        $(this).hasClass("active")?elemento.next().slideToggle("slow",function(){
            $.scrollTo(elemento,1000,{
                axis:'y'
            })
        }):elemento.next().slideToggle("slow",function(){
            //$.scrollTo('0px',1000,{
            //  axis:'y'
            //})
            });

    })



    //funzione per over tasti


    var arr = {
        date:"date",
        biografia:"biografia",
        media:"media",
        contatti:"contatti"
    };


    jQuery.each(arr, function(i, val) {
        $("#"+i+" .testata").hover(
            function () {
                $(this).append("<div class='over'>sdfsdfsfsd</div>");
                $("#"+i+" .over").css("background-image","url(../img/"+val+"_up.jpg)").hide().fadeIn("fast");
                //$(this).css("background-image","url(../img/"+val+"_up.jpg)");
            },
            function () {
                $("#"+i+" .over").fadeOut("fast",function(){
                    $(this).remove();
                })
                //$(this).css("background-image","url(../img/"+val+".jpg)");
            }
            )


    })

 




    //---------------------------


    //funzione per il caricamento delle date

    $aprimappa=function(valore){
        //alert(valore);
        Shadowbox.open({
            content:    valore,
            player:     "iframe",
            title:      "Mappa",
            height:     500,
            width:      500
        })

        

    }

    $.ajax({
        type: "GET",
        url: "date.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('data_singola').each(function(){
                            
                var data = $(this).find('data').text();
                var posto = $(this).find('posto').text();
                var indirizzo = $(this).find('indirizzo').text();
                var link = $(this).find('link').text();

                var mappa="maps.php?address="+$.URLEncode(indirizzo);
                
                $("#date .contenuti").append("\
                <div class='data_singola'>\n\
                    <div class='data_dafare'>"+data+"</div>\n\
                    <div class='posto'>"+posto+"</div>\n\
                    <div class='indirizzo'>"+indirizzo+"</div>\n\
                    \n\
                    \n\
                    <div class='mappa'>\n\
                    <a href='#' onclick='$aprimappa(\""+mappa+"\");return false;' title='Mappa'>\n\
                    Come Arrivare<img src='img/icon_info.gif' />\n\
                    </a>\n\
                    </div>\n\
                    \n\
                    \n\
                    <div class='link'><a href='"+link+"' title='"+posto+"' target='_blank'>"+link+"<img src='img/icon_get_world.gif' /></a></div>\n\
                </div>");
                
       
            });
                        
        }
    });

    

    //--------------------------------------



    //youtube--------------------------------------
    $(".demo1 li a").click(function(){
       $(".demo1 li a").removeClass("currentvideo");
        $(this).addClass("currentvideo");
        var split =$(this).attr('href').split("=");
        var parametri=play(split[1],263,394,'','&rel=0','&autoplay=1');
        $("#ytvideo").empty();
        $("#ytvideo").append(parametri);
        return false;
    })



    function play(id,playerHeight,playerWidth,screen,showRelated,autoPlay){
        var html  = '';
        html += '<object height="'+playerHeight+'" width="'+playerWidth+'">';
        html += '<param name="movie" value="http://www.youtube.com/v/'+id+autoPlay+showRelated+screen+'"> </param>';
        html += '<param name="wmode" value="transparent"> </param>';
        if(screen) {
            html += '<param name="allowfullscreen" value="true"> </param>';
        }
        html += '<embed src="http://www.youtube.com/v/'+id+autoPlay+showRelated+screen+'"';
        if(screen) {
            html += ' allowfullscreen="true" ';
        }
        html += 'type="application/x-shockwave-flash" wmode="transparent"  height="'+playerHeight+'" width="'+playerWidth+'"></embed>';
        html += '</object>';

        return html;

    }
//--------------------------------------



});