function MarkerHighlight(latLng)
{
    this.latLng_ = latLng;
}

var Route = Class.create();
Route.prototype = {
    itemSelectedClass: 'listItem listItemSelected',
    itemClass: 'listItem',
    initialize: function(parent, name, description, area, sequence)
    {
        this.sequence = sequence;
        this.type = 2;
        this.area = area;
        this.selected = false;
        this.list = [];
        this.route = null;
        this.parent = parent;
        this.name = name;
        this.tags = '';
        this.description = description;
        this.createDiv();
        this.marker_end = null;
        this.marker_start = null;
        this.visible = false;
        //MarkerRoute.image = this.parent.marker_route_image;
    },
    updateName: function()
    {
        var len = this.name;
        if (this.list.length > 1)
        {
            len += " (";
            var x = 0;
            for (var i = 0; i<this.list.length-1; i++)
            {
                x += this.list[i].distanceFrom(this.list[i+1]);
            }
            if (this.area)
                x += this.list[0].distanceFrom(this.list[this.list.length-1]);
            var unit = "m";
            if (x<10)
            {
                x = Math.ceil(x*10)/10;
            } else
            if (x<1000)
            {
                x = Math.ceil(x);
            } else
            {
                unit = "km";
                if (x < 10000)
                    x = Math.ceil(x/100)/10;
                else
                    x = Math.ceil(x/1000);
            }
            
            len += x;
            len += " " + unit + ")";
        }
        this.headerName.innerHTML = len;
    },
    createDiv: function()
    {
        var div = document.createElement('div');
        this.header = document.createElement('div');
        this.header.className = this.itemClass;
        this.header.onclick = this.onclick.bind(this);
        this.headerName = document.createElement('div');
        this.updateName();
        
        this.header.appendChild(this.headerName);
        div.appendChild(this.header);

        this.formDiv = document.createElement('div');
        div.appendChild(this.formDiv);
        this.div = div;
    },
    refreshMarker: function()
    {
        this.updateRoute();
    },
    getDiv: function()
    {
        return this.div;
    },
    removeRoute: function()
    {
        if (this.route != null)
            this.parent.map.gMap.removeOverlay(this.route);
        this.route = null;
        if (this.route_start != null)
            this.parent.map.gMap.removeOverlay(this.route_start);
    },
    updateRoute: function()
    {
        this.removeRoute();
        var list = [];
        for (var i=0; i<this.list.length; i++)
            list.push(this.list[i]);
        if (this.area)
            list.push(this.list[0]);
        this.route = new GPolyline(list, this.parent.getFullColor(), 8, 0.75);
        this.route.parent = this.parent;
        this.parent.map.gMap.addOverlay(this.route);
        this.updateName();
    },
    addMarkerCore: function(point)
    {
        this.list.push(point);
    },
    getDiv: function()
    {
        return this.div;
    },
    onclick: function()
    {
        if (this.selected)
            this.parent.deselectAllItems();
        else
        {
            this.parent.selectItem(this, true);
        }
    },
    select: function(state)
    {
        if (state)
        {
            this.selected = state;
            this.header.className = this.itemSelectedClass;

            var bounds = new GLatLngBounds();
            var mlat = 0;
            var mlng = 0;
            for (var i=0; i<this.list.length; i++)
            {
                bounds.extend(this.list[i]);
                mlat += this.list[i].lat();
                mlng += this.list[i].lng();
            }
            mlat /= this.list.length;
            mlng /= this.list.length;
            
            var html = "<div class='viewerInfoWindow'>";
            html += "<span zoomstate=1 class='orangeButton' style='padding-left:3px; padding-right:5px; float:right' onclick='infoWindowZoom(this, " + mlat   +  " , " + mlng  + ")'>" + lang[29] +"</span>";
            html += "<h2>" + this.name + "</h2>";
            html += "</div>";            
            
            this.parent.map.gMap.openInfoWindowHtml(this.list[0], html);
        }
        else
        {
            this.selected = state;
            this.header.className = this.itemClass;
            this.parent.map.gMap.closeInfoWindow();
        }
    },
    onRemovePlace: function()
    {
        if (confirm(lang[9] + ' ' + this.name + '?'))
        {
            this.remove();
            this.parent.deleteItem(this);
        }
    },
    remove: function()
    {
        this.removeRoute();
        this.hideMarkers();
    },
    centerMapOnIt: function()
    {
        if (this.list.length > 1)
        {
            var bounds = new GLatLngBounds();
            for (var i=0; i<this.list.length; i++)
                bounds.extend(this.list[i]);
                
            //this.parent.map.gMap.setZoom(this.parent.map.gMap.getBoundsZoomLevel(bounds));
            this.parent.map.gMap.panTo(bounds.getCenter());
        } else
        if (this.list.length == 1)
        this.parent.map.gMap.panTo(this.list[0]);
    },
    initialized: function()
    {
        return (this.list.length > 0);
    }
}

