<commit_before>mw.addFreeWheelControler = function( embedPlayer, config, callback ) {
	embedPlayer.freeWheelAds = new mw.freeWheelControler({ 
		'embedPlayer' : embedPlayer,
		'config' : config,
		'callback' :  callback
	});
};

mw.freeWheelControler = function( opt ){
	return this.init( opt );
};

mw.freeWheelControler.prototype = {
	init: function( opt ){
		var _this = this;
		$j.extend( this, opt);
		// Load the ad manager url:
		// XXX todo we should be able to read this from "adManagerUrl"
		var AdManagerUrl = mw.getConfig( 'FreeWheel.AdManagerUrl' );
		// For debuging use local copy: 
		//$j.getScript(AdManagerUrl, function(){
		mw.load('tv.freewheel.SDK', function(){
			_this.setupAds();
		});
	},
	setupAds: function(){
		var _this = this;
		this.freewheel= new tv.freewheel.SDK.AdManager();
		this.freewheel.registerVideoDisplayBase( 'videoContainer' );
		
		// @@TODO Need to confirm relatively arbitrary mapping
		this.freewheel.setVideoAsset( this.config.videoAssetId,  this.embedPlayer.duration );
		this.freewheel.setSiteSection( this.config.networkId );
		this.freewheel.setServerURL( this.config.serverUrl );
		
		// XXX strange.. FreeWheels servers respond with SVLads037 while its not defined ?
		window.SVLads037 = true;
		
		this.freewheel.submitRequest( function(){ 
			_this.adsRequestComplete();
		}, 4000 );
	},
	adsRequestComplete: function(){
		var _this = this;
		mw.log( "freeWheelControler::adsRequestComplete> " + this.callback);
		if( this.callback )
			this.callback();
		
		// Read the ad response
		$j( this.embedPlayer ).bind( 'onplay', function(){
			_this.embedPlayer.stopEventPropagation();
			_this.freewheel.playSlots( tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL, function(){
				_this.prerollComplete 
			});
		});
	},
	prerollComplete: function(){
		var _this = this;
		debugger;
		
		this.embedPlayer.restoreEventPropagation();
		// Restore player
		mw.log('freeWheelControler:: restore original video ');
	}
};<commit_msg>minor flow clean up<commit_after>mw.addFreeWheelControler = function( embedPlayer, config, callback ) {
	embedPlayer.freeWheelAds = new mw.freeWheelControler({ 
		'embedPlayer' : embedPlayer,
		'config' : config,
		'callback' :  callback
	});
};

mw.freeWheelControler = function( opt ){
	return this.init( opt );
};

mw.freeWheelControler.prototype = {
	init: function( opt ){
		var _this = this;
		$j.extend( this, opt);
		// Load the ad manager url:
		// XXX todo we should be able to read this from "adManagerUrl"
		var AdManagerUrl = mw.getConfig( 'FreeWheel.AdManagerUrl' );
		
		//$j.getScript(AdManagerUrl, function(){
		
		// For debugging use local copy: 
		mw.load('tv.freewheel.SDK', function(){
			_this.setupAds();
		});
	},
	setupAds: function(){
		var _this = this;
		this.freewheel= new tv.freewheel.SDK.AdManager();
		this.freewheel.registerVideoDisplayBase( 'videoContainer' );
		
		// @@TODO Need to confirm relatively arbitrary mapping
		this.freewheel.setVideoAsset( this.config.videoAssetId,  this.embedPlayer.duration );
		this.freewheel.setSiteSection( this.config.networkId );
		this.freewheel.setServerURL( this.config.serverUrl );
		
		// XXX strange.. FreeWheels servers respond with SVLads037 while its not defined ?
		window.SVLads037 = true;
		
		this.freewheel.submitRequest( function(){ 
			_this.adsRequestComplete();
		}, 4000 );
	},
	adsRequestComplete: function(){
		var _this = this;
		mw.log( "freeWheelControler::adsRequestComplete> " + this.callback);
		
		// Read the ad response
		$j( this.embedPlayer ).bind( 'onplay', function(){
			_this.embedPlayer.stopEventPropagation();
			_this.freewheel.playSlots( tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL, function(){
				_this.prerollComplete 
			});
		});
		
		// Freewheel ad loading is complete issue callback: 
		if( this.callback ){
			this.callback();
		}
	},
	prerollComplete: function(){
		var _this = this;
		this.embedPlayer.restoreEventPropagation();
		// Restore player
		mw.log('freeWheelControler:: restore original video ');
	}
};
{'fraction_non_alphanumeric': 0.13256915026164964, 'fraction_numerical': 0.0049838026414154, 'mean_word_length': 4.061790668348046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649018', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1294, 'n_words': 287}