﻿var currentMarker;
var currentCenter;
var myMap;
var infowindow=false;
//loading maps namespace version 2

 google.load("maps","2");

 
 function setIcons(){
 var icons = new Array();
 var Yblog = new google.maps.Icon();
 Yblog.image = "yblog.png";
 Yblog.iconSize = new google.maps.Size(20,20);
 Yblog.iconAnchor = new google.maps.Point(10,10);
 Yblog.infoWindowAnchor = new google.maps.Point(10, 7);
 Yblog.transparent = "yblog.png"; 
 //without blog icon marker
 
 var Nblog = new google.maps.Icon();
 Nblog.image = "nblog.png";
 Nblog.iconSize = new google.maps.Size(20,20);
 Nblog.iconAnchor = new google.maps.Point(10,10);
 Nblog.infoWindowAnchor = new google.maps.Point(10, 7);
 icons['yblog']=Yblog;
 icons['nblog']=Nblog;
 
 return icons; 
 }

function initialize(){

    
        
        setPoints();
        currentCenter=Points[0]._gPoint;
        var icons = setIcons();
        
        myMap = new google.maps.Map2(document.getElementById("googlemap"));
        myMap.addControl(new google.maps.LargeMapControl3D ());
        
        //iterate over the points
        var mapPoints = [];
        var content;
        for (i=0;i<Points.length;i++)
        {
        
        //add a marker for each point
        myMap.addOverlay(Points[i]._marker);
        
        //add click event for the marker
        google.maps.Event.addListener(Points[i]._marker, "click", function(){
                                                            this.showMapBlowup({mapType:G_SATELLITE_MAP,zoomLevel:13});
                                                            infowindow=false;
                                                            
                                                            });
        
        //add the mouse over event for the marker 
        google.maps.Event.addListener(Points[i]._marker,"mouseover",function(){
                                            this.openInfoWindowHtml(getHtml(this));
                                            infowindow=true;
                                            }
                                      );
        
        //add the mouseout event for the marker
        google.maps.Event.addListener(Points[i]._marker,"mouseout",function(){                                                        
                                                       
                                                      
                                                       currentMarker = this;
                                                       setTimeout('hideInfoWindow()',5000);
                                                       });
        
        //add the point to the point array for the polyline
        mapPoints.push(Points[i]._gPoint);        
        }
       
        myMap.addOverlay(new google.maps.Polyline(mapPoints,"#18bd3f",5));
        
        //initialize map
        myMap.setCenter(new google.maps.LatLng(44, 8), 3);   
        myMap.setMapType(G_PHYSICAL_MAP);
        
        //pan to last position gradually
        var time = 5000;
        for (n=Points.length-1;n>-1;n--)   {
        
                 setTimeout('pan('+Points[n]._lat+','+Points[n]._lon+')',time);
                 time+=50;       
                }      
          
        //zoom in 5 times
        for(m=0;m<5;m++){
                    time+=1500;
                    setTimeout('zoom()',time);
                    }     
       
}

function hideInfoWindow(){
        
        if(infowindow){
        
        myMap.getInfoWindow().hide();
        }           
        
       }
       
function pan(lat,lng){
//alert('panto '+lat+' '+lng);
myMap.panTo(new google.maps.LatLng(lat,lng));
}

function zoom(){
myMap.zoomIn(currentCenter,true,true);
}
function getHtml(marker){

for(i=0;i<Points.length;i++)
{
 if (Points[i]._marker==marker) return Points[i]._html;
}
return "nada";
}


google.setOnLoadCallback(initialize);

