var cameraIcon = new GIcon();
cameraIcon.image = "http://maps.google.com/mapfiles/kml/pal4/icon46.png";
cameraIcon.iconSize = new GSize(17, 17);
cameraIcon.iconAnchor = new GPoint(9, 9);
cameraIcon.infoWindowAnchor = new GPoint(9, 9);

var cameraIconMed = new GIcon();
cameraIconMed.image = "http://maps.google.com/mapfiles/kml/pal4/icon46.png";
cameraIconMed.iconSize = new GSize(32,32);
cameraIconMed.iconAnchor = new GPoint(12,12);
cameraIconMed.infoWindowAnchor = new GPoint(12,12);

var cameraIconLarge = new GIcon();
cameraIconLarge.image = "http://maps.google.com/mapfiles/kml/pal4/icon46.png";
cameraIconLarge.iconSize = new GSize(41,41);
cameraIconLarge.iconAnchor = new GPoint(15,15);
cameraIconLarge.infoWindowAnchor = new GPoint(15,15);

var cameraImport = 30;
var cameraTimerId = null;

var cameraIconClass = Class.create(mapIconClass,{
    iconSmall: cameraIcon,
    iconMedium: cameraIconMed,
    iconLarge: cameraIconLarge,
    zIndex: cameraImport,
    type: "camera",
    initialize: function ($super, obj){
       Object.extend(this, obj);
       this.title = this.location['intersection'];
       this.lat = this.location.lat;
       this.lng = this.location.lon;
       $super(this);
    },
    update: function ($super, newObj) {
       $super(newObj);
    },
    getMarkerText: function () {
        var imgClass = "";
        var viewName = "";
        var divWidth = "";
        if(!this.size) this.size = "small";
        if(this.size == "small") {
           imgClass = "smallImage";
           viewName = "Larger";
           divWidth = "360px";
           
        } else {
           imgClass = "largeImage";
           viewName = "Smaller";
           divWidth = "528px;"
        }
        var tabs = new Array();
        var tabsLarge = new Array();
        var snapshots = this.snapshots;
        var latlon = this.location;
        var infoWin = map.getInfoWindow();
        for (var j = 0; j < snapshots.length; j++){
           var timestamp = new Date();
           var fileinfo = snapshots[j];
           var index = 0;
var src = "<p><img src = 'http://www.lakecountypassage.com/snapshots/" + fileinfo.filename + "?x=" + Date.parse(timestamp) + "' class='"+imgClass+"'/></p>";
src += "<div style=\"width:"+divWidth+"\"><span style=\"float: left; color:black; font-family: verdana; font-size: 10pt; font-weight: bold;\">" + latlon.intersection + "<br>Looking " + fileinfo.direction + "</span>";
src += "<span style=\"font-family: verdana; font-size: 10pt; font-weight: bold; color:black; float: right\"><a id='linkName' href=\"javascript:switchPopup()\">"+viewName+" View</a></span></div>";

           tabs.push(new GInfoWindowTab(fileinfo.direction, src));
        }
        map.updateInfoWindow(tabs);
        infoWin.iconObj = this;
        if(cameraTimerId != null) clearTimeout(cameraTimerId);
        cameraTimeId = setTimeout("reloadInfoWindow()", 120000);
    }
});



function switchPopup(){
     var infoWin = map.getInfoWindow();
     var marker = infoWin.iconObj;
     if(marker.size == "small") marker.size = "large";
     else marker.size = "small";
     marker.getMarkerText();
}

function reloadInfoWindow()
{
     if(!map.getInfoWindow().isHidden()){
         var marker = map.getInfoWindow().iconObj;
         if(marker && null != marker) marker.getMarkerText();
     }
}

function addCameraWindowClose(){
  GEvent.addListener(map, "infowindowclose", function (){
    if(cameraTimerId != null) clearTimeout(cameraTimerId);
    cameraTimerId = null;
    if(map.getInfoWindow()) map.getInfoWindow().iconObj = null;
  });
}

