$(document).ready( function(){

  var vid = new String(window.location.hash).replace("#", "");
  
  $("a[rel='vimeo']").each( 
    function(i){
      $(this).click(function(){ 
      
          $("#player-embed").html('<object width="500" height="325">' + 
                                  '<param name="allowfullscreen" value="true" />' +
                                  '<param name="allowscriptaccess" value="always" />' +
                                  '<param name="movie"' + 
                                    'value="' + $(this).attr("href") + '" />' +
                                  '<embed src="' + $(this).attr("href") + '"' +
                                  'width="500" height="325"' +
                                  'type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always">' +
        '</embed></object>');
        
        $("#player-caption").html($(this).attr("caption") + 
                                  "<br /> <a style='color: red' href='" + $(this).attr("href") + "' target='_new'>Pop out (new window)</a>");
        tb_show("", "#TB_inline?height=400&width=600&inlineId=videoPlayerDiv", null);
        
        jQuery(document).bind('thickBoxClosed', function(event, msg) { window.location.hash = "NONE"; });
        window.location.hash = $(this).attr("caption");
        return false; 
      });
      
      if(vid != "NONE" && vid == $(this).attr("caption")){
        $(this).trigger("click");
      }
      
    });
});  
