var $j = jQuery.noConflict();
$j(document).ready(function(){
  updateTwitter();
  var updateTwitterInterval = setInterval(updateTwitter, 30000);
});
loadFlickr();
window.addEvent('domready', function() {
  // smooth scrolling
  new SmoothScroll();
  customLoad();
});
window.addEvent('unload', function() {
  if(window.customUnload) {
    customUnload();
  }
});
function customLoad() {
}
function loadFlickr() {
    $j.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157624792434766&nsid=29899367@N02&lang=en-us&format=json&jsoncallback=?", function(data) {
        var count = 0;
        $j.each(data.items, function(i, item) {
            if (count > 5) return;
            var p = item.media.m.replace('_m', '_s');
            $j("<img/>").attr("src", p).appendTo("#flickr-pics").wrap("<a href='" + item.link + "'></a>");
            count++;
        });
        /*$j('#flickr-pics').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 0,
        next: '#next',
        prev: '#prev'
        });*/
    });
}
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", "August 14, 2010 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), 11);//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 };
    // Barker High School
    markerBarker = new GMarker(new GLatLng(47.66530065105367, -117.22493648529053), markerOptions);
    map.addOverlay(markerBarker);
    GEvent.addListener(markerBarker,"mouseover",function(){ 
      showMapProject(markerBarker,
      "Barker High School",
      "13313 East Broadway Avenue, Spokane Valley, WA 99216",
      "Assemble a pre-purchased storage shed.");
    });
    // Central Valley
    markerCV = new GMarker(new GLatLng(47.649734721373136, -117.19184875488281), markerOptions);
    map.addOverlay(markerCV);
    GEvent.addListener(markerCV,"mouseover",function(){ 
      showMapProject(markerCV,
      "Central Valley High School",
      "821 South Sullivan Road, Spokane Valley, WA 99037",
      "Assemble a pre-purchased storage shed.");
  });
  // early learning
  markerELC = new GMarker(new GLatLng(47.64875175854892, -117.26733684539795), markerOptions);
  map.addOverlay(markerELC);
  GEvent.addListener(markerELC, "mouseover", function() {
      showMapProject(markerELC,
      "Early Learning Center",
      "10304 E 9th Ave, Spokane Valley, WA 99206",
      "Paint exterior portions of the building and<br />accomplish some minor grounds-keeping.<br />(Family friendly. Need ladders.)");
  });
  // opportunity
  markerOpportunity = new GMarker(new GLatLng(47.64702, -117.246618), markerOptions);
  map.addOverlay(markerOpportunity);
  GEvent.addListener(markerOpportunity, "mouseover", function() {
    showMapProject(markerOpportunity,
      "Opportunity Elementary",
      "1109 South Wilbur Road, Spokane Valley, WA 99206",
      "Disassemble children's playground equipment at<br />Barker High School and install at Opportunity (tentative).");
  });
  // liberty lake
  markerLiberty = new GMarker(new GLatLng(47.667559, -117.088327), markerOptions);
  map.addOverlay(markerLiberty);
  GEvent.addListener(markerLiberty, "mouseover", function() {
      showMapProject(markerLiberty,
      "Liberty Lake Elementary",
      "23606 East Boone Avenue, Liberty Lake, WA 99019",
      "Paint exterior portions of the building.<br />(Need ladders.)");
  });
  // progress
  markerProgress = new GMarker(new GLatLng(47.663348, -117.200574), markerOptions);
  map.addOverlay(markerProgress);
  GEvent.addListener(markerProgress, "mouseover", function() {
      showMapProject(markerProgress,
      "Progress Elementary",
      "710 North Progress Road, Spokane Valley, WA 99037",
      "Assemble a storage chest and build a bench<br />in the entryway.");
  });
  // university
  markerUniv = new GMarker(new GLatLng(47.641523, -117.260025), markerOptions);
  map.addOverlay(markerUniv);
  GEvent.addListener(markerUniv, "mouseover", function() {
      showMapProject(markerUniv,
      "University Elementary",
      "1613 South University Road, Spokane Valley, WA 99206",
      "Paint the gutters and eaves around the building<br />and accomplish some minor grounds-keeping.<br />(Need ladders).");
  });
  // broadway
  markerBroadway = new GMarker(new GLatLng(47.663431, -117.257209), markerOptions);
  map.addOverlay(markerBroadway);
  GEvent.addListener(markerBroadway, "mouseover", function() {
      showMapProject(markerBroadway,
      "Broadway Elementary",
      "11016 East Broadway Avenue, Spokane Valley, WA 99206",
      "Paint the exterior portions of the building<br />and accomplish some minor grounds-keeping.");
  });

    // 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
}

