function NBAVideoPlayer() {
	this.playerDiv = '';
	this.context = 'nba_standalone_player';
	this.siteSection = '';
	this.playlist = [];
	this.useHTML5 = /\b(iPad|iPod|iPhone)\b/.test(window.navigator.userAgent);
	
	this.initialize = function(vidPlayerDiv, vidPlaylist, height, width, context, siteSection) {

		if (new NBA_FlashDetect().getVersion() == 0 && !(this.useHTML5) && document.getElementById(vidPlayerDiv)) {
			document.getElementById(vidPlayerDiv).innerHTML = '<a target="_blank" href="http://get.adobe.com/flashplayer/"><img height="' + height + '" width="' + width + '" alt="Flash not detected. Click here to install Adobe Flash Player" src="http://i.cdn.turner.com/nba/nba/.element/img/2.0/global/640x360_no_flash.jpg" /></a>';
			return false;
		};
	
		if (context) {
			this.context = context;
		}
		if (siteSection) {
			this.siteSection = siteSection;
		}
		this.playerDiv = vidPlayerDiv;
		var ct=vidPlaylist.length
		for (var i=0; i < ct; i++) {
			var thisVid = vidPlaylist[i];
			thisVid = thisVid.replace(/\.json$/i, '');
			this.playlist[i] = thisVid;
		}

		CVP_config.height = height;
		CVP_config.width = width;
		CVP_config.flashVars.contentId = this.playlist[0],
		CVP_config.flashVars.player = this.context;
		CVP_player = new CVP( CVP_config );
		CVP_player.embedSWF(this.playerDiv);
		CVP_player.video_obj = this;
	}	
	this.queueNext = function(videoId) {
		this.log('[CVP] NBAVideoPlayer.queueNext(' + videoId + ')');
		videoId = videoId.replace(/\.xml/i, '');
		var marker = this.playlist.indexOf('/video/' + videoId)
		var ct = this.playlist.length - 1;
		if ((marker > -1) && (marker < ct)) {
			marker++;
			this.log('[CVP] queueing next id: ' + marker);
			CVP_player.queue(this.playlist[marker]);
		}		
	}
	this.playVideo = function(videoID) {
		this.log('[CVP] playVideo(' + videoID + ')');
		CVP_player.play(videoID);
	}

	this.log = function(message) {
		if (typeof(console) != 'undefined') {
			console.log(message)
		}
	}
	this.error = function(message) {
		if (typeof(console) != 'undefined') {
			console.error(message)
		}
	}	
}
var CVP_player;
var CVP_config = {
	id : 'cvp_standaloneplayer',
	width : 320,
	height : 210,
	flashVars : {
		player : 'nba_standalone_player'
	},

	embed : {
		containerSwf : 'http://i.cdn.turner.com/nba/nba/.element/swf/1.1/cvp/nba_container.swf',
		expressInstallSwf : 'http://i.cdn.turner.com/v5cache/turnerplayer/flash/expressInstall.swf',
		options : {
			quality : 'high',
			bgcolor : '#000000',
			allowFullScreen : 'true',
			allowScriptAccess : 'always',
			wmode : 'transparent'
		}
	},

	onContentPlay : function() {
		var videoId = this.getContentId();
		this.video_obj.queueNext(videoId);

		//Omniture Implementation
		var videoMetaData = this.getContentEntry(videoId).evalJSON(true);
		if (videoMetaData.isExpired == 'no') {
			w.nbaOmCurrentVideo = videoMetaData.id;
			nbaOmEvent.videoSource = 'L';
			nbaOmEvent.videoContext = 'S';
			nbaOmEvent.videoId = videoMetaData.id;
			nbaOmEvent.videoTitle = videoMetaData.headline;
			nbaOmEvent.videoRunTime = videoMetaData.trt;
			nbaOmEvent.videoPlayerType = 'CVP';
			var tempFolders = videoMetaData.category.split('/');
			var sectionName = tempFolders[tempFolders.length-1];
			nbaOmEvent.videoCategory = (nbaOmSuiteInfo.currentTeam ? nbaOmSuiteInfo.currentTeam : nbaOmSuiteInfo.currentLeague)+':'+sectionName;
			nbaOmEvent.onStreamStart();
		}
	},


	onContentDataLoaded : function(videoId) {	},
	onPlayerReady : function() {
		if (this.video_obj.siteSection) {
			this.setAdSection(this.video_obj.siteSection);
		}	
	},
	onAdPrerollUrl : function(videoId, adUrl) {},
	onAdPostrollUrl : function(videoId, adUrl) {},
	onAdStarted : function(token) {	},
	onAdFinished : function(token) {},
	onAdSensitive : function (videoId) {	},
	onVideoPlayerBegin : function(videoId, json) {},
	onVideoPlayerPlay : function(videoId) {	},
	onVideoPlayerStop : function(videoId) {},
	onAdError : function(message) {},
	onVideoPlayerError : function(message) {},
	onContentError : function(errorMessage) {},
	onContentPlayHead : function() {},
	onContentStop : function(videoId) {},
	onContentPause : function(videoId, paused) {},
	onContentCompleted : function() {},

	/************************
	    Tracking callbacks
	 ************************/
	onVideoTrackingAdClick : function(videoId, url) {},
	onVideoTrackingProgress : function(videoId, percent) {},
	onVideoTrackingLifetime : function(seconds) {},
	onVideoTrackingFullscreen : function(videoId, fullscreen) {},
	onVideoTrackingMuted : function(videoId, muted) {},
	onVideoTrackingPaused : function(videoId, paused) {},
	onVideoTrackingCompleted : function(videoId) {},
	onVideoTrackingReplay : function(videoId) {},
	onVideoTrackingPlay : function(videoId) {},
	onContentTrackingAdCountdown : function(secs) {}
}

