$(document).ready(function() {
  runBuild = function(){
    $('.refreshLink').hide("normal");
    $('#title').show("fast");
    $('#title_cont').show("fast");
    $('#images').show("fast");
    $('#flickrNav').show("fast");
    ret = $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=61897336@N00&lang=en-us&format=json&jsoncallback=?",
    function(data){
      $.each(data.items, function(i,item){ 
        $("<img />").attr({
          src: item.media.m,
          title: item.title,
          alt: item.title
        }).appendTo("#images").wrap("'<a href='" + item.link + " title=\"" + item.title +"\" target=\"_blank\"></a>");
      });
      $('#images').cycle({
        fx:     'fade',
        sync:   true,
        speed:    1000,
        timeout:  7000,
        next:   '#next',
        prev:   '#prev',
        pause:  1,
        random: 0,
        containerResize: 0,
        fit: 1,
        before: function() { $("#title").html($(this).attr('title')); }
      });
    });
    if(ret == "") {
      $('#title').hide("normal");
      $('#title_cont').hide("normal");
      $('#images').hide("normal");
      $('#flickrNav').hide("normal");
      $('.refreshLink').show("normal");
    }
    return false;
  }
  $(function(){
    if(typeof(loadFlickr) != "undefined") {
      runBuild();
      $('a.refreshLink').click(runBuild);
    }
  });
});
