﻿
// **************************************************************************************************************************
// Google Maps API objects
// --------------------------------------------------------------------------------------------------------------------------
// - elementId : String - Id of HTML element for displaying maps
// **************************************************************************************************************************
function GoogleMapObject(elementId)
{
    // -------------------------------------------------------------------------------------------------
    // ATTRIBUTES - filling from constructor, default values
    // -------------------------------------------------------------------------------------------------
    var map = null;      // general map object
    var mgr = null;      // manager for markers
    var icons = {};      // icons for markers
    var allmarkers = []; // array of all markers
    
    var googleMapsNotSupportedMessage = "Váš prohlížeč nepodporuje Google Maps API.";
    var defaultIconFileURL = "http://maps.google.com/intl/cs_ALL/mapfiles/marker.png";
    var defaultIconSize = new GSize(20,34);

    // -------------------------------------------------------------------------------------------------
    // MAP INITIALIZATION AND SETTINGS METHODS
    // -------------------------------------------------------------------------------------------------
    
    // General method for map initialization. (This must be executed only once.) -----------------------
    // - centerLat : Real    - langitude start
    // - centerLng : Real    - longitude start
    // - initZoom  : Integer - zoom at the start - value from 0 to 17 is supported by this parameter
    // - useMarker : Boolean - if true, enables marker object initialization
    function initialize(centerLat, centerLng, initZoom, useMarker)
    {
        if (GBrowserIsCompatible())
        {
            // map options definition
            var mapOptions =
            {
                googleBarOptions : {
                    style : "new"
                }
            }
            
            // map initialization
            this.map = new GMap2(document.getElementById(elementId), mapOptions);
            
            this.map.setCenter(new GLatLng(centerLat, centerLng), initZoom);
            this.map.enableDoubleClickZoom();
            
            // marker manager activation
            if (useMarker == true)
            {
                this.mgr = new MarkerManager(this.map, {trackMarkers:true});
            }
            //window.setTimeout(setupOfficeMarkers, 0);
        }
        else
        {
            // showing message that web browser does not support Google Maps API
            document.getElementById(elementId).innerHTML = googleMapsNotSupportedMessage;
        }
    }
    this.initialize = initialize;

    // Adding map size remote control. ----------------------------------------------------------------
    // - topAnchor    : Boolean - should be tacked to the top?
    // - rightAnchor  : Boolean - should be tacked to the right side?
    // - bottomAnchor : Boolean - should be tacked to the bottom?
    // - leftAnchor   : Boolean - should be tacked to the left side?
    function addSizesControl(topAnchor, rightAnchor, bottomAnchor, leftAnchor)
    {
        this.map.addControl(new GLargeMapControl(),
            getAnchor(topAnchor, rightAnchor, bottomAnchor, leftAnchor, 10, 20));
    }
    this.addSizesControl = addSizesControl;

    // Adding search control directly into map. --------------------------------------------------------
    // - topAnchor    : Boolean - should be tacked to the top?
    // - rightAnchor  : Boolean - should be tacked to the right side?
    // - bottomAnchor : Boolean - should be tacked to the bottom?
    // - leftAnchor   : Boolean - should be tacked to the left side?
    function addSearch(topAnchor, rightAnchor, bottomAnchor, leftAnchor)
    {
        this.map.addControl(new google.maps.LocalSearch(), 
            getAnchor(topAnchor, rightAnchor, bottomAnchor, leftAnchor, 10, 20));
    }
    this.addSearch = addSearch;

    // Adding overview panel for huge maps. ------------------------------------------------------------
    // - topAnchor    : Boolean - should be tacked to the top?
    // - rightAnchor  : Boolean - should be tacked to the right side?
    // - bottomAnchor : Boolean - should be tacked to the bottom?
    // - leftAnchor   : Boolean - should be tacked to the left side?
    function addOverview(topAnchor, rightAnchor, bottomAnchor, leftAnchor)
    {
        this.map.addControl(new GOverviewMapControl(),
            getAnchor(topAnchor, rightAnchor, bottomAnchor, leftAnchor, 20, 20));
    }
    this.addOverview = addOverview;
    
    // Adding map type switch. -------------------------------------------------------------------------
    // - topAnchor    : Boolean - should be tacked to the top?
    // - rightAnchor  : Boolean - should be tacked to the right side?
    // - bottomAnchor : Boolean - should be tacked to the bottom?
    // - leftAnchor   : Boolean - should be tacked to the left side?
    function addMapTypeSwitch(topAnchor, rightAnchor, bottomAnchor, leftAnchor)
    {
        // creating control
        this.map.addControl(new GMapTypeControl(), 
            getAnchor(topAnchor, rightAnchor, bottomAnchor, leftAnchor, 10, 10));
    }
    this.addMapTypeSwitch = addMapTypeSwitch;
    
    // Private method for creating anchor. -------------------------------------------------------------
    // - topAnchor    : Boolean - should be tacked to the top?
    // - rightAnchor  : Boolean - should be tacked to the right side?
    // - bottomAnchor : Boolean - should be tacked to the bottom?
    // - leftAnchor   : Boolean - should be tacked to the left side?
    // - sizeWidth    : Integer - margin width
    // - sizeHeight   : Integer - margin height
    function getAnchor(topAnchor, rightAnchor, bottomAnchor, leftAnchor, sizeWidth, sizeHeight)
    {
        var anchor = null;
        // anchor settings - there can be only anchor for 2 sides next to themselves
        if (topAnchor == true)
        {
            if (leftAnchor == true)
                anchor = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(sizeWidth,sizeHeight));
            else
                anchor = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(sizeWidth,sizeHeight));
        }
        else
        {
            if (leftAnchor == true)
                anchor = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(sizeWidth,sizeHeight));
            else
                anchor = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(sizeWidth,sizeHeight));
        }
        return anchor;
    }
    
    // Public method for map center setting. -----------------------------------------------------------
    // - lat  : Float   - center latitude
    // - lng  : Float   - center longitude
    // - zoom : Integer - init zoom
    function setCenter(lat, lng, zoom)
    {
        this.map.setCenter(new GLatLng(lat, lng), zoom);
    }
    this.setCenter = setCenter;
    
    // Public method for zoom setting. -----------------------------------------------------------------
    // - zoom : Integer - new zoom level
    function setZoom(zoom)
    {
        if ((zoom >= 1) && (zoom <= 17))
        {
            this.map.setZoom(zoom);
        }
    }
    this.setZoom = setZoom;
    
    // Public method for increasing actual zoom. -------------------------------------------------------
    function incZoom()
    {
        if (this.map.getZoom() < 17)
        {
            this.map.setZoom(this.map.getZoom() + 1);
        }
    }
    this.incZoom = incZoom;
    
    // Public method for decreasing actual zoom. -------------------------------------------------------
    function decZoom()
    {
        if (this.map.getZoom() > 1)
        {
            this.map.setZoom(this.map.getZoom() - 1);
        }
    }
    this.decZoom = decZoom;
    
    // -------------------------------------------------------------------------------------------------
    // METHODS FOR MARKERS - GENERAL
    // -------------------------------------------------------------------------------------------------

    // Loading markers. --------------------------------------------------------------------------------
    // - objectsCount : Integer          - count of generated markers
    // - iconsArray   : Array of String  - array of URLs to icons
    // - iconWidth    : Integer          - general icon widht
    // - iconHeight   : Integer          - general icon height
    function createMarkersExample(objectsCount, iconsArray, iconWidth, iconHeight, moveableMarkers)
    {
        // Add 10 markers to the map at random locations
        var bounds = this.map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngSpan = northEast.lng() - southWest.lng();
        var latSpan = northEast.lat() - southWest.lat();
        
        if (iconsArray == null)
            iconsArray = new Array();
        if (moveableMarkers == null)
            moveableMarkers = false;

        var markers = [];
        var iconsCounter = 0;
        for (var i = 0; i < objectsCount; i++)
        {
            var latitude = southWest.lat() + latSpan * Math.random();
            var longitude = southWest.lng() + lngSpan * Math.random();
            
            var newIcon = null;
            if (iconsArray.length > 0)
            {
                if (iconsCounter >= iconsArray.length)
                    iconsCounter = 0;
                    
                newIcon = this.createIcon(iconsArray[iconsCounter], iconWidth, iconHeight);
                
                iconsCounter++;
            }
            else
            {
                newIcon = this.createIcon();
            }
            
            var marker = this.createMarker(latitude, longitude, "Example marker", newIcon, moveableMarkers);
            markers.push(marker);
        }
        this.mgr.addMarkers(markers, 0, 17);
        this.mgr.refresh();
        return;
    }
    this.createMarkersExample = createMarkersExample;
    
    // Creating object of icon. ------------------------------------------------------------------------
    // - iconFileURL   : String  - URL of image for icon
    // - iconWidth     : Integer - icon's width
    // - iconHeight    : Integer - icon's height
    // - shadowFileURL : String  - URL of image for icon's shadow
    // - shadowWidth   : Integer - shadow's width
    // - shadowHeight  : Integer - shadow's height
    function createIcon(iconFileURL, iconWidth, iconHeight, shadowFileURL, shadowWidth, shadowHeight)
    {
        // settings for variables if some of them are null
        if (iconFileURL == null)   iconFileURL = defaultIconFileURL;
        if (iconWidth == null)     iconWidth = 0;
        if (iconHeight == null)    iconHeight = 0;
        if (shadowFileURL == null) shadowFileURL = "";
        if (shadowWidth == null)   shadowWidth = 0;
        if (shadowHeight == null)  shadowHeight = 0;
        
        var icon = new GIcon();
        icon.image = iconFileURL;
        icon.shadow = shadowFileURL;
        icon.iconSize = (((iconWidth == 0) || (iconHeight == 0)) ? defaultIconSize : new GSize(iconWidth,iconHeight));
        icon.shadowSize = new GSize(shadowWidth,shadowHeight);
        icon.iconAnchor = new GPoint(16,16);
        icon.infoWindowAnchor = new GPoint(5,1);
        return icon;
    }
    this.createIcon = createIcon;

    // Creating general marker object. -----------------------------------------------------------------
    // - positionLat : Integer - latitude position of the marker
    // - positionLng : Integer - longitude position of the marker
    // - title       : String  - title of the marker
    // - icon        : GIcon   - icon of the marker
    // - isDraggable : Boolean - indication if marker will be draggable
    function createMarker(positionLat, positionLng, title, icon, isDraggable)
    {
        if (title == null)       title = "";
        if (icon == null)        icon = this.createIcon();
        if (isDraggable == null) isDraggable = false;
        
        var marker = new GMarker(new GLatLng(positionLat, positionLng), {
            title: title, 
            icon: icon, 
            draggable:isDraggable 
        });
        return marker;
    }
    this.createMarker = createMarker;
    
    // -------------------------------------------------------------------------------------------------
    // METHODS FOR GETTING DATA FROM THE MAP
    // -------------------------------------------------------------------------------------------------

    // Getting bounds from the map. --------------------------------------------------------------------
    function getBounds()
    {
        return this.map.getBounds();
    }
    this.getBounds = getBounds;
    // Getting SouthWest bounds from the map. ----------------------------------------------------------
    function getSouthWestBounds()
    {
        var bounds = this.map.getBounds();
        return bounds.getSouthWest();
    }
    this.getSouthWestBounds = getSouthWestBounds;
    // Getting NorthEast bounds from the map. ----------------------------------------------------------
    function getNorthEastBounds()
    {
        var bounds = gMapWithXML.getBounds();
        return bounds.getNorthEast();
    }
    this.getNorthEastBounds = getNorthEastBounds;
    
    // -------------------------------------------------------------------------------------------------
    // METHODS FOR EVENTS
    // -------------------------------------------------------------------------------------------------

    // Adding new event listener for the map. ----------------------------------------------------------
    // - eventType      : string   - event type which must occur of execution of the method
    // - method2execute : function - method to execute after event
    function addEvent(eventType, method2execute)
    {
        GEvent.addListener(this.map, eventType, method2execute);
    }
    this.addEvent = addEvent;

    // Adding new event listener for the map. ----------------------------------------------------------
    // - obj            : object   - object with event to handle
    // - eventType      : string   - event type which must occur of execution of the method
    // - method2execute : function - method to execute after event
    function addEventFull(obj, eventType, method2execute)
    {
        GEvent.addListener(obj, eventType, method2execute);
    }
    this.addEventFull = addEventFull;
    
    // -------------------------------------------------------------------------------------------------
    // METHODS FOR MARKERS - CONCRETE
    // -------------------------------------------------------------------------------------------------

    // Putting new marker into map. --------------------------------------------------------------------
    // - marker          : GMarker - created object of new marker to add
    // - zoomVisibleFrom : Integer - value from 0 to 17 - lower bound of visibility according to zoom
    // - zoomVisibleTo   : Integer - value from 0 to 17 - upper bound of visibility according to zoom 
    function addMarker(marker, zoomVisibleFrom, zoomVisibleTo)
    {
        this.mgr.addMarker(marker, zoomVisibleFrom, zoomVisibleTo);
        this.mgr.refresh();
    }
    this.addMarker = addMarker;
    
    // Removes one marker according to its unique number. ----------------------------------------------
    function deleteMarker()
    {
        var markerNum = parseInt(document.getElementById("markerNum").value);
        this.mgr.removeMarker(allmarkers[markerNum]);
    }
    this.deleteMarker = deleteMarker;

    // Removes all markers. ----------------------------------------------------------------------------
    function clearMarkers()
    {
        this.mgr.clearMarkers();
    }
    this.clearMarkers = clearMarkers;
    
}

























var GoogleMapDataManager4Catalog_actualZoom = 12;
var GoogleMapDataManager4Catalog_actualURL = "";

// **************************************************************************************************************************
// Object for working with data on Google Map
// --------------------------------------------------------------------------------------------------------------------------
// -  :  - 
// **************************************************************************************************************************
function GoogleMapDataManager4Catalog(dataSourceURL, gMapInstance, zoom)
{
    // -------------------------------------------------------------------------------------------------
    // ATTRIBUTES - filling from constructor, default values
    // -------------------------------------------------------------------------------------------------
    var dataURL = dataSourceURL;      // URL of data connector
    var gMap = gMapInstance;          // reference to google map
    GoogleMapDataManager4Catalog_actualZoom = zoom;
    
    var ajaxReader = new AjaxDataReader();
    
    
    // !!!!!!!!!!!!!!!!!!!!!!!!!! doresit nacitani dat pri posunu mapy + zvetseni
    //gMap.addEvent("mousemove", function() { alert("kukuč"); });
    
    
    // Loading data and showing them on the map. -------------------------------------------------------
    function loadData(objInstance, centerByRecordId)
    {
        centerByRecordId = (centerByRecordId == null ? "-1" : centerByRecordId);
        centerByRecordId = (centerByRecordId == "" ? "-1" : centerByRecordId);
        
        gMap.addEvent("dragend", function() {
            if (GoogleMapDataManager4Catalog_actualZoom > 11)
            {
                var mapBounds = gMapWithXML_Catalog.getBounds().toString(); //(48.20271028869972, 12.205810546875)  (51.73383267274113, 18.797607421875)
                while (mapBounds.indexOf(" ") > -1)
                {
                    mapBounds = mapBounds.replace(" ","");
                }
                mapBounds = mapBounds.replace("),(",";");
                mapBounds = mapBounds.replace("(","").replace("(","");
                mapBounds = mapBounds.replace(")","").replace(")","");

                var lonlt = (mapBounds.split(";")[0]).split(",")[1];
                var latlt = (mapBounds.split(";")[0]).split(",")[0];
                var lonrb = (mapBounds.split(";")[1]).split(",")[1];
                var latrb = (mapBounds.split(";")[1]).split(",")[0];
                
                lonlt = (lonlt == null ? "" : lonlt.replace(",","-").replace(".","-"));
                latlt = (latlt == null ? "" : latlt.replace(",","-").replace(".","-"));
                lonrb = (lonrb == null ? "" : lonrb.replace(",","-").replace(".","-"));
                latrb = (latrb == null ? "" : latrb.replace(",","-").replace(".","-"));
                
                if (GoogleMapDataManager4Catalog_actualURL != "http://"+GetUrlBase()+"/pipe.ashx?type=text/xml&url=http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb)
                {
                    gMapWithXML_Catalog.clearMarkers();
                    GoogleMapDataManager4Catalog_actualURL = "http://"+GetUrlBase()+"/pipe.ashx?type=text/xml&url=http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb;
                    
                    dataManager_Catalog = new GoogleMapDataManager4Catalog("http://"+GetUrlBase()+"/pipe.ashx?type=text/xml&url=http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb, gMapWithXML_Catalog, GoogleMapDataManager4Catalog_actualZoom);
                    dataManager_Catalog.loadData("dataManager_Catalog");
                }
            }
            else
            {
                gMapWithXML_Catalog.clearMarkers();
            }
        });
        
        gMap.addEvent("zoomend", function(oldLevel, newLevel) {
            GoogleMapDataManager4Catalog_actualZoom = newLevel;
        
            if (GoogleMapDataManager4Catalog_actualZoom > 11)
            {
                
                var mapBounds = gMapWithXML_Catalog.getBounds().toString(); //(48.20271028869972, 12.205810546875)  (51.73383267274113, 18.797607421875)
                while (mapBounds.indexOf(" ") > -1)
                {
                    mapBounds = mapBounds.replace(" ","");
                }
                mapBounds = mapBounds.replace("),(",";");
                mapBounds = mapBounds.replace("(","").replace("(","");
                mapBounds = mapBounds.replace(")","").replace(")","");

                var lonlt = (mapBounds.split(";")[0]).split(",")[1];
                var latlt = (mapBounds.split(";")[0]).split(",")[0];
                var lonrb = (mapBounds.split(";")[1]).split(",")[1];
                var latrb = (mapBounds.split(";")[1]).split(",")[0];
                
                lonlt = (lonlt == null ? "" : lonlt.replace(",","-").replace(".","-"));
                latlt = (latlt == null ? "" : latlt.replace(",","-").replace(".","-"));
                lonrb = (lonrb == null ? "" : lonrb.replace(",","-").replace(".","-"));
                latrb = (latrb == null ? "" : latrb.replace(",","-").replace(".","-"));
                
                if (GoogleMapDataManager4Catalog_actualURL != "http://"+GetUrlBase()+"/pipe.ashx?type=text/xml&url=http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb)
                {
                    gMapWithXML_Catalog.clearMarkers();
                    GoogleMapDataManager4Catalog_actualURL = "http://"+GetUrlBase()+"/pipe.ashx?type=text/xml&url=http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb;
                    
                    dataManager_Catalog = new GoogleMapDataManager4Catalog("http://"+GetUrlBase()+"/pipe.ashx?type=text/xml&url=http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb, gMapWithXML_Catalog, GoogleMapDataManager4Catalog_actualZoom);
                    dataManager_Catalog.loadData("dataManager_Catalog");
                }
            }
            else
            {
                gMapWithXML_Catalog.clearMarkers();
            }
        });
        
        gMap.clearMarkers();
        ajaxReader.getDataByItem(dataSourceURL, objInstance +".showResult|,"+centerByRecordId, "item");
    }
    this.loadData = loadData;
    
    // Method for showing one newly loaded marker on the map. ------------------------------------------
    // - xmlDataItem     - one XML node object
    // - actualItemIndex - index of actual item in XML result
    // - itemsCount      - count of all XML results
    // - attributes      - array with string indexed attribute items
    function showResult(xmlDataItem, actualItemIndex, itemsCount, attributes, centerByRecordId)
    {
        centerByRecordId = (centerByRecordId == null ? "-1" : centerByRecordId);
    
        var lat = 0.0;
        var lon = 0.0;
        if ((attributes["lat"] == null) || (attributes["lon"] == null))
        {
            try
            {
                var latSS = parseFloat(attributes["ssn"]);
                var latMM = parseFloat(attributes["mmn"]);
                var latHH = parseFloat(attributes["hhn"]);
                
                var lonSS = parseFloat(attributes["sse"]);
                var lonMM = parseFloat(attributes["mme"]);
                var lonHH = parseFloat(attributes["hhe"]);
                
                lat = latSS / 60.0;
                lat = (lat + latMM) / 60.0;
                lat = lat + latHH;
                
                lon = lonSS / 60.0;
                lon = (lon + lonMM) / 60.0;
                lon = lon + lonHH;
            }
            catch (exception) {}
        }
        else
        {
            lat = attributes["lat"];
            lon = attributes["lon"];
        }
        //document.getElementById("centralNewsPanel").innerHTML = document.getElementById("centralNewsPanel").innerHTML + GLOBAL_FILE_SERVER + attributes["icon"] + "\n";
        //document.getElementById("centralNewsPanel").innerHTML = document.getElementById("centralNewsPanel").innerHTML + parseFloat(lat).toString() +"..."+ parseFloat(lon).toString() + "\n";
        //alert("http://"+ GetUrlBase() +"/"+ attributes["url"]);
        
        // loading icon and showing marker
        var imgIcon = new Image();
        imgIcon.src = GLOBAL_FILE_SERVER + attributes["icon"]
        imgIcon.onload = function() {
            // creating marker
            var newIcon = gMap.createIcon(GLOBAL_FILE_SERVER + attributes["icon"], imgIcon.width, imgIcon.height);
            var newMarker = gMap.createMarker(parseFloat(lat.replace(",",".")), parseFloat(lon.replace(",",".")), attributes["name"], newIcon, false);
            
            // adding marker onclick event
            GEvent.addListener(newMarker, "click", function() {
                window.location = "http://"+ GetUrlBase() +"/"+ attributes["url"];
                //marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
            });
            
            // adding marker mouseover event
		    GEvent.addListener(newMarker, "mouseover", function() {
                // *********************************************************************************************************************************************************
                // calculation of area for grouped records
                // *********************************************************************************************************************************************************
                var mapBounds = gMapWithXML_Catalog.getBounds().toString(); //(48.20271028869972, 12.205810546875)  (51.73383267274113, 18.797607421875)
                var url4areaData = "http://teplice.naseadresa-test.cz/cz/s2515/catt25/lonlt13-717803955078125/latlt50-603287887819015/lonrb13-931350708007812/latrb50-681014687913105";
                while (mapBounds.indexOf(" ") > -1)
                {
                    mapBounds = mapBounds.replace(" ","");
                }
                mapBounds = mapBounds.replace("),(",";");
                mapBounds = mapBounds.replace("(","").replace("(","");
                mapBounds = mapBounds.replace(")","").replace(")","");

                var lonlt = parseFloat((mapBounds.split(";")[0]).split(",")[1].replace(",","."));
                var latlt = parseFloat((mapBounds.split(";")[0]).split(",")[0].replace(",","."));
                var lonrb = parseFloat((mapBounds.split(";")[1]).split(",")[1].replace(",","."));
                var latrb = parseFloat((mapBounds.split(";")[1]).split(",")[0].replace(",","."));
                
                // final area bounds
                var lonltFinal = lonlt;
                var latltFinal = latlt;
                var lonrbFinal = lonrb;
                var latrbFinal = latrb;
                
                // one part variables
                var partX = parseFloat(lonlt) - parseFloat(lonrb);
                partX = (partX < 0 ? partX / -5 : partX / 5);
                var partY = parseFloat(latlt) - parseFloat(latrb);
                partY = (partY < 0 ? partY / -5 : partY / 5);
                
                // converting marker position
                var markerLon = parseFloat(lon.toString().replace(",","."));
                var markerLat = parseFloat(lat.toString().replace(",","."));
                
                // getting concrete summarizing area for actual marker
                for (var x = (lonlt < lonrb ? lonlt : lonrb); x <= (lonlt > lonrb ? lonlt : lonrb); x += partX)
                {
                    for (var y = (latlt < latrb ? latlt : latrb); y <= (latlt > latrb ? latlt : latrb); y += partY)
                    {
                        if ((markerLon >= x) && (markerLon <= x + partX) && (markerLat >= y) && (markerLat <= y + partY))
                        {
                            //alert("x = "+x+" ; y = "+y);
                            lonltFinal = (lonlt > lonrb ? x + partX : x).toString().replace(".","-").replace(",","-");
                            lonrbFinal = (lonlt < lonrb ? x + partX : x).toString().replace(".","-").replace(",","-");
                            
                            latltFinal = (latlt > latrb ? y + partY : y).toString().replace(".","-").replace(",","-");
                            latrbFinal = (latlt < latrb ? y + partY : y).toString().replace(".","-").replace(",","-");
                        }
                    }
                }
                
                // 2515 - test
                // 2468 - test to remove on original web
                url4areaData = "http://"+GetUrlBase()+"/cz/s2515/catt"+attributes["type"]+"/lonlt"+lonltFinal+"/latlt"+latltFinal+"/lonrb"+lonrbFinal+"/latrb"+latrbFinal;
                
                // *********************************************************************************************************************************************************
                
                var infoWinHTML = "<div style=\"width: 205px; height: 170px; display: block; overflow: hidden; style=\"border: 1px solid black;\" id=\"infoWindowInnerContent\">"+
                    "<iframe src=\""+url4areaData+"\" style=\"margin: 0; padding: 0; width: 204px; height: 169px; border: none;\" border=\"0\"></iframe>"+
                    "</div>";
		    
			    newMarker.openInfoWindowHtml(
			        infoWinHTML
			    );
		    });
		    
		    // adding marker mouseout event
		    GEvent.addListener(newMarker, "mouseout", function() {
			    //newMarker.closeInfoWindow();
		    });
              
            // inserting marker into map
            gMap.addMarker(newMarker, 0, 17);
            
            // centering map according to marker position
            if (parseInt(centerByRecordId) == parseInt(attributes["id"]))
            {
                gMap.setCenter(parseFloat(attributes["lat"]),parseFloat(attributes["lon"]), 17);
            }
        }
    }
    this.showResult = showResult;
    
}





var GoogleMapDataManager4Catalog_Concrete_actualZoom = 12;
var GoogleMapDataManager4Catalog_Concrete_actualURL = "";

// **************************************************************************************************************************
// Object for working with data on Google Map
// --------------------------------------------------------------------------------------------------------------------------
// -  :  - 
// **************************************************************************************************************************
function GoogleMapDataManager4Catalog_Concrete(dataSourceURL, gMapInstance, zoom)
{
    // -------------------------------------------------------------------------------------------------
    // ATTRIBUTES - filling from constructor, default values
    // -------------------------------------------------------------------------------------------------
    var dataURL = dataSourceURL;      // URL of data connector
    var gMap = gMapInstance;          // reference to google map
    GoogleMapDataManager4Catalog_Concrete_actualZoom = zoom;
    
    var ajaxReader = new AjaxDataReader();
    
    
    // !!!!!!!!!!!!!!!!!!!!!!!!!! doresit nacitani dat pri posunu mapy + zvetseni
    //gMap.addEvent("mousemove", function() { alert("kukuč"); });
    
    
    // Loading data and showing them on the map. -------------------------------------------------------
    function loadData(objInstance, centerByRecordId)
    {
        centerByRecordId = (centerByRecordId == null ? "-1" : centerByRecordId);
        centerByRecordId = (centerByRecordId == "" ? "-1" : centerByRecordId);
        
//        gMap.addEvent("dragend", function() {
//            if (GoogleMapDataManager4Catalog_actualZoom > 11)
//            {
//                var mapBounds = gMapWithXML_Catalog.getBounds().toString(); //(48.20271028869972, 12.205810546875)  (51.73383267274113, 18.797607421875)
//                while (mapBounds.indexOf(" ") > -1)
//                {
//                    mapBounds = mapBounds.replace(" ","");
//                }
//                mapBounds = mapBounds.replace("),(",";");
//                mapBounds = mapBounds.replace("(","").replace("(","");
//                mapBounds = mapBounds.replace(")","").replace(")","");

//                var lonlt = (mapBounds.split(";")[0]).split(",")[1];
//                var latlt = (mapBounds.split(";")[0]).split(",")[0];
//                var lonrb = (mapBounds.split(";")[1]).split(",")[1];
//                var latrb = (mapBounds.split(";")[1]).split(",")[0];
//                
//                lonlt = (lonlt == null ? "" : lonlt.replace(",","-").replace(".","-"));
//                latlt = (latlt == null ? "" : latlt.replace(",","-").replace(".","-"));
//                lonrb = (lonrb == null ? "" : lonrb.replace(",","-").replace(".","-"));
//                latrb = (latrb == null ? "" : latrb.replace(",","-").replace(".","-"));
//                
//                if (GoogleMapDataManager4Catalog_actualURL != "http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb)
//                {
//                    gMapWithXML_Catalog.clearMarkers();
//                    GoogleMapDataManager4Catalog_actualURL = "http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb;
//                    
//                    dataManager_Catalog = new GoogleMapDataManager4Catalog("http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb, gMapWithXML_Catalog, GoogleMapDataManager4Catalog_actualZoom);
//                    dataManager_Catalog.loadData("dataManager_Catalog");
//                }
//            }
//            else
//            {
//                gMapWithXML_Catalog.clearMarkers();
//            }
//        });
//        
//        gMap.addEvent("zoomend", function(oldLevel, newLevel) {
//            GoogleMapDataManager4Catalog_actualZoom = newLevel;
//        
//            if (GoogleMapDataManager4Catalog_actualZoom > 11)
//            {
//                
//                var mapBounds = gMapWithXML_Catalog.getBounds().toString(); //(48.20271028869972, 12.205810546875)  (51.73383267274113, 18.797607421875)
//                while (mapBounds.indexOf(" ") > -1)
//                {
//                    mapBounds = mapBounds.replace(" ","");
//                }
//                mapBounds = mapBounds.replace("),(",";");
//                mapBounds = mapBounds.replace("(","").replace("(","");
//                mapBounds = mapBounds.replace(")","").replace(")","");

//                var lonlt = (mapBounds.split(";")[0]).split(",")[1];
//                var latlt = (mapBounds.split(";")[0]).split(",")[0];
//                var lonrb = (mapBounds.split(";")[1]).split(",")[1];
//                var latrb = (mapBounds.split(";")[1]).split(",")[0];
//                
//                lonlt = (lonlt == null ? "" : lonlt.replace(",","-").replace(".","-"));
//                latlt = (latlt == null ? "" : latlt.replace(",","-").replace(".","-"));
//                lonrb = (lonrb == null ? "" : lonrb.replace(",","-").replace(".","-"));
//                latrb = (latrb == null ? "" : latrb.replace(",","-").replace(".","-"));
//                
//                if (GoogleMapDataManager4Catalog_actualURL != "http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb)
//                {
//                    gMapWithXML_Catalog.clearMarkers();
//                    GoogleMapDataManager4Catalog_actualURL = "http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb;
//                    
//                    dataManager_Catalog = new GoogleMapDataManager4Catalog("http://"+GetUrlBase()+"/cz/s2085/catt"+actualCatalogTypeId+"/lonlt"+lonlt+"/latlt"+latlt+"/lonrb"+lonrb+"/latrb"+latrb, gMapWithXML_Catalog, GoogleMapDataManager4Catalog_actualZoom);
//                    dataManager_Catalog.loadData("dataManager_Catalog");
//                }
//            }
//            else
//            {
//                gMapWithXML_Catalog.clearMarkers();
//            }
//        });
        
        gMap.clearMarkers();
        ajaxReader.getDataByItem(dataSourceURL, objInstance +".showResult|,"+centerByRecordId, "item");
    }
    this.loadData = loadData;
    
    // Method for showing one newly loaded marker on the map. ------------------------------------------
    // - xmlDataItem     - one XML node object
    // - actualItemIndex - index of actual item in XML result
    // - itemsCount      - count of all XML results
    // - attributes      - array with string indexed attribute items
    function showResult(xmlDataItem, actualItemIndex, itemsCount, attributes, centerByRecordId)
    {
        centerByRecordId = (centerByRecordId == null ? "-1" : centerByRecordId);
    
        var lat = 0.0;
        var lon = 0.0;
        if ((attributes["lat"] == null) || (attributes["lon"] == null))
        {
            try
            {
                var latSS = parseFloat(attributes["ssn"]);
                var latMM = parseFloat(attributes["mmn"]);
                var latHH = parseFloat(attributes["hhn"]);
                
                var lonSS = parseFloat(attributes["sse"]);
                var lonMM = parseFloat(attributes["mme"]);
                var lonHH = parseFloat(attributes["hhe"]);
                
                lat = latSS / 60.0;
                lat = (lat + latMM) / 60.0;
                lat = lat + latHH;
                
                lon = lonSS / 60.0;
                lon = (lon + lonMM) / 60.0;
                lon = lon + lonHH;
            }
            catch (exception) {}
        }
        else
        {
            lat = attributes["lat"];
            lon = attributes["lon"];
        }
        //document.getElementById("centralNewsPanel").innerHTML = document.getElementById("centralNewsPanel").innerHTML + GLOBAL_FILE_SERVER + attributes["icon"] + "\n";
        //document.getElementById("centralNewsPanel").innerHTML = document.getElementById("centralNewsPanel").innerHTML + parseFloat(lat).toString() +"..."+ parseFloat(lon).toString() + "\n";
        //alert("http://"+ GetUrlBase() +"/"+ attributes["url"]);
        var newIcon = gMap.createIcon(GLOBAL_FILE_SERVER + attributes["icon"], 24, 26);
        var newMarker = gMap.createMarker(parseFloat(lat.replace(",",".")), parseFloat(lon.replace(",",".")), attributes["name"], newIcon, false);
        GEvent.addListener(newMarker, "click", function() {
            window.location = "http://"+ GetUrlBase() +"/"+ attributes["url"];
            //marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
          });
        gMap.addMarker(newMarker, 0, 17);
        
        if (parseInt(centerByRecordId) == parseInt(attributes["id"]))
        {
            gMap.setCenter(parseFloat(lat.replace(",",".")), parseFloat(lon.replace(",",".")), 12);
        }
    }
    this.showResult = showResult;
    
}