// Handle the embedding of flash videos into the DOM through swfObject
Makena.EmbedVideoPlayers = {

	init: function() {
		// selector for images with the class type flash-embed and replace them with video embeds
		$('img.flash-embed').each(function(){
			var playerPath = $(this).attr('title'); // path to the video directory is stored in the images title attribute which is fine since the image will never be displayed
			var w = $(this).width(); // width of the video is the same as the images width
			var h = $(this).height(); // height of the video is the same as the images height
			// use the jquery swfObject plugin to create a video embed
			var swfObj = $.flash.create({
				swf:playerPath+'player.swf', // the player path varies but the player name is the same
				width:w, 
				height:h,
				hasVersion: 9, // require at least version 9 of the flash player to be installed and if not prompt upgrade
				params: {
					play:true, // auto play
					loop:false, // don't loop
					flashvars: {
						playerPath:playerPath // tell the player where it's hosted so it can access assets when it needs to
					}
				}
			});
			// after the image marked as a video, add the flash video, then remove the image from the dom
			$(this).after(swfObj).remove();
		});
	}
};

// when the html is finished downloading and the browser has rendered the dom elements, parse the dom for images tagged as videos and convert them to embedded videos
$(document).ready(function() {
	Makena.EmbedVideoPlayers.init();
});
