//fix PNGsVISUALITALY_BLANK_IMAGE = 'img/s.gif';(function($){    $.fn.vAlign = function(){        return this.each(function(i){            var ah = $(this).height();            var ph = $(this).parent().height();            var mh = (ph - ah) / 2;            $(this).css('margin-top', mh);        });    };})(jQuery);jQuery.ifixpng(VISUALITALY_BLANK_IMAGE);jQuery(function($){    $("img[src$=.png]").ifixpng();});//globalvar visualApp;//coordinate di aperturaif(!open_lat){    var open_lat = 42.12748;    var open_lon = 11.83871;    var open_z = 10;}//ready$(document).ready(function(){    visualApp = new Visualitaly({        'mapConf': {            lat: open_lat,            lon: open_lon,            z: open_z,            tmLnk: 0,			tmDisp:0,            imgHost: 'http://maps.visual-italy.it',            mapType:PGMAP_TYPE_MAP,			imgType: PGMAP_IMG_TYPE_LIGHT        },        'loadAllPoints': false    });});//Flash callbacksvar flashReady = function(){    visualApp.streetPlayerReady();};var newPos = function(){};var mapMoveTo = function(lat, lon){    visualApp.streetPlayerMapMoveTo(lat, lon);};var updateBearing = function(dir){    visualApp.updateStreetlevelBearing(dir);};var coordsNotInMap = function(){};var hiTxtLoaded = function(){	visualApp.hiTxtLoaded();}var audioPressed = function(audio_mute){	visualApp.audioPressed(audio_mute);}//main classVisualitaly = function(options){    var defaultOptions = {        'serviceUrl': 'service.php',        'loadAllPoints': false,        'pagemode': ''    };    this.options = $.extend(defaultOptions, (options ||    {}));    this.zoomGeoConversionMap = {        '-3': 2,        '-2': 2,        '-1': 2,        '0': 2,        '1': 3,        '2': 4,        '3': 4,        '4': 5,        '5': 5,        '6': 5,        '7': 6,        '8': 7,        '9': 8,        '10': 9,        '11': 9    };    this.geoZoomConversionMap = {        '0': -3,        '1': -3,        '2': 0,        '3': 1,        '4': 3,        '5': 5,        '6': 7,        '7': 8,        '8': 9,        '9': 10    };        this.nextUniqueId = 0;        this.westContent;    this.seatWidget = {};        this.streetPlayerData = null;    this.queryExtraParameters = {};    this.ptList = [];    this.streetLevelPoint;    this.currMode;        this.curAudioSpeaker = '';        this.init();};Visualitaly.prototype = {    nextId: function(){        this.nextUniqueId++;        return this.nextUniqueId;    },    init: function(){        var self = this;        this.changePageLayout('map');        this.initMappa();        this.initZoom();        this.initMapModes();        this.mapRefresh();                /*        var poiId = jQuery.url.param("id");        if (poiId != undefined) {            this.SelectPoiById(poiId);        }        else {            this.btPoiAction();        }        */    },    loadLeftContent: function(url, callback){        var self = this;        $.get(url, function(data){            $('#left').html(data);            if (callback) {                callback.apply();            };        });    },    emptyLeftContent: function(){        $('#left').html();    },    changePageLayout: function(newPageMode){        var self = this;        if (newPageMode != this.options.pagemode) {            this.options.pagemode = newPageMode;            //vuota left            this.emptyLeftContent();                        //a seconda se siamo in modo mappa o player...            if (this.options.pagemode == 'map') {                //nasconde la bussola                $('#poimarker-sv-container').hide();                //dimensiona left e caricaci la lista delle regioni                $('#left').width(170);                this.loadLeftContent('regioni.html', this.initZoomRegioni);                //dimensiona il div della mappa                $('#mappa').width(745).height(607);                if(this.mappa) this.mappa.setSize(745, 607);            }else {                //dimensiona left e caricaci il player                $('#left').width(500);                this.loadLeftContent('player.html');                //dimensiona il layer della mappa e l'oggetto PGMappy                this.mappa.setSize(415, 360);                if(this.mappa) $('#mappa').width(415).height(360);            }        }    },    initMappa: function(){        var self = this;        this.options.mapConf.mapWidth = $('#mappa').width();        this.options.mapConf.mapHeight = $('#mappa').height();        $('<div id="map-container" />').appendTo('#mappa');        this.options.mapConf.nameContainer = 'map-container';        this.mappa = new PGMappy(this.options.mapConf);        var mapCenter;        PGEvent.addListener(this.mappa, 'zoomaftermap', this.mapRefresh, this);        PGEvent.addListener(this.mappa, 'mousedownafter', function(){            self.mapCenter = self.mappa.getCenter();        });        PGEvent.addListener(this.mappa, 'mouseupmapafter', function(){            var newCenter = self.mappa.getCenter();            if (self.mapCenter.lat != newCenter.lat || self.mapCenter.lon != newCenter.lon) {                if (self.options.loadAllPoints == false) {                    self.mapRefresh();                }            }            self.mapCenter = newCenter;        });        $("#mapTypeChooser div[value=1]").click(function(){            self.changeMapType(1);        });        $("#mapTypeChooser div[value=2]").click(function(){            self.changeMapType(2);        });        $("#mapTypeChooser div[value=3]").click(function(){            self.changeMapType(3);        });        this.changeMapType(3);    },    initMapModes: function(){        var self = this;        $(".mapModeSelectors > li").click(function(){            var el = $(this);            var id = el.attr('id');            var fnc = 'self.' + id + 'Action()';            eval(fnc);        });    },    initZoom: function(){        var self = this;        $('<div id="mapzoom" />').css({            position: 'absolute',            zIndex: 10000,            top: '10px',            left: '10px',            cursor: 'pointer'        }).click(function(event){            var pieceMin = 33;            var pieceMax = 164;            var pieceSize = 13;            var ofs = $(this).offset();            var coords = {                left: event.pageX - ofs.left,                top: event.pageY - ofs.top            };            if (coords.top < pieceMin) {                self.mappa.zoomIn();            }            else                 if (coords.top > pieceMax) {                    self.mappa.zoomOut();                }                else {                    var cp = Math.floor((coords.top - pieceMin) / pieceSize);                    self.mappa.setZoom(cp);                }        }).appendTo('#mappa');        $('<img />').attr({            src: 'img/zoom.png',            alt: 'zoom'        }).ifixpng().appendTo('#mapzoom');    },    initZoomRegioni: function(){        var self = visualApp;        $('#btZoomAbruzzo').click(function(){self.mappa.setCenterAndZoom(13.94809, 42.30459, 8);});        $('#btZoomBasilicata').click(function(){self.mappa.setCenterAndZoom(16.16863, 40.44813, 8);});        $('#btZoomCalabria').click(function(){self.mappa.setCenterAndZoom(16.46109, 39.20385, 9);});        $('#btZoomCampania').click(function(){self.mappa.setCenterAndZoom(14.80911, 40.78938, 8);});        $('#btZoomEmilia').click(function(){self.mappa.setCenterAndZoom(10.5244, 44.92213, 9);});        $('#btZoomFriuli').click(function(){self.mappa.setCenterAndZoom(13.05985, 46.03082, 8);});        $('#btZoomLazio').click(function(){self.mappa.setCenterAndZoom(12.73662, 42.00902, 8);});        $('#btZoomLiguria').click(function(){self.mappa.setCenterAndZoom(8.87796, 44.1993, 8);});        $('#btZoomLombardia').click(function(){self.mappa.setCenterAndZoom(9.93086, 45.71179, 8);});        $('#btZoomMarche').click(function(){self.mappa.setCenterAndZoom(13.12565, 43.41641, 8);});        $('#btZoomMolise').click(function(){self.mappa.setCenterAndZoom(14.63536, 41.74238, 7);});        $('#btZoomPiemonte').click(function(){self.mappa.setCenterAndZoom(8.53616, 45.00511, 9);});        $('#btZoomPuglia').click(function(){self.mappa.setCenterAndZoom(16.32927, 40.87058, 9);});        $('#btZoomSardegna').click(function(){self.mappa.setCenterAndZoom(9.21002, 40.05204, 9);});        $('#btZoomSicilia').click(function(){self.mappa.setCenterAndZoom(14.07756, 37.71066, 9);});        $('#btZoomToscana').click(function(){self.mappa.setCenterAndZoom(10.97278, 43.31599, 8);});        $('#btZoomTrentino').click(function(){self.mappa.setCenterAndZoom(11.41959, 46.36066, 8);});        $('#btZoomUmbria').click(function(){self.mappa.setCenterAndZoom(12.33597, 42.9822, 8);});        $('#btZoomAosta').click(function(){self.mappa.setCenterAndZoom(7.44703, 45.75805, 7);});        $('#btZoomVeneto').click(function(){self.mappa.setCenterAndZoom(11.78755, 45.8251, 8);});    },    changeMapType: function(t){        this.mappa.setMapType(t);        $("#mapTypeChooser div").removeClass("btSelected");        $("#mapTypeChooser div[value=" + t + "]").addClass("btSelected");    },    getGeoimportanceFromZoom: function(z){        return this.zoomGeoConversionMap[z] ? this.zoomGeoConversionMap[z] : null;    },    getZoomFromGeoimportance: function(g){        return this.geoZoomConversionMap[g] ? this.geoZoomConversionMap[g] : null;    },    mapRefresh: function(){        this.loadMapPOI();    },    loadMapPOI: function(){        var self = this;        var mapSize = this.mappa.getSize();        var pTopLeft = this.mappa.getLonLatFromPixel(0, 0);        var pBottomRight = this.mappa.getLonLatFromPixel(mapSize.width, mapSize.height);        var geoimportance = this.getGeoimportanceFromZoom(this.mappa.getZoom().z);        var data = {            a: 'loadmappoi',            geoimportance: geoimportance        };        jQuery.extend(data, this.queryExtraParameters);        if (self.options.loadAllPoints == false) {            data.tlx = pTopLeft.lon;            data.tly = pTopLeft.lat;            data.brx = pBottomRight.lon;            data.bry = pBottomRight.lat;        };        $.getJSON(this.options.serviceUrl, data, function(data){            self.drawPointsOnMap(data)        });    },    drawPointOnMap: function(item){        var self = this;        var tipologiaId = item.tipologia_id ? item.tipologia_id : 0;        var marker = 'poimarker-' + tipologiaId + '-' + item.type;        var imgpoi = '<img src="img/poi/' + tipologiaId + '-' + item.color + '.png" />';                var poipointTpl = '<div class="poimarker poi-' + item.color + '">' + imgpoi;        if (item.cnt != undefined) {            poipointTpl += '<div class="poicounter">' + item.cnt + '</div>';        }        if (item.nome_IT != item.nome_EN) {            poipointTpl += '<span>' + item.nome_IT + '<br /><i>' + item.nome_EN + '</i></span>' + '</div>';        }else{            poipointTpl += '<span>' + item.nome_IT + '</span>' + '</div>';        }                var conf = {            lat: item.lat,            lon: item.lon,            offsetX: 0,            offsetY: 0,            width: '24px',            height: '38px',            html: poipointTpl,            id: item.id        };                //aggiungi il punto alla mappa        var point = new PGPoint(conf);        this.mappa.pointAdder(point);                //fix png        $(point.dPoint).find('img').ifixpng();                //al click sul POI        PGEvent.addListener(point, 'click', function(data){            self.hideTooltip();            self.changePageLayout('player');            self.mappa.setCenterPoint(point);            self.loadStreetlevel(data.id);        });                PGEvent.addListener(point, 'openbefore', function(data){            $('#poitip').css({                'display': 'none'            });        });                PGEvent.addListener(point, 'openafter', function(data){            //$("#poitip").ifixpng();        });                //tooltip (apri/chiudi)        PGEvent.addListener(point, 'mouseover', function(data){            var t = $(self.getTarget(data.event));            var el = $(t.parents("[id^='map-container_point_']")[0]);            self.openTooltip('#' + el.attr('id'));        });        PGEvent.addListener(point, 'mouseout', function(data){            self.hideTooltip();        });                item.p = point;                return item;    },    loadStreetlevel: function(id){        var self = this;        $.get(this.options.serviceUrl, {            'a': 'loadpoi',            'id': id        }, function(data){            if (data && data.what && data.what.length == 1) {                var poi = data.what[0];                self.openStreetlevel(poi);            }            else {            }        }, 'json');    },    drawPointsOnMap: function(result){        var newList = [];        var found;        //per ogni punto ritornato dalla chiamata, cerco quelli uguali        for (var i = 0; i < result.what.length; i++) {            //cerco il punto corrente nella lista dei punti visualizzati            found = false;            for (var pi = 0; pi < this.ptList.length; pi++) {                if (this.ptList[pi].id == result.what[i].id) {                    //trovato il punto, la sposto nella nuova lista                    newList.push(this.ptList[pi]);                    //lo tolgo dalla lista corrente                    this.ptList.splice(pi, 1);                    found = true;                    break;                }            }            if (found == false) {                //punto nuovo                newList.push({                    id: result.what[i].id,                    d: result.what[i]                });            }        }                //cancello tutti i punti della lista dei vecchi visualizzati        for (var i = 0; i < this.ptList.length; i++) {            if (this.ptList[i].p) {                this.mappa.removePoint(this.ptList[i].p);                this.ptList[i].p = null;            }        }                //mostro i punti        for (var i = newList.length - 1; i > -1; i--) {            //se mai disegnato, lo renderizzo            if (!newList[i].p) {                newList[i].p = this.drawPointOnMap(newList[i].d).p;            }        }                this.ptList = newList;    },    removeAllPOIs: function(){        var self = this;        $.each(this.ptList, function(C, B){            if (this.p) {                self.mappa.removePoint(this.p);                this.p = null;            }        });        this.ptList = [];    },    openTooltip: function(pointId){        //pointId è nella forma #map-container_point_nnn        var el = $(pointId);        var tx = el.find(".poimarker > span").html();        var pos = el.offset();        var btop = pos.top + 1;        var bleft = pos.left + 27;                $('#poitip p').html(tx);        $('#poitip').css({            'top': btop,            'left': bleft        }).show();        $('#poitip p').vAlign();                //$("#poitip").ifixpng();    },    hideTooltip: function(){        $('#poitip').hide();    },    streetPlayerReady: function(){        //this.mainLayout.resizeContent('west');        this.streetPlayerAction();    },    getStreetPlayerObject: function(){        var sp = swfobject.getObjectById('streetlevel-object-container');        if (sp !== null) {            //FF            if (typeof(sp) === 'function') {                return sp;            }            //IE            else                 if ($(sp).is('object')) {                    return sp;                }        }        return null;    },    streetPlayerAction: function(){        var sp = this.getStreetPlayerObject();        if (sp !== null && typeof(sp.goLatLong) === 'function' && this.streetPlayerData) {            var c = this.streetPlayerData;            var zoom = (c.z == undefined || c.z == '') ? 400 : c.z;            sp.goLatLong(String(c.lat), String(c.lon), String(c.u), String(c.v), String(zoom));        }    },    removeStreetLevelPoint: function(){        if (this.streetLevelPoint) {            this.mappa.removePoint(this.streetLevelPoint);        }        this.streetLevelPoint = null;    },    updateStreetlevelBearing: function(dir){        $('#poimarker-sv-container').css('backgroundPosition', this.getBearingBackgroundPosition(dir));    },    getBearingBackgroundPosition: function(dir){        if (dir > 360) {            dir = dir % 360;        }        var ret = Math.round(dir / 30.0) * 30;        if (ret == 360) {            ret = 0;        }        return '0px -' + (30 + ret) + 'px';    },    streetPlayerMapMoveTo: function(lat, lon){        this.removeStreetLevelPoint();        var conf = {            lat: lat,            lon: lon,            offsetX: 0,            offsetY: 15,            width: '30px',            height: '30px',            html: '<div id="poimarker-sv-container" alt="bearing"></div>',            id: 'streetlevel_pos'        };        var point = new PGPoint(conf);        this.mappa.pointAdder(point);        //$('#poimarker-sv-container').ifixpng();                this.streetLevelPoint = point;    },    showStreetlevelDetails: function(){        var c = this.streetPlayerData;        $('#title_it').text(c.nome_IT);        $('#title_en').text(c.nome_EN);        $('#descrizione_IT').text(c.descrizione_IT);        $('#descrizione_EN').text(c.descrizione_EN);                //carico lo streetplayer        var sp = this.getStreetPlayerObject();        if (sp !== null) {            this.streetPlayerAction();        }        else {            this.createStreetPlayer();        }    },    openStreetlevel: function(poi){        this.streetPlayerData = poi;        this.showStreetlevelDetails();    },    createStreetPlayer: function(){        var flashvars = {    		serverPath: "http://otrws.visual-italy.it/ws",    		latlong: 0,    		overlay: 1,    		debugJS: 0,    		radarmap2d: 0,    		radarmap3d: 1,    		r3zoom: 0.05,    		navdepth: 12,    		texturedepth: 2,    		audioToggle: 0,    		nologo: 1    	};    	var params = {    		allowscriptaccess: 'always',    		allowfullscreen: true,    		wmode: 'transparent',    		scale: 'exactfit'    	};    	var attributes = {};                swfobject.embedSWF('player.swf', 'streetlevel-object-container', "500", "300", '10.0.0', "expressInstall.swf", flashvars, params, attributes);    },    repairString: function(str){        if (str != undefined && str.length > 0) {            var temp_div = document.createElement('div');            temp_div.innerHTML = str;            return temp_div.firstChild.nodeValue;        };        return '';    },    getTarget: function(x){	        x = x || window.event;        return x.target || x.srcElement;    },    SelectPoiById: function(poiId){        var self = this;        $.get(this.options.serviceUrl, {            'a': 'loadpoi',            'id': poiId        }, function(data){            var poi = data.what[0];            if (poi == undefined) {                this.mode = 'MAP';                self.loadIndice();                self.mapRefresh();            }            else {                self.searchFormHide();                self.mode = 'SEARCH';                self.removeAllPOIs();                self.drawPointsOnMap(data);                if (poi.type == 'v') {                    self.openStreetlevel(poi);                }                else {                    self.loadIndice();                }                var gi = poi.geoimportance;                var z = 5;                var centerPoint = new PGPoint({                    lat: poi.lat,                    lon: poi.lon                });                self.mappa.setCenterPoint(centerPoint);                self.mappa.setZoom(z);            }        }, 'json');    },    getRouteFormatCb: function(route, id){		var self = this;        var routeList = [{            route: route,			routeParams:this.routeParams        }];                /*		if (this.routeParams.poiId != undefined && this.routeParams.poiId != '')		{			$.get(this.options.serviceUrl, {				'a': 'loadpoi',				'id': this.routeParams.poiId			}, function(data){				var poi = data.what[0];				if (poi != undefined) {					self.searchFormHide();					self.mode = 'SEARCH';					self.removeAllPOIs();					self.drawPointsOnMap(data);				}			}, 'json');		}		*/				this.mappa.addRouteFormat(routeList);    },    sharedBtActions: function(params){        $(".mapModeSelectors > li").removeClass('menuSel');        if (params.bt) {            this.currMode = params.bt;            $(".mapModeSelectors li#bt" + params.bt).addClass('menuSel');        }                if (params.mode != undefined) {            this.mode = params.mode;        }                if (this.mode == 'SEARCH') {            this.mappa.removeAllPoints();        }                //pulisco i layer seat        if (this.seatWidget.obj) {            this.mappa.removeLayer(this.seatWidget.obj);        }                this.searchFormClearFields();                if (params.search == true) {            this.searchFormShow();        }        else {            this.searchFormHide();        }                if (params.queryExtraParameters != undefined) {            this.queryExtraParameters = params.queryExtraParameters;        }                this.mapRefresh();        if (this.westContent != 'indice') {            this.loadIndice();        }    },    btPoiAction: function(){            if (this.currMode == 'Seat') {            this.removeAllPOIs();        }                this.sharedBtActions({            bt: 'Poi',            mode: 'MAP',            search: true,            queryExtraParameters: {                repo: 'VISUAL'            }        });    },    btSeatAction: function(){        this.removeAllPOIs();                this.sharedBtActions({            bt: 'Seat',            mode: 'SEARCH',            search: true,            queryExtraParameters: {                repo: 'SEAT'            }        });            }};