var player;
var experienceModule;
var videoPlayerModule;
var adModule;
var ad;
var a=0;

function onTemplateLoaded(id)    {
	player = brightcove.getExperience(id);
	adModule = player.getModule(APIModules.ADVERTISING);
	adModule.addEventListener(BCAdvertisingEvent.AD_START, onAdStart);
	adModule.addEventListener(BCAdvertisingEvent.AD_COMPLETE, onAdComplete);
	videoPlayer = player.getModule(APIModules.VIDEO_PLAYER);
	videoPlayer.addEventListener(BCContentEvent.VIDEO_LOAD, start_inskin);
}

function onAdStart()
{
	ad="preroll";
}

function onAdComplete()
{
	InSkinParams['srv_Keywords'] = '{/literal}{foreach from=$video.tags item=tag}{$tag|lower|escape},{/foreach}{literal}prerollserved';
	InSkinLoad.init(InSkinParams);
}

function start_inskin()
{
	if(ad==null&&a==0)
	{
		InSkinParams['srv_Keywords'] = '{/literal}{foreach from=$video.tags item=tag}{$tag|lower|escape},{/foreach}{literal}';
		InSkinLoad.init(InSkinParams);
		a++;
	}
}
