var $j = jQuery.noConflict();
$j(document).ready(function(){
  updateTwitter();
  var updateTwitterInterval = setInterval(updateTwitter, 30000);
});
window.addEvent('domready', function() {
  // smooth scrolling
  new SmoothScroll();
  customLoad();
});
window.addEvent('unload', function() {
  if(window.customUnload) {
    customUnload();
  }
});
function customLoad() {
}
function updateTwitter()
{
  $j.ajax({
    method: 'get',
    url : 'twitter.aspx',
    dataType : 'text',
    success: function (text) { $j('#twitter-updates').html(text); }
  });
}
function loadCountdown() {
  // Countdown
  var futuredate=new cdtime("countdown", "July 11, 2009 00:00:00");
  futuredate.displaycountdown("days", formatCountdown);
}
function loadGoogleMap()
{
  // Google Map
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.enableScrollWheelZoom();
    map.setCenter(new GLatLng(47.665, -117.21), 12);//47.656044, -117.1948 47.66053163924831, -117.21811294555664), 12);
    map.setMapType( G_NORMAL_MAP );
    map.addControl(new GMapTypeControl());
    map.addControl(new GSmallZoomControl());
    // Create our custom marker icon
    var myIcon = new GIcon(G_DEFAULT_ICON);
    myIcon.image = "http://www.joinsos.org/_images/map-marker.png";
    myIcon.iconSize = new GSize(32, 32);
    myIcon.shadow = "http://www.joinsos.org/_images/map-shadow.png";
    myIcon.shadowSize = new GSize(45, 32);
    myIcon.iconAnchor = new GPoint(16, 32);
    myIcon.infoWindowAnchor = new GPoint(19, 0);
    // Set up our GMarkerOptions object
    markerOptions = { icon:myIcon };
    // Sunrise Elementary
    markerSunrise = new GMarker(new GLatLng(47.635870345156, -117.20849990844727), markerOptions);
    map.addOverlay(markerSunrise);
    GEvent.addListener(markerSunrise,"mouseover",function(){ 
      showMapProject(markerSunrise,
      "Sunrise Elementary",
      "14603 E 24th Ave, Spokane, WA",
      "Remove ground cover and weeds and<br/>\ndo general clean-up of the grounds.");
    });
    // Terrace View
    markerTerrace = new GMarker(new GLatLng(47.63585588611748, -117.22242593765259), markerOptions);
    map.addOverlay(markerTerrace);
    GEvent.addListener(markerTerrace,"mouseover",function(){ 
      showMapProject(markerTerrace,
      "Terrace View Park",
      "13500 E 24th Ave, Spokane, WA",
      "Playground renovation.");
    });
    // North Pines
    markerNP = new GMarker(new GLatLng(47.66345090425596, -117.24068641662598), markerOptions);
    map.addOverlay(markerNP);
    GEvent.addListener(markerNP,"mouseover",function(){ 
      showMapProject(markerNP,
      "North Pines Middle School",
      "701 N Pines Rd, Spokane, WA",
      "Clean-up and paint storage sheds.");
    });
    // Greenacres
    markerGreen = new GMarker(new GLatLng(47.653926561028385, -117.16354608535767), markerOptions);
    map.addOverlay(markerGreen);
    GEvent.addListener(markerGreen,"mouseover",function(){ 
      showMapProject(markerGreen,
      "Greenacres Elementary",
      "17915 E 4th Ave, Spokane, WA",
      "Paint exterior walls.");
    });
    // Mission
    markerMission = new GMarker(new GLatLng(47.67216437287117, -117.25390434265137), markerOptions);
    map.addOverlay(markerMission);
    GEvent.addListener(markerMission,"mouseover",function(){ 
      showMapProject(markerMission,
      "Valley Mission Horse Arena",
      "11223 E Mission Ave, Spokane, WA",
      "Clean-up stable and arena area.");
    });
    // Natural Area Park Cleanup
    markerSullivan = new GMarker(new GLatLng(47.6826677317923, -117.2235631942749), markerOptions);
    map.addOverlay(markerSullivan);
    GEvent.addListener(markerSullivan,"mouseover",function(){ 
      showMapProject(markerSullivan,
      "Natural Area Park Cleanup",
      "13500 E Mirabeau Parkway, Spokane, WA 99216",
      "General park cleanup of the natural<br/>\narea at the west end of Mirabeau<br/>\nPoint Park.");
    });
    // Centennial Trail
    markerCent = new GMarker(new GLatLng(47.69442551736704, -117.25029945373535), markerOptions);
    map.addOverlay(markerCent);
    GEvent.addListener(markerCent,"mouseover",function(){ 
      showMapProject(markerCent,
      "Centennial Trail",
      "11568 E Upriver Dr, Spokane, WA",
      "General clean-up of paved trail and shoulders<br/>\nof the trail between mile markers 12.5<br/>\n(Denny Ashlock Bridge) and 11.8 (Trent).");
    });    
    // Projects Latitude/Longitude
    // javascript:void(prompt('',gApplication.getMap().getCenter()));
  }
}
function showMapProject(marker, name, address, description) {
  var dir;
  if(address && !(address === "")) {
    dir = "<a href=\"http://maps.google.com/maps?daddr="+address+"\" target=\"_blank\">Get Directions</a>";
  }
  else {
    dir = "Exact location to be determined";
  }
  marker.openInfoWindowHtml("<div style=\"color: #000;\"><strong style=\"font-size: 120%;\">"+name+"</strong><br/>\n"+description+"<br/>\n<br/>\n<span style=\"font-size:85%;\"><a href=\"#involved\">Get Involved</a> &nbsp;&nbsp;"+dir+"</div>");
}
function customUnload() {
  GUnload();
}
function formatCountdown(){
  if (this.timesup==false){ //if target date/time not yet met
    var displaystring=arguments[0]+" days "+arguments[1]+" hours "+arguments[2]+" minutes "+arguments[3]+" seconds";
  }
  else { //else if target date/time met
    var displaystring=""
  }
  return displaystring
}

