﻿var gAutoPrint = true;

var map;
var infowindow;
var directionDisplay;
var directionsService = new google.maps.DirectionsService();

function processPrint(printMe, withMap) {
    var printReadyElem = $('#' + printMe);
    if (printReadyElem == null) {
        alert("Error, no content.");
        return;
    }

    if (withMap)
        var mapCanvas = $('#map_canvas');

    var html = '<HTML>\n<HEAD>\n<TITLE>Hotel Victoria Budapest Directions';
    html += '</TIT' + 'LE>\n</HE' + 'AD>\n<BODY>\n';

    if (withMap)
        html += '<div id="map_canvas" style="width: 655px; height: 500px; page-break-after: always;">' + mapCanvas.html() + '</div>';

    html += printReadyElem.html();
    html += '\n</BO' + 'DY>\n</HT' + 'ML>';

    var printWin = window.open("", "processPrint");
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();

    if (gAutoPrint)
        printWin.print();
}

function getDirections(start, end) {
    //$("#directionsPanel").text("Directions are loading...");
    if (infowindow != null) {
        infowindow.close();
    }
    $("#linksPanel").show();

    var request = {
        origin: start,
        destination: end,
        provideTripAlternatives: true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };

    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
            $("#printDirections").show();
        }
        else {
            $("#directionsPanel").html(status.toString());
        }
    });

    $.scrollTo($("#directionsPanel"));
}

function map_initialize(text) {
    $("#linksPanel").hide();

    var image = "http://www.victoria.hu/assets/images/mm_20_blue.png";
    var latlng = new google.maps.LatLng(47.501533, 19.039902);
    var contentString = "<span class='gm'><b>Hotel Victoria **** Budapest</b><br/>" +
                                "1011 Budapest, Bem rakpart 11.<br/>Tel: (+36 1) 457-8080<br/>Fax: (+36 1) 457-8088<br/>" +
                                "E-mail: <a class='arak' href='mailto:victoria@victoria.hu'>victoria@victoria.hu</a><br/>" +
                                "<br/>" + text + ":<br />" +
                                "<input type='text' size='42' maxlength='40' class='form' name='start' id='start' value='' />" +
                                "<input type='hidden' name='end' id='end' value='Hotel Victoria **** Hungary 1011 Budapest, Bem rakpart 11.'/>" +
                                "<br/><input value='Get Directions' type='button' class='form button' onclick=\"getDirections($('#start').val(),$('#end').val());\">" +
                                "</span>";

    var myOptions = {
        zoom: 13,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    directionsDisplay = new google.maps.DirectionsRenderer();
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));

    var marker = new google.maps.Marker({ map: map,
        position: latlng,
        title: "Hotel Victoria"
    });

    infowindow = new google.maps.InfoWindow({
        content: contentString
    });
    infowindow.open(map, marker);

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map, marker);
    });

    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.495400, 19.039693),
        title: "Buda Castle - Royal Palace"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.501960, 19.034232),
        title: "Buda Castle - Matthias Church"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.500068, 19.081830),
        title: "Keleti Pu. - Eastern Railway Station"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.510649, 19.056944),
        title: "Nyugati Pu. - Western Railway Station"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.499749, 19.024758),
        title: "Deli Pu. - Southern Railway Station"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.507345, 19.046044),
        title: "Parliament"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.486817, 19.048061),
        title: "Gellert Hill - Citadel"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.515345, 19.078102),
        title: "City Park - Heroes' Square"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.497676, 19.054498),
        title: "Deak Ter"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.490833, 19.062073),
        title: "Hungarian National Museum"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.487034, 19.058382),
        title: "Central Market Hall"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.479044, 19.063854),
        title: "Petofi Bridge"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.485753, 19.054756),
        title: "Liberty Bridge"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.490993, 19.049263),
        title: "Elizabeth Bridge"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.498879, 19.044113),
        title: "Chain Bridge"
    });
    new google.maps.Marker({ map: map, icon: image,
        position: new google.maps.LatLng(47.514650, 19.043426),
        title: "Margaret Bridge"
    });
}