$(document).ready(function() {

	// bind the flash video player to the video player div
	$("[id^=playvid]").each(function(){
		var re = /\d+/;
		var id = $(this).attr('id').match(re)[0];

		var s = new SWFObject('/swf/vodplayer.swf','player_r' + id,'500','300','9');
		s.addParam('name', 'player_r' + id);
		s.addParam('allowfullscreen','true');
		s.addParam('swliveconnect', 'true');
		s.addParam('AllowScriptAccess','always');
		s.addParam('flashvars','file=/vodcasts/'+id+'&amp;type=video');
		s.write('playvid_r'+id);

	});

	// create a callback for the video player popup div so it can tell poplight how to close it properly
	$("[id^=video_r]").each(function() {

		$(this).bind('popupOnClose', function() {
			var re = /\d+/;
			var id = $(this).attr('id').match(re)[0];

			var moo = document.getElementById('player_r' + id);
			moo.sendEvent('STOP');
		});

	});

});
