// Set Up Vimeo API

var moogaloop = false;	    				
var autoplay = false;	    				
var swf_id = 'player';
var current_video = 0;

var flashvars = {
    clip_id: 0,
    show_portrait: 0,
    show_byline: 0,
    show_title: 0,
    color: '4a94c5',
	js_api: 1,
	js_onLoad: 'vimeo_player_loaded',
	js_swf_id: 'player' 
};

var params = {
	allowscriptaccess: 'always',
	allowfullscreen: 'true'
};
	
var attributes = {};

var expressinstall = "http://www.roveit.com/expressinstall.swf";




// function that runs when the Vimeo video has fully loaded into the player

function vimeo_player_loaded(swf_id) {
	
	// get video player DOM element
	moogaloop = document.getElementById(swf_id);
	
	// set up listener to listen for the video to end
	moogaloop.api_addEventListener('onFinish', 'vimeo_on_finish');
	
	// if we want to the video play right away, do so
	if(autoplay == true) {
		moogaloop.api_play();
	}
	
}



// function that runs the onFinish listener fires, ie: video is over

function vimeo_on_finish(swf_id) {
	// set autoplay to false so it wont start again, and reload the video
	// so that we don't see the Vimeo 'related videos' stuff	
	
	//autoplay = false;	
	//swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "458", "258", "9.0.0", expressinstall, flashvars, params, attributes);
	
	jQuery('#movie #player').remove();
	jQuery('<div id="player"></p>').insertBefore('#movie #social');
	
}




// function that loads the Vimeo player and video onto the homepage

function loadVideo(video_id, auto) { 
	
	// set up variables, ie: player id, video id and such
	current_video = video_id;
	flashvars.clip_id = video_id;
	autoplay = auto;
	
	// use SWFObject to embed the player, based on above variables	
	swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "458", "258", "9.0.0", expressinstall, flashvars, params, attributes);
							
}



// load the ROVE video when the player splash image is clicked

jQuery(document).ready(function() {

	jQuery('#movie div#player').click(function() {
	  loadVideo(7077036, true);
	  return false;
	});
  
});


// preload the splash rollover

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


jQuery(document).ready(function() {

jQuery.preLoadImages("/images/video_placeholder-over.jpg");
  
});
