function loadPlayer(id, activity_id, width, height) {
	if(!width) {
		width = "320px";
	}
	if(!height) {
		height = "240px";
	}
	
	$('a|videoDiv|'+id+'|'+activity_id).setStyle('display', 'none');
	var player = new Swiff('/app/1/flash/player.swf', {
								'width': width,
								'id': 'player|'+id+"|"+activity_id,								
								'height': height,
								'container': $("videoDiv|"+id+"|"+activity_id),
								'params': {
									'allowScriptAccess' : 'always',
									'allowfullscreen': "true"
								},
								'properties': { 
									'name': 'player|'+id+"|"+activity_id
								},
								'vars': {
									'controlbar': 'over',
									'autostart': 'true',
									'file': 'http://www.youtube.com/v/'+id
								}
						});	
}

var player = null;
function playerReady(thePlayer) {
	player = $(thePlayer.id);
	addListeners();
}
 
 
function addListeners() {
	if (player) {
		player.addModelListener('STATE', 'stateMonitor');
	} else {
		setTimeout("addListeners()",100);
	}
}

function stateMonitor(obj) {
  if(obj.newstate == 'COMPLETED') {
	  $('a|videoDiv|'+obj.id.split('|')[1]+'|'+obj.id.split('|')[2]).setStyle('display', 'inline-block');
	  $('player|'+obj.id.split('|')[1]+"|"+obj.id.split('|')[2]).parentNode.removeChild($('player|'+obj.id.split('|')[1]+"|"+obj.id.split('|')[2]));
  }
}

