/*
# This file is part of Lonvia's Hiking Map
# Copyright (C) 2010 Sarah Hoffmann
#
# This is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# Functions for route sidebar.
*/

// if true, routes will be reloaded on map move
var doRouteReload = 0;

function toggleRouteView() {
    doRouteReload = 0;
    $("#routeview").toggleClass('opensidebar closedsidebar');
    $("#map").toggleClass('fullmap smallmap');
    if ($("#routeview").hasClass('opensidebar')) {
        loadRoutes();
        $("#routeselector").html('close');
    } else {
        $("#routeselector").html('Routes');
        $('#routecontent').html('');
    }
}

function loadRoutes() {
    var bounds = map.getExtent();
    bounds.transform(map.projection, map.displayProjection);
    $('#routecontent').html('<i>Loading data...</i>');
    $('#routecontent').load('/relationinfo/list.py?bbox=' + bounds.toBBOX()
                              + ' .mainpage');
    doRouteReload = 1;
}

function reloadRoutes(map, mapele) {
    if (doRouteReload)
        loadRoutes();
}

function showRouteInfo(osmid) {
    $('#routecontent').html('<i>Loading data...</i>');
    $('#routecontent').load('/relationinfo/info.py?id=' + osmid + 
                              ' .routewin');
    doRouteReload = 0;
}
