var SectionLinkRectangles = new Array;
var SectionNames = new Array;
var SqNumber;
var StartLat, StartLong;
var RectCount=0;
var AvailableSections = ["O37_109N", "O37_110N", "O37_111N", "O37_112N", "O37_113N","O37_114N","O37_115N","O36_131N", "O36_132N", "O37_121N", "O37_122N",
"O37_123N", "O37_124N", "O37_125N", "O37_126N", "O37_127N", "O36_143N", "O36_144N","O37_133N", "O37_134N","O37_135N", "O37_136N", "O37_137N",
"O37_138N", "O37_139N", "N36_12N", "N37_1N", "N37_2N", "N37_3N","N37_4N", "N37_5N", "N37_6N", "N37_7N", "N37_8N", "N36_23N", "N37_13N","N37_14N",
"N37_15N","N37_16N", "N37_17N","N37_18N","N37_19N","N37_20N","N37_21N", "N37_25N", "N37_26N","N37_27N", "N37_28N","N37_29N","N37_30N", "N37_31N",
"N37_40N", "N37_43N", "N37_44N"];

var NormalOptions = {
    strokeColor: 'green',
    strokeOpacity: 0.5,
    strokeWeight: 1,
    fillColor: 'green',
    fillOpacity: 0.12,
    map: map }
    
var EmptyRectangleOptions = {
    strokeOpacity: 0,
    strokeWeight: 0,
    fillOpacity: 0,
    map: map };
    
var HoverRectangleOptions = {
    strokeColor: 'blue',
    strokeOpacity: 0.5,
    strokeWeight: 1,
    fillColor: 'blue',
    fillOpacity: 0.12,
    map: map }
var CurrentRectangleOptions;


for (Lat=57; Lat>=54.9; Lat=Lat-1/3)

{
  for (Long=35; Long<=40; Long=Long+0.5)
  {
   
   if (Lat<=56) 
   { SqNumber = 'N'; 
   StartLat = 56;
   }
   else
    {SqNumber='O';
     StartLat = 60;
     }
   if (Long>=36)
   {
    SqNumber+='37';
    StartLong = 36;
    }
    else 
   {
    SqNumber+='36';
    StartLong=30;
    }

SectionNames[RectCount]=SqNumber+'_'+(Math.round((StartLat-Lat)/(1/3))*12+ Math.round((Long-StartLong)/0.5)+1)+'N';
  
  for (var i=0; i<=AvailableSections.length;i++)
  {
  if (SectionNames[RectCount] == AvailableSections[i]) 
  { CurrentRectangleOptions = NormalOptions;
    break
  }
    else
    {   CurrentRectangleOptions = EmptyRectangleOptions;
    }
   }
   
      CurrentRectangleOptions.bounds = new google.maps.LatLngBounds(
      new google.maps.LatLng( Lat, Long),
      new google.maps.LatLng(Lat-1/3, Long+0.5));
      
    SectionLinkRectangles[RectCount] = new google.maps.Rectangle(CurrentRectangleOptions);
    SectionLinkRectangles[RectCount].Link = CityLinkPath+SectionNames[RectCount]+'.html';
 
  if (SectionLinkRectangles[RectCount].fillOpacity!=0)
     {
      google.maps.event.addListener(SectionLinkRectangles[RectCount], 'click', function() {window.location.href = this.Link });
      google.maps.event.addListener(SectionLinkRectangles[RectCount], 'mouseover', function() {this.setOptions(HoverRectangleOptions); window.status=this.Link});
      google.maps.event.addListener(SectionLinkRectangles[RectCount], 'mouseout', function() { var OldBounds = this.getBounds(); this.setOptions(NormalOptions); this.setBounds(OldBounds); window.status=''});
        
     } else google.maps.event.addListener(SectionLinkRectangles[RectCount], 'click', function() {window.alert ('Для этого квадрата данные пока отсутствуют') });
  
  RectCount++;      


  }
}


