/* stuff.js - some code for the Processing Hack Week website that
 * fades some images in and out
 */

images = [
  {
    'img': 'hex_illusion.jpg',
    'caption': 'Hex Illusion by Stinging Eyes',
    'src': 'http://www.flickr.com/photos/martinlatter/3117564781/'
  },
  {
    'img': 'tangle.jpg',
    'caption': 'Tangle by Wblut',
    'src': 'http://www.flickr.com/photos/wblut/2365458971/'
  },
  {
    'img': 'bobblescence.jpg',
    'src': 'http://www.flickr.com/photos/martinlatter/2891285509/',
    'caption': 'Bobblescence by Stinging Eyes'
  },
  {
    'img': 'two_furry_balls.jpg',
    'src': 'http://www.flickr.com/photos/xfrf/3113315058/',
    'caption': 'two furry balls by xfrf'
  },
  {
    'img': 'extranet_visualization.jpg',
    'src': 'http://www.flickr.com/photos/mjryall/2926798990/',
    'caption': 'Extranet comments visualization by Matt Ryall'
  }
];
current_image = 0;

function set_image (i) {
  var image = images[i];
  $('#img-fader').attr('src', image['img']);
  $('#img-caption').attr('href', image['src']).text(image['caption']);
}

function switch_image () {
  current_image++;
  if (current_image == images.length)
    current_image = 0;
  $('#img-fader').fadeOut(2500, function () {
			    set_image(current_image);
			    $('#img-fader').fadeIn(2500, function () {
			      setTimeout(switch_image, 5000);
			    });
			  });
}

$(document).ready(function () {
		    set_image(0);
		    setTimeout(switch_image, 5000);
                    var startDate = (new Date(2009, 0, 28)).getTime(); // January 28th
                    var finishDate = (new Date(2009, 1, 4)).getTime(); // February 4th
		    var today = (new Date()).getTime();
                    if (today >= startDate && today <= finishDate) {
                      $('#when').append("<br/><em>Right now! Today! :)</em>");
                    } else if (today > finishDate) {
                      $('#when').append("<br/><em>It was fun, but now it's over :(</em>");
                    }
		  });