var WistiaVideoTracker = {
	track: function(name, player) {
		var obj = {
			keepTracking: true,
			wPlayer: undefined,
			wasPaused: false,
			wasStopped: true,
			videoName: "",
			track: function(name, player) {
				this.keepTracking = true;
				this.wPlayer = player;
				this.videoName = name;
				this.pollPlayer();
			},
			stop: function() {
				this.keepTracking = false;
			},
			pollPlayer: function() {
				if(this.keepTracking) {
					var wps = this.wPlayer.getCurrentState();
					if (wps === 1) {
						this.wasPaused = false;
						this.wasStopped = false;
						var ct = this.wPlayer.getCurrentTime();
						if(!ct || ct === 0) {
							ct = 0.1;
						}
						this.sendData('time', ct);
					}
					else if (this.wasStopped === false && wps === 0) {
						this.wasPaused = false;
						this.wasStopped = true;
						this.sendData('eov', this.wPlayer.getCurrentTime());
					}
					else if (this.wasPaused === false && wps === 2) {
						this.wasPaused = true;
						this.wasStopped = false;
						this.sendData('buttonclick', 'pause');
					}
					setTimeout(function(thisObj) { thisObj.pollPlayer(); }, 5000, this);
				}
			},
			sendData: function(eventName, value) {
				if ((typeof cat == "object") && (typeof cat.VideoData == "function")) {
					cat.VideoData(this.videoName, eventName, this.wPlayer.getCurrentTime(), value);
				}
			}
		};
		obj.track(name,player);
		return obj;
	}
};
