
    //mapaa===========
$(document).ready(function(){
        


       function mapInit(){
           directionsDisplay = new google.maps.DirectionsRenderer();
           var latlng = pos;
            var myOptions = {
              zoom: zoom,
              center: latlng,
              scaleControl: true,
              scrollwheel : false,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

            addMarker(pos);

            directionsDisplay.setMap(map);


       }

       function addMarker(pos) {
            marker = new google.maps.Marker({
              map:map,
              draggable:false,
              position: pos
            });
            marker.setMap(map);

      }

      function calcRoute() {
          var start = $('#mapStart').val();
          var end = startPos;
          var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.TravelMode.DRIVING
          };
          directionsService.route(request, function(result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
              directionsDisplay.setDirections(result);
            } else {
                alert('Nieudane wyznaczenie trasy. Sprawdz podany adres\n - w adresie mozesz podac nr domu, ulice i miasto.');
                $('#mapStart').focus();
            }
          });
        }


      if(($('#map_canvas').length>0)) {
          $('#map_canvas').css({
              width:'550px',
              height:'400px'
          })
          $('#mapStart').css({
              'color':'#aaa',
          'font-size':'11px'});
          var startStartText='Wprowadz swoj adres...';

          $('#mapStart').val(startStartText);
          $('#mapStart').click(function(){             
              if($(this).val()==startStartText) {                
                $(this).val('');
                $('#mapStart').css('color','#000');
              }
              
          }).blur(function(){
              if($(this).val()=='') {
                  $('#mapStart').css('color','#aaa');
                $(this).val(startStartText);
              }
              
          }).keypress(function(e){
              if(e.which == 13){
                    $('#search_route').trigger('click');
               }
          });

          var marker;
            var map;
            var pos;
            var startPos=new google.maps.LatLng(50.110575,20.016101);
            var zoom;
            var geocoder;
            var directionsDisplay;
            var directionsService = new google.maps.DirectionsService();


            
            pos = startPos;
            zoom=11;
            
          mapInit();

          $('#search_route').click(function(){
              calcRoute(); 
          })
      }
});

