var mgr;
var lastmarker = null;
var allabonnes = [];
var allnonabonnes = [];
var allpano = [];
var visiblemarkers = [];
var map;
var labelRadar = null;
var labe; // objet eLabel du radar Google MAP
var angledefaut1 = 0; // angle par défaut envoyé au eLabel (radar Google)
var startX;
var startY;
var startTitle;
var titre;
var infowp = [];
var gauche;
var droite;
var pos = 0;
var idpano;
var langue = 'fr';
var langId = null;
var lastmarkerencours;
var newmarker;
var angleFinal = 0;
var allselectedlieu = new Array();
var selectedMarkerlieu;
var typemarkerprec;
var panodefaut=new Array();
var etatmarkerpast=0;
var issecteur=false;
var allsecteur=new Array();
var idsecteurtodel=0;
var idsecteurtodel2=0;
var secteurtoadd=null;
$(document).ready(function() {
    idpano = $('#idPanorama').val();
    langue = $('#language').val();
    if('fr' == langue ){
        langId = 2;
    }else if ('es' == langue){
        langId = 3;
    }else{
        langId = 1;
    }
    var resultat = getLatLng('ville', 1);

    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("carte"), {
            mapTypes : [ G_NORMAL_MAP, G_HYBRID_MAP, G_SATELLITE_MAP ]
        });
        map.setCenter(new GLatLng(resultat[0].x, resultat[0].y), parseInt(resultat[0].zoom));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        GEvent.addListener(map, "zoomend", function(){
            var niveauZoom = map.getZoom();
            if(niveauZoom==15){
                if(issecteur){
                    for ( var i = 0; i < allsecteur.length; i++) {
                        if(allsecteur[i].getId()==idsecteurtodel){
                            mgr.removeMarker(allsecteur[i].getMarker());
                            mgr.refresh();
                            secteurtoadd=allsecteur[i].getMarker();
                            idsecteurtodel2=1;
                            idsecteurtodel=0;
                        }
                    }
                }
            }
        });
        mgr = new MarkerManager(map, {
            trackMarkers : true
        });
        loadPano(idpano,1);
        setMarkersLieu();
        setMarkersPanorama();
    }
});
function setMarkersLieu() {
    $.ajax( {
        type : "POST",
        url : "/mode_debug/MVC_PATTERN/ajax/getLieux.php",
        data : "model=lieu&langue=" + langue,
        async : true,
        dataType : "json",
        success : function(data) {
            var length = data.length;
            if (length > 0) {
                for ( var i = 0; i < length; i += 1) {
                    var id = data[i].panorama_id;
                    var x = data[i].x;
                    var y = data[i].y;
                    var title = data[i].nom;
                    var code_typelieu = data[i].code;
                    var typelieu_id = data[i].tlid;
                    var abonne = data[i].abonne;
                    var partenaire = data[i].partenaire;
                    var lieuid=data[i].lieuid
                    if(code_typelieu!="Secteur"){
                        panodefaut.push(data[i].panorama_id);
                    }
                    if (code_typelieu == "secteur") {
                        var marker = createMarker(lieuid,false, new GLatLng(x,
                            y), title, getIconLieu(code_typelieu,
                            typelieu_id, abonne), id, abonne,
                        partenaire, 3,true,code_typelieu,typelieu_id,1,1);
                        var cmarker = new CMarker(marker,typelieu_id,id,0,1,lieuid,code_typelieu);
                        allsecteur.push(cmarker);
                        mgr.addMarker(marker, 7, 15);
                    } else {
                        if (abonne == 1) {
                            if (id > 0) {
                                var marker = createMarker(lieuid,true,
                                    new GLatLng(x, y), title,
                                    getIconLieu(code_typelieu,
                                        typelieu_id, abonne), id,
                                    1, partenaire, 3,true,code_typelieu,typelieu_id,0,2);
                                var cmarker = new CMarker(marker,typelieu_id,id,0,1,lieuid,code_typelieu);
                                allabonnes.push(cmarker);
                                if(lieuid!=idlieu) {
                                    mgr.addMarker(marker, 7);
                                }
                            }
                        } else {
                            var marker = createMarker(lieuid,true, new GLatLng(x, y),
                                title, getIconLieu(code_typelieu,
                                    typelieu_id, abonne,0), id, 0,
                                partenaire, 3,false,code_typelieu,typelieu_id,0,2);
                            var cmarker = new CMarker(marker,typelieu_id,id,0,0,lieuid,code_typelieu);
                            allnonabonnes.push(cmarker);
                            map.addOverlay(marker);
                            marker.hide();
                        }
                    }
                    if(lieuid==idlieu) {
                        if(typelieu_id!=16)
                        {
                            lastmarker=marker;
                        }
                        else
                        {
                            var icon = new GIcon(false,"/files/panoramas/images/panorama_12.png");
                            icon.iconSize = new GSize(12, 12);
                            icon.iconAnchor = new GPoint(6, 6);
                            icon.infoWindowAnchor = new GPoint(0,
                                -10);
                            lastmarker=createMarker(lieuid,true,
                                new GLatLng(x, y), title,icon, id,
                                1, partenaire, 3,true,code_typelieu,typelieu_id,0,3);
                        }
                        var icon3 = new GIcon(false,"/files/typelieu/"+ typelieu_id + "/" + code_typelieu + "_18v.png");
                        icon3.iconSize = new GSize(18,18);
                        icon3.iconAnchor = new GPoint(6, 6);
                        icon3.infoWindowAnchor = new GPoint(0, -10);
                        if(typelieu_id!=16)
                        {
                            newmarker=marker;
                        }
                        else
                        {

                            var icon = new GIcon(false,"/files/panoramas/images/panorama_12v.png");
                            icon.iconSize = new GSize(12, 12);
                            icon.iconAnchor = new GPoint(6, 6);
                            icon.infoWindowAnchor = new GPoint(0,
                                -10);
                            newmarker=createMarker(lieuid,true,
                                new GLatLng(x, y), title,icon, id,
                                1, partenaire, 3,true,code_typelieu,typelieu_id,0,3);

                        }

                    }
                }
            }
        },
        error : function(xhr, err, e) {
        // alert(err+"lieu");
        }
    });
}
function setMarkersPanorama() {
    $.ajax( {
        type : "POST",
        url : "/mode_debug/MVC_PATTERN/ajax/getPanorama.php",
        data : "langue=" + langue,
        async : true,
        dataType : "json",
        success : function(data) {
            var length = data.length;
            if (length > 0) {
                for ( var i = 0; i < length; i += 1) {
                    var id = data[i].id;
                    var x = data[i].x;
                    var y = data[i].y;
                    var title = data[i].nom;
                    var visible = parseInt(data[i].visible);
                    var lieu_id=data[i].lieu_id;
                    var spherique = parseInt(data[i].spherique);
                    if (visible == 1) {
                        if (spherique == 0) {
                            if (id > 0) {
                                icon = new GIcon(false,"/files/panoramas/images/panorama_8.png");
                                icon.iconSize = new GSize(8, 8);
                                icon.iconAnchor = new GPoint(4, 4);
                                icon.infoWindowAnchor = new GPoint(0,
                                    -10);
                                var marker = createMarker(0,true,
                                    new GLatLng(x, y), title, icon,
                                    id, 0, '', spherique,true,"","",0,3);
                                mgr.addMarker(marker, 16);
                            }
                        } else {
                            if (id > 0) {
                                icon = new GIcon(false,"/files/panoramas/images/panorama_12.png");
                                icon.iconSize = new GSize(12, 12);
                                icon.iconAnchor = new GPoint(6, 6);
                                icon.infoWindowAnchor = new GPoint(0,
                                    -10);
                                var marker = createMarker(0,true,
                                    new GLatLng(x, y), title, icon,
                                    id, 0, '', spherique,true,"","",0,3);
                                mgr.addMarker(marker, 16);
                            }
                        }
                    }

                    var cmarker = new CMarker(marker, '',id,spherique,0,lieu_id,'');

                    allpano.push(cmarker);

                    if(idpano ==id) {
                        etatmarkerpast=3;
                        if (spherique == 0) {
                            var icon3 = new GIcon(false,"/files/panoramas/images/panorama_8v.png");
                            icon3.iconSize = new GSize(8, 8);
                            icon3.iconAnchor = new GPoint(4, 4);
                            icon3.infoWindowAnchor = new GPoint(0, -5);
                        } else {
                            var icon3 = new GIcon(false,"/files/panoramas/images/panorama_12v.png");
                            icon3.iconSize = new GSize(12, 12);
                            icon3.iconAnchor = new GPoint(6, 6);
                            icon3.infoWindowAnchor = new GPoint(0, -10);
                        }
                        if(panodefaut.inArray(id)) {
                        } else {
                            lastmarker=marker;
                            mgr.removeMarker(lastmarker);
                            newmarker= createMarker(0,true,new GLatLng(x, y), title, icon3,id, 0, '', spherique,true,"","",0,3);
                            mgr.addMarker(newmarker, 16);
                        }
                    }

                }
            }

        },
        error : function(xhr, err, e) {
        // alert(err+"panorama");
        }
    });

}
function getLatLng(element, id) {
    var resultat = new Array();
    $.ajax( {
        type : "POST",
        url : "/mode_debug/MVC_PATTERN/ajax/getCoordonnees.php",
        data : "element=" + element + "&id=" + id,
        async : false,
        dataType : "json",
        success : function(data) {
            var length = data.length;
            if (length == 1) {
                resultat = data;
            }
        },
        error : function(xhr, err, e) {
            alert(err + "coordonnees");
        }
    });
    return resultat;
}
function getLieuUrl(id){
    if(id != 0){
        $.ajax({
            type: "POST",
            url: "/mode_debug/MVC_PATTERN/ajax/getLieuURL.php",
            data: "id="+id+"&langue="+langue,
            async: true,
            success: function(data){
                var url="/"+trim(data);
                $(location).attr('href',url);
            },
            error: function(xhr, err, e){
            // alert(err+"panorama+id");
            }
        });
    }
}
function getAngleDefaut(angledefaut) {
    if (angledefaut == "") {
        angledefaut = 0;
    }
    angledefaut1 = angledefaut;
}
function getIconLieu(typelieu_code, typelieu_id, abonne) {
    // secteur : icones des lieu du cas parcours guidé
    var icon;
    if (typelieu_code == "secteur") {
        image = "/files/typelieu/" + typelieu_id + "/" + typelieu_code + "_map.png";
        icon = new GIcon(false,image);
        icon.iconSize = new GSize(32, 32);
        icon.iconAnchor = new GPoint(16, 16);
    } else {
        if (abonne == 1) {
            image = "/files/typelieu/" + typelieu_id + "/" + typelieu_code + "_18.png";
            icon = new GIcon(false,image);
            icon.iconSize = new GSize(18, 18);
            icon.iconAnchor = new GPoint(9, 9);
        } else {
            image = "/files/typelieu/" + typelieu_id + "/" + typelieu_code + "_16.png";
            icon = new GIcon(false,image);
            icon.iconSize = new GSize(16, 16);
            icon.iconAnchor = new GPoint(8, 8);
        }
    }
    icon.infoWindowAnchor = new GPoint(0, -5);

    return icon;
}
function loadPanorama(id_panorama) {
    var markerpano=getMarkerPanoEnCours(id_panorama);
    if(markerpano!=null){
        var idlieucherche=markerpano.getIdLieu();
        var markeurLieu=getLieuMarkerEnRapport(idlieucherche);
        if(markeurLieu!=null) {
            var typelieu_id=markeurLieu.getTypeLieuId();
            var typelieu_code=markeurLieu.getCodeTypeLieu();
            var icon3 = new GIcon(false,"/files/typelieu/" + typelieu_id + "/" +typelieu_code+"_18.png");
            icon3.iconSize = new GSize(18,18);
            icon3.iconSize = new GSize(18,18);
            icon3.iconAnchor = new GPoint(6, 6);
            icon3.infoWindowAnchor = new GPoint(0, -10);
            lastmarker=markeurLieu.getMarker();
            mgr.removeMarker(lastmarker);
            var markerchange=markeurLieu;
        }
        else
        {
            if (markerpano.getSpherique() == 0){
                var icon3 = new GIcon(false,"/files/panoramas/images/panorama_8v.png");
                icon3.iconSize = new GSize(8, 8);
                icon3.iconAnchor = new GPoint(4, 4);
                icon3.infoWindowAnchor = new GPoint(0, -5);
            }else{
                var icon3 = new GIcon(false,"/files/panoramas/images/panorama_12v.png");
                icon3.iconSize = new GSize(12, 12);
                icon3.iconAnchor = new GPoint(6, 6);
                icon3.infoWindowAnchor = new GPoint(0, -10);
            }
            lastmarker=markerpano.getMarker();
            mgr.removeMarker(lastmarker);
            var markerchange=markerpano;


        }

        mgr.addMarker(newmarker, 16);
        mgr.refresh();
        newmarker=createMarker(0,true,lastmarker.getLatLng(),lastmarker.getTitle(), icon3,id_panorama,markerchange.getAbonne(),0,markerchange.getSpherique(),1,"","",0,3);

    }
    loadPano(id_panorama,0);
}
function getLieuMarkerEnRapport(id){
    var markerreturn=null;
    for ( var i = 0; i < allabonnes.length; i++) {
        if (allabonnes[i].getIdLieu() == id){

            markerreturn=allabonnes[i];
        }
    }
    return markerreturn;
}
function getMarkerPanoEnCours(id){
    var markerreturn=null;
    for ( var i = 0; i < allpano.length; i++) {
        //alert(allpano[i].getId());
        if (allpano[i].getId() == id){
            markerreturn=allpano[i];
        }
    }
    return markerreturn;
}
function loadPano(id_panorama,zoom) {
    try {
        if (id_panorama != 0) {
            $.ajax( {
                type : "POST",
                url : "/mode_debug/MVC_PATTERN/ajax/getOnePanorama.php",
                data : "id=" + id_panorama + "&langue=" + langue,
                async : true,
                dataType : "json",
                success : function(data) {
                    var length = data.length;
                    if (length == 1) {
                        var spherique = data[0].spherique;
                        var id = data[0].id;
                        startX = data[0].x;
                        startY = data[0].y;
                        startTitle = data[0].title;
                        idlieu=data[0].lieuid;
                        var date = new Date;
                        path = "files/panoramas/"+id+"/"+id+".xml?" + date.getTime();
                        addSWFObject(path);
                        var position = new GLatLng(startX, startY);
                        var image = "/files/panoramas/images/panorama_encours.png";
                        var icon2 = new GIcon();
                        icon2.image = image;
                        icon2.iconSize = new GSize(16, 16);
                        icon2.iconAnchor = new GPoint(8, 8);
                        icon2.infoWindowAnchor = new GPoint(0, -5);
                        if (lastmarkerencours != null) {
                            map.removeOverlay(lastmarkerencours.getMarker());
                        }
                        var ver = getInternetExplorerVersion();
                        if (ver > -1) {
                            // si ie 8
                            if (ver == 8) {
                                lastmarkerencours = new GMarker(position, {
                                    icon : icon2,
                                    draggable : false
                                });
                            } else {
                                lastmarkerencours = new GMarker(position, {
                                    icon : icon2,
                                    draggable : false,
                                    zIndexProcess : encoursOrder
                                });
                            }
                        } else {
                            lastmarkerencours = new GMarker(position, {
                                icon : icon2,
                                draggable : false,
                                zIndexProcess : encoursOrder
                            });
                        }
                        map.addOverlay(lastmarkerencours);
                        lastmarkerencours = new CMarkerEncours(lastmarkerencours, position, spherique,startTitle, id, '');
                        placeRadar(startX, startY);
                        if(zoom==1){
                            map.setZoom(16);
                        }
                        map.panTo(position);
                        afficheTexte(id,startTitle,data[0].meta,data[0].url,data[0].panoramaContents);
                    }
                },
                error : function(xhr, err, e) {
                // alert(err+"panorama ici +id");
                }
            });
        }
    } catch (e) {
    }
}
function addSWFObject(path) {
    var flashvars = {}
    flashvars.zoommin= "0.45";
    flashvars.langue=langue;
    flashvars.movie="/files/flash/pano.swf?xml_file=/" + path;
    flashvars.redirect=window.location;
    var params = {};
    params.allowFullScreen = true;
    params.allowScriptAccess = "sameDomain";
    params.wmode = "transparent";
    swfobject.embedSWF('/files/flash/show_pano.swf', 'flash',  '100%','100%', '8.0.0',
        '/files/flash/expressInstall.swf', flashvars, params);
}
function onPanoMove(test, angle) {
    angle = Math.round(parseInt(angle) / 15) * 15;
    var newAngle = parseInt(angledefaut1) + angle;
    if (newAngle > angleFinal + 8 || newAngle < angleFinal - 8) {
        angleFinal = newAngle;
        if (document.getElementById("radar") == null) {
            if (labelRadar != null) {
                position = labelRadar.getPoint();
                map.removeOverlay(labelRadar);
            //placeRadar(position, angleFinal);
            }
        } else {
            document.getElementById("radar").src = '/mode_debug/MVC_PATTERN/radar.php?angle=' + angleFinal;
        }
    }
}
function placeRadar(x, y) {
    var html = '<div id="radarcss"><img id="radar" width="75" height="75" src="/mode_debug/MVC_PATTERN/radar.php?angle=' + getAngleDefaut() + '" /></div>';
    var label = new ELabel(new GLatLng(x, y), html, "", new GSize(-36, 42), 0,
        true);
    // labelRadar : variable Globale
    if (labelRadar != null) {
        labelRadar.remove();
    }
    labelRadar = label;
    map.addOverlay(label);
}
function createMarker(lieuid,lirepanorama, posn, title, icon, id, abonne, partenaire,
    spherique,cliquable,typelieu_code,typelieu_id,secteur,markeretat) {
    var ver = getInternetExplorerVersion();
    // Si ie
    if (ver > -1) {
        // si ie 8
        if (ver == 8) {
            var marker = new GMarker(posn, {
                icon : icon,
                draggable : false,
                title:title
            });
        } else {
            // si autre que ie 8
            if (abonne == 1) {
                marker = new GMarker(posn, {
                    icon : icon,
                    draggable : false,
                    title:title,
                    zIndexProcess : importanceOrder
                });
            } else {
                marker = new GMarker(posn, {
                    icon : icon,
                    title:title,
                    draggable : false
                });
            }
        }
    } else {
        // Si firefox, Safari, Chrome, Opera ...
        if (abonne == 1) {
            marker = new GMarker(posn, {
                icon : icon,
                title:title,
                draggable : false,
                zIndexProcess : importanceOrder
            });
        } else {
            marker = new GMarker(posn, {
                icon : icon,
                title:title,
                draggable : false
            });
        }
    }
    GEvent.addListener(marker,'click',function() {

        if(idsecteurtodel2==1)
        {

            mgr.addMarker(secteurtoadd, 7, 15);

            idsecteurtodel2=0;
        }
        if(markeretat==1)
        {
            issecteur=true;
            markersecteur=marker;
            idsecteurtodel=id;
        }
        else
        {
            issecteur=false;
        }
        if(markeretat>1)
        {
            mgr.removeMarker(marker);
        }


        if(!cliquable){
            getLieuUrl(lieuid);
        }else{
            if(markeretat>1)
            {


                if (lastmarker != null){
                    mgr.removeMarker(lastmarker);
                }
                if(etatmarkerpast==3)
                {

                    mgr.addMarker(newmarker, 16);
                    mgr.refresh();


                }
                else if(etatmarkerpast==2)
                {

                    mgr.addMarker(newmarker, 7);

                }
                if(lieuid==0)
                {
                    if (spherique == 0){
                        var icon3 = new GIcon(false,"/files/panoramas/images/panorama_8v.png");
                        icon3.iconSize = new GSize(8, 8);
                        icon3.iconAnchor = new GPoint(4, 4);
                        icon3.infoWindowAnchor = new GPoint(0, -5);
                    }else{
                        var icon3 = new GIcon(false,"/files/panoramas/images/panorama_12v.png");
                        icon3.iconSize = new GSize(12, 12);
                        icon3.iconAnchor = new GPoint(6, 6);
                        icon3.infoWindowAnchor = new GPoint(0, -10);
                    }
                }
                else
                {

                    var icon3 = new GIcon(false,"/files/typelieu/" + typelieu_id + "/" +typelieu_code+"_18.png");
                    icon3.iconSize = new GSize(18,18);
                    icon3.iconSize = new GSize(18,18);
                    icon3.iconAnchor = new GPoint(6, 6);
                    icon3.infoWindowAnchor = new GPoint(0, -10);

                }


                lastmarker=marker;

                newmarker=createMarker(lieuid,true,posn,title, icon3,id, abonne,partenaire,spherique,cliquable,typelieu_code,typelieu_id,0,markeretat);



                etatmarkerpast=markeretat;


            }
            loadPano(id,secteur);
        }
    });
    // Ces événements sont communs a tous les marqueurs
    GEvent.addListener(marker, "mouseover", function() {
        var html = '<p>' + title + '</p>';
        marker.openExtInfoWindow(map, "simple_example_window", html, {
            beakOffset : 3
        });
    });
    GEvent.addListener(marker, "mouseout", function() {
        marker.closeExtInfoWindow(map);
    });

    return marker;
}
function CMarkerEncours(marker, pos, spherique, title, id, abonne, partenaire) {
    this.marker = marker;
    this.pos = pos;
    this.spherique = spherique;
    this.title = title;
    this.id = id;
    this.abonne = abonne;
    this.partenaire = partenaire;
}
function importanceOrder(marker) {
    return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance
    * 10000;
}
function encoursOrder(marker) {
    return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance
    * 10000000;
}
function CMarker(marker, typelieu_id , id,spherique,abonne,idlieu,codetypelieu) {
    this.marker = marker;
    this.typelieu_id  = typelieu_id ;
    this.id = id;
    this.spherique =spherique;
    this.abonne=abonne;
    this.idlieu=idlieu;
    this.codetypelieu=codetypelieu;
}
Array.prototype.inArray = function(val) {
    for(var i = 0; i < this.length; i++) {
        if(this[i] == val)
            return true;
    }
    return false;
}
CMarker.prototype.getCodeTypeLieu = function() {
    return this.codetypelieu;
//return "toto";
};
CMarkerEncours.prototype.getPos = function() {
    return this.pos;
};
CMarkerEncours.prototype.getAbonne = function() {
    return this.abonne;
};
CMarkerEncours.prototype.getPartenaire = function() {
    return this.partenaire;
};
CMarkerEncours.prototype.getId = function() {
    return this.id;
};
CMarkerEncours.prototype.getSpherique = function() {
    return this.spherique;
};
CMarkerEncours.prototype.getTitle = function() {
    return this.title;
};
CMarkerEncours.prototype.getMarker = function() {
    return this.marker;
};
CMarker.prototype.getTypeLieuId = function() {
    return this.typelieu_id ;
};
CMarker.prototype.getMarker = function() {
    return this.marker;
};
CMarker.prototype.getId = function() {
    return this.id;
};
CMarker.prototype.getSpherique = function() {
    return this.spherique;
};
CMarker.prototype.getAbonne = function() {
    return this.abonne;
};
CMarker.prototype.getIdLieu = function() {
    return this.idlieu;
};

function Search() {

    if (trim($("#val").val()).length == 0) {
        window.location.replace("/" + $("#language").val() + "/search.html");
    } else {

        $("form").submit();
    }
}
function fullLargePano(){
    $('body').toggleClass('fullscreen');
}
function filtre(nom_typelieu, checked) {
    for ( var i = 0; i < allnonabonnes.length; i++) {
        if (allnonabonnes[i].getCodeTypeLieu().toLowerCase() == nom_typelieu.toLowerCase()) {
            if (checked) {
                allnonabonnes[i].getMarker().show();
            } else {
                allnonabonnes[i].getMarker().hide();

            }
        }
    }

}
function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
function trim(myString) {
    return myString.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
function afficheTexte(id,title,meta,url,panoramaContent){
    $("#content").html(title);
    $("#titrehaut").html(title);
    $('title').html(meta.title);
    $('meta[name=keywords]').attr('content',meta.keywords);
    $('meta[name=description]').attr('content',meta.description);
    $('#panoramaContents').html(panoramaContent);
    afficheAdresse(id,title);
    
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        //    $(activeTab).blur();
        return false;
    });
    $(".tab_content").hide();
    $(".tab_content:first").show();
    jQuery('.sexy-bookmarks a.external').click(function() {
        switch(this.parentNode.className) {
            case 'sexy-digg':
                this.href += '?phase=2&title=' + startTitle + '&url=' + url;
                break;
            case 'sexy-twitter':
                this.href += '?status=RT+@360cityscape:+' + startTitle + '+-+' + url;
                break;
            case 'sexy-scriptstyle':
                this.href += '?title=' + startTitle + '&url=' + url;
                break;
            case 'sexy-reddit':
                this.href += '?title=' + startTitle + '&url=' + url;
                break;
            case 'sexy-delicious':
                this.href += '?title=' + startTitle + '&url=' + url;
                break;
            case 'sexy-stumbleupon':
                this.href += '?title=' + startTitle + '&url=' + url;
                break;
            case 'sexy-mixx':
                this.href += '?title=' + startTitle + '&page_url=' + url;
                break;
            case 'sexy-facebook':
                this.href += '?t=' + startTitle + '&u=' + url;
                break;
            case 'sexy-google':
                this.href += '?op=add&title=' + startTitle + '&bkmk=' + url;
                break;
        }
    })
}
function afficheAdresse(id) {
    $.ajax( {
        type : "POST",
        url : "/mode_debug/MVC_PATTERN/ajax/getAdresse.php",
        data : "id="+id+"&langue=" + langue,
        async : false,
        dataType : "json",
        success : function(data) {
            if (data.length > 0) {
                $("#coordonnees").html(data[0].content);
                $("#caract").html(data[0].info);
                $("#urlfr").attr("href", "/"+data[0].urlfr);
                $("#urlen").attr("href", "/"+data[0].urlen);
                $("#urles").attr("href", "/"+data[0].urles);

            }
        },
        error : function(xhr, err, e) {
        // alert(err+"lieu");
        }
    });
}