title: Open Google Maps InfoWindow based on certain criteria
body: <p>I want to open a Google Maps <code>InfoWindow</code> based on whether or not one of my buildings is throwing a building alarm. The buildings I have the markers on all have alarm states (on or off), and if they are in alarm state, I am changing the color of the marker to yellow or red, depending on the severity of the alarm. When the alarms are "red" alarms, the marker is animated with the <code>google.maps.Animation.BOUNCE</code> effect.</p>
  
  <p>The bounce effect is sometimes not enough to garner attention (we leave this screen open on a wall, and the data in the <code>$(this).children(".alarm-count")</code> div below changes dynamically due to another script we have running on the site in the background.</p>
  
  <p>I already know how to change the markers based on the alarm state, can I also open an InfoWindow within the same condition? I have tried this:</p>
  
  <pre><code>        google.maps.event.addListener(map,'idle',(function(marker,i){
              return function(){
                  infowindow.setContent(
  
                      '&lt;div class="infowindow-inner"&gt;'+
                          '&lt;a href="'+bldgGfx[i]+'" onclick="window.open('+bldgGfx[i]+');return false;" target="_blank" title="'+bldgName[i]+' ('+bldgAddr[i]+')"&gt;'+
                              '&lt;h2&gt;'+bldgName[i]+'&lt;/h2&gt;'+
                              '&lt;h4&gt;'+bldgAddr[i]+'&lt;/h4&gt;'+
                              '&lt;p&gt;'+mainMeter[i]+' kW&lt;/p&gt;'+
                              '&lt;p&gt;'+alarmCount[i]+' Alarms&lt;/p&gt;'+
                      '&lt;/div&gt;'
  
                  );infowindow.open(map,marker);
              }
          })(marker,i));
  </code></pre>
  
  <p>but it doesn't seem to be working.</p>
  
  <p><strong>The long and short of it is I need to evaluate one value per marker in my page, and open (or not open) the InfoWindow for each building based on that value.</strong></p>
  
  <p>Here is my code:</p>
  
  <pre><code>$(".building").each(function(i){
  
      bldgNo[i] = $(this).children(".bldg-no").html().slice(1);
      bldgName[i] =   $(this).children(".bldg-name").html();
      bldgAddr[i] =   $(this).children(".bldg-address").html();
      bldgGfx[i] =    $(this).children(".bldg-graphic").html();
      mainMeter[i] =  $(this).children(".main-meter").html();
      alarmCount[i] = $(this).children(".alarm-count").html();
      latitude[i] =   $(this).children(".latitude").html();
      longitude[i] =  $(this).children(".longitude").html();
  
      if (alarmCount[i]!="N/A"){alarmCount[i]=alarmCount[i].slice(0,-3);}
      if (alarmCount[i]&gt;"0" &amp;&amp; alarmCount[i]!="N/A"){
          marker=new google.maps.Marker({position:new google.maps.LatLng(latitude[i],longitude[i]),map:map,shadow:shadow,icon:redIcon,title:bldgName[i]+" \n"+bldgAddr[i],optimized:false});marker.setAnimation(google.maps.Animation.BOUNCE);
  
  
      ////    
      //// THE COMMAND TO OPEN THE INFOWINDOW WILL GO HERE, RIGHT?
      ////
  
  
      }
      else if ($(this).hasClass("new")||(mainMeter[i]=="N/A")||(!isNumber(mainMeter[i]))) {
          marker=new google.maps.Marker({position:new google.maps.LatLng(latitude[i],longitude[i]),map:map,shadow:shadow,icon:yellowIcon,title:bldgName[i]+" \n"+bldgAddr[i],optimized:false});marker.setAnimation(google.maps.Animation.NULL);}
      else {
          marker=new google.maps.Marker({position:new google.maps.LatLng(latitude[i],longitude[i]),map:map,shadow:shadow,icon:greenIcon,title:bldgName[i]+" \n"+bldgAddr[i],optimized:false});marker.setAnimation(google.maps.Animation.NULL);}
  
      markersArray.push(marker);
      google.maps.event.addListener(marker,'click',(function(marker,i){
          return function(){
              infowindow.setContent(
  
                  '&lt;div class="infowindow-inner"&gt;'+
                      '&lt;a href="'+bldgGfx[i]+'" onclick="window.open('+bldgGfx[i]+');return false;" target="_blank" title="'+bldgName[i]+' ('+bldgAddr[i]+')"&gt;'+
                          '&lt;h2&gt;'+bldgName[i]+'&lt;/h2&gt;'+
                          '&lt;h4&gt;'+bldgAddr[i]+'&lt;/h4&gt;'+
                          '&lt;p&gt;'+mainMeter[i]+' kW&lt;/p&gt;'+
                          '&lt;p&gt;'+alarmCount[i]+' Alarms&lt;/p&gt;'+
                  '&lt;/div&gt;'
  
              );infowindow.open(map,marker);
          }
      })(marker,i));
  
      i++;
  
  });
  </code></pre>