var moogaloop = false;

function vimeo_player_loaded(swf_id) {
	moogaloop = document.getElementById("moogaloop");
	moogaloop.api_addEventListener('onFinish',   'vimeo_on_finish');
}

function vimeo_on_finish(swf_id) {
  if ($("ul.image-list li").length > 1) {
    $("ul.image-list a").each(function(){ 
      if ($(this).attr("href") == window.location.hash.substr(1)) {
        $(this).parent().next().find("a").click();
        return false;
      }
    });
  }
}

function load_vimeo_player(video_id) {
  // Run the javascript when the page is ready
  var swf_id = 'moogaloop';
  var callback = callback || function(){};
  
  var flashvars = {
    clip_id: video_id,
    show_portrait: 1,
    show_byline: 1,
    show_title: 1,
    autoplay: 1,
    js_api: 1, // required in order to use the Javascript API
    js_onLoad: 'vimeo_player_loaded', // moogaloop will call this JS function when it's done loading (optional)
    js_swf_id: 'moogaloop' // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
  };
  var params = {
    allowscriptaccess: 'always',
    allowfullscreen: 'true'
  };
  var attributes = {};

  // For more SWFObject documentation visit: http://code.google.com/p/swfobject/wiki/documentation
  swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "500", "375", "9.0.0","expressInstall.swf", flashvars, params, attributes);
  
}

