var players = [];
cvpFlashVars.player = 'main'+cvpPlayerTest;

//define player config
var cvpStory = {
	flashVars: {},
	embed: {
		containerSwf : cvpContainerSwf
	},
	
	onPlayerReady: function() {
		var storyAdSection = (tourFreeWheelBaseSiteSection != '')?tourFreeWheelBaseSiteSection : 'pgatour.com_pgatour_news';	//default to pgatour.com_pgatour_news if empty string
		
		if(this.getWidth() == '640') {	//hate this hack.  should check player instance, but it seems to always be 'inline' if there is a T1 and an inline in the page at the same time
			storyAdSection += '_t1';
		} else {
			storyAdSection += '_inpage';
		}
		
		this.setAdSection(storyAdSection);
	},
	
	onContentPlay: function() {
		/* omniture video start */
		try {
			var vdata = cvpStory.getContentEntry(cvpStory.getContentId());
			var currVidObj = _w.JSON.parse(vdata);
			trackMetrics({
				type: "video-start",
				data: {
					video : {
						title: currVidObj.headline,
						id: currVidObj.id
					}
				}
			});
		} catch(e){}
	},
	
	onAdStarted: function(token) {
		/* omniture ad pre-roll */
		try {
			var vdata = cvpStory.getContentEntry(cvpStory.getContentId());
			var currVidObj = _w.JSON.parse(vdata);
			trackMetrics({
				type: "video-preroll",
				data: {
					video : {
						title: currVidObj.headline,
						id: currVidObj.id
					}
				}
			});
		} catch(e){};
	},
	
	onContentCompleted : function() { 
		/* omniture video complete */
		try {
			var vdata = cvpStory.getContentEntry(cvpStory.getContentId());
			var currVidObj = _w.JSON.parse(vdata);
			trackMetrics({
				type: "video-complete",
				data: {
					video : {
						title: currVidObj.headline,
						id: currVidObj.id
					}
				}
			});
		} catch(e){}
	},
	
	onContentPause : function(videoId, paused) {
		/* omniture video pause */
		try {
			trackMetrics({
				type: "video-pause",
				data: { }
			});
		} catch(e){}
	}
};

Event.observe(window, 'load', function() {
	var len = players.length;
	
	//loop over players and embed in page
	for (var i=0; i<=len-1; i++) {
		var pInstance = players[i].player;
		
		cvpStory.id = 'cvp_'+i;
		cvpFlashVars.contentId = players[i].playlist[0].url;
		cvpFlashVars.player = pInstance;
		
		cvpStory.flashVars = cvpFlashVars;
		
		$(players[i].divId+'Headline').update(players[i].playlist[0].headline);
		$(players[i].divId+'Desc').update(players[i].playlist[0].description);
		
		if(pInstance == 'main' || pInstance == '640x360_no_autostart') {	//set player size based on player instance
			cvpStory.width = '640';
			cvpStory.height = '360';
		} else {
			cvpStory.width = '288';
			cvpStory.height = '162';
		}
		
		window['player_'+i] = new CVP(cvpStory);
		window['player_'+i].embedSWF(players[i].divId);
	}
});

