/*
 *jQuery Vimeo Plugin
 *Copyright 2009 Robby Colvin
 */
(function($){
  $.fn.vimeo = function(settings) {
    $.fn.vimeo.el = $(this);
    $.getJSON("http://vimeo.com/api/v2/" + settings.user + "/videos.json?callback=?", function(response) {
      var jsonResponse = response;
      $.each(response, function(item) {
        jsonResponse = $.grep(jsonResponse, function(asdf) {
          return asdf.tags.indexOf(settings.tag,0);
        }, true);
      });

      $.each(jsonResponse, function(i, item) {
        $.fn.vimeo.el.append("<li><p>" + item.title + " <a href='http://vimeo.com/moogaloop.swf' title='" + item.title + "\
          ' rel='shadowbox;width=503;height=378;options={flashVars:{clip_id:" + item.id + "}}'>Play &raquo;</a>");
        });
      if ($.fn.vimeo.el.children("li").size() > 0) {
        Shadowbox.setup();
        $.fn.vimeo.el.parent().fadeIn();
      }
    });
  };
})(jQuery);
