var map;
var glmc = new GLargeMapControl();
function initialize() {
   if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("maps"));
        map.removeMapType(G_HYBRID_MAP);
        map.setCenter(new GLatLng(55.73752473183342, 37.646756172180176), 15);        
	for(i in glmc){if(glmc[i]=='mapcontrols2'){glmc[i]='mapcontrols3d';}}
        map.addControl(glmc); 
        map.enableContinuousZoom();
		map.enableDoubleClickZoom();
           
        var mapControl = new GMapTypeControl();
        map.addControl(mapControl);
       
        var iconItem = new GIcon();
        iconItem.image = '/images/m.png';
        iconItem.iconSize = new GSize(31, 29); 
        iconItem.iconAnchor = new GPoint(4, 28); 
        iconItem.infoWindowAnchor = new GPoint(14, 10); 

        var arrowIcon = new GIcon();
	    arrowIcon.iconSize = new GSize(24,24);
	    arrowIcon.shadowSize = new GSize(1,1);
	    arrowIcon.iconAnchor = new GPoint(12,12);
	    arrowIcon.infoWindowAnchor = new GPoint(0,0);
        var degreesPerRadian = 180.0 / Math.PI;    
        
        function arrowMap(point, degree){
            var cursor = new BDCCArrow(point, degree, "#FF1010", 0.9, ""); 
            map.addOverlay(cursor); 
        }      
            
        function bearing( from, to ){
	       // Convert to radians.
	       var lat1 = from.latRadians();
	       var lon1 = from.lngRadians();
	       var lat2 = to.latRadians();
	       var lon2 = to.lngRadians();
	       // Compute the angle.
	       var angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) );
	       if ( angle < 0.0 )
	       angle  += Math.PI * 2.0;
	       // And convert result to degrees.
	       angle = angle * degreesPerRadian;
	       angle = angle.toFixed(1);
	       return angle;
        }
        
        // === A function to put arrow heads at intermediate points
        function midArrows(points) {
	       for (var i=0; i < points.length-1; i++) {  
	           var p1=points[i];
	           var p2=points[i+1];
	           var dir = bearing(p1,p2);	           
	           var dir = Math.round(dir/3) * 3;
	           var midx = p1.x+((p2.x-p1.x)/1.3);
	           var midy = p1.y+((p2.y-p1.y)/1.3);	           
	           var middlepoint = new GLatLng(midy, midx);	           
	           arrowMap(middlepoint, dir);           
	       }
        }
        
        // A function to create a tabbed marker and set up the event window
        function createTabbedMarker(point,html1,html2,label1,label2) {
            var marker = new GMarker(point, { icon: iconItem, title: 'Flower-shop.ru' });
            GEvent.addListener(marker, "click", function() {
               marker.openInfoWindowTabsHtml([new GInfoWindowTab(label1,html1), new GInfoWindowTab(label2,html2)], {maxContent:'<div style="padding: 10px 10px 10px 0;"><div style="width: 100%; text-align: center; padding-top: 19px; padding-bottom: 19px; background: url(/pics/bg_video_pop.png) no-repeat scroll 50% 50%"><object wmode="opaque" height="338" width="450"><param name="video" value="http://flv.video.yandex.ru/lite/www-flowershop-ru/gbhtwt1luc.800/"><param name="allowFullScreen" value="true"><param name="scale" value="noscale"><param value="is-hq=true" name="flashvars"><param name="wmode" value="opaque"><embed flashvars="is-hq=true" src="http://flv.video.yandex.ru/lite/www-flowershop-ru/gbhtwt1luc.800/" wmode="opaque" type="application/x-shockwave-flash" allowfullscreen="true" scale="noscale" height="338" width="450"></embed></object></div></div>', maxTitle: "Видео о нас"});
            });
            return marker;
        }
        // Set up the tabbed markers      
        var point = new GLatLng(55.737409968385215, 37.6447069644928);
        var marker = createTabbedMarker(point, '<p style="width: 327px; margin: 0; padding: 0;"><img src="/images/fs_sm.png" align="left" style="margin-right: 15px; border: none;" alt="" title=""/><br/><b style="font-size: 16px;">Flower-shop.ru</b><br/><a href="http://maps.google.com/maps?f=q&hl=ru&geocode=&q=%D0%9C%D0%BE%D1%81%D0%BA%D0%B2%D0%B0,+%D0%9A%D0%BE%D1%81%D0%BC%D0%BE%D0%B4%D0%B0%D0%BC%D0%B8%D0%B0%D0%BD%D1%81%D0%BA%D0%B0%D1%8F+%D0%BD%D0%B0%D0%B1%D0%B5%D1%80%D0%B5%D0%B6%D0%BD%D0%B0%D1%8F,+%D0%B4.+40%2F42&sll=55.73747,37.645758&sspn=0.004228,0.010042&ie=UTF8&ll=55.738515,37.644868&spn=0.008456,0.020084&z=16&iwloc=addr" target="_blank">Москва, Космодамианская набережная, д. 40/42</a><br/>тел./факс: +7 (495) 626-4414&nbsp;</p>', "<p>Время работы цветочного салона Flower-shop.ru<br />с 9:00 до 20:00 (MSK).</p>", "Адрес", "График");
        map.addOverlay(marker);
    
    //Taganskaya 
    var polyOptions = {geodesic:true};
    var polyline = new GPolyline([
          new GLatLng(55.74234449194563,  37.65370845794678),
          new GLatLng(55.74201232206435,  37.65363335609436),
          new GLatLng(55.74068965394728,  37.65236735343933),
          new GLatLng(55.73917366412097,  37.65012502670288),
          
          new GLatLng(55.735942174527594, 37.64549016952515),
          new GLatLng(55.73583948729475,  37.645307779312134),
          new GLatLng(55.73609318467343,  37.64495372772217),
          new GLatLng(55.73643748562124,  37.64543652534485),
          new GLatLng(55.73738580761628,  37.64498591423035),
          new GLatLng(55.737343526234625, 37.644771337509155),
          new GLatLng(55.737409968385215, 37.6447069644928),
        ], "#48AC43", 4, 1, polyOptions);    
    map.addOverlay(polyline);	    

    //Path marker
    point = new Array(new GLatLng(55.74201232206435,  37.65363335609436), 
                      new GLatLng(55.74068965394728,  37.65236735343933));
    midArrows(point);
    
    point = new Array(new GLatLng(55.73948773856276,  37.6506507396698),
                      new GLatLng(55.73917366412097,  37.65012502670288));
    midArrows(point);
    
    point = new Array(new GLatLng(55.73917366412097,  37.65012502670288),          
                      new GLatLng(55.735942174527594, 37.64549016952515));
    midArrows(point);
    point = new Array(new GLatLng(55.73643748562124,  37.64543652534485),
                      new GLatLng(55.73738580761628,  37.64498591423035));
    midArrows(point);

    //Poveleckaya
    var polyline_three = new GPolyline([
          new GLatLng(55.731302858187696, 37.636284828186035),
          new GLatLng(55.73151429735616,  37.637518644332886),
          new GLatLng(55.73187676183781,  37.638570070266724),
          new GLatLng(55.733471565575904, 37.64145612716675),
          new GLatLng(55.73379172665516,  37.642056941986084),
          new GLatLng(55.73474011293229,  37.64332294464111),
          new GLatLng(55.73599653824739,  37.645061016082764),
        ], "#48AC43", 4, 1, polyOptions);    
    map.addOverlay(polyline_three);
    /*
    var polyline_four = new GPolyline([
          new GLatLng(55.73076519342934,  37.636638879776),
          new GLatLng(55.731242446786375, 37.63620972633362),
        ], "#48AC43", 4, 1, polyOptions);    
    map.addOverlay(polyline_four);
    
    var polyline_five = new GPolyline([
          new GLatLng(55.73069873996753,  37.63599514961243),
          new GLatLng(55.731242446786375, 37.63620972633362),
        ], "#48AC43", 4, 1, polyOptions);    
    map.addOverlay(polyline_five); */   
    
    //Path marker
    point = new Array(new GLatLng(55.73151429735616,  37.637518644332886),
          new GLatLng(55.73187676183781,  37.638570070266724));
    midArrows(point);
    
    point = new Array(new GLatLng(55.73379172665516,  37.642056941986084),
          new GLatLng(55.73474011293229,  37.64332294464111));
    midArrows(point);
    
    GEvent.trigger(marker, "click"); 
    //GEvent.trigger(marker, "close"); 
    //GEvent.trigger(marker, "click"); 
                
    }
}
