var vtkTrackVid={};
vtkTrackVid.counters={};
vtkTrackVid.counters.Start=false;
vtkTrackVid.counters.Sec30=false;
vtkTrackVid.counters.Sec60=false;
vtkTrackVid.counters.MidPoint=false;
vtkTrackVid.counters.Finish=false;
vtkTrackVid.counters.addCuepoint=false;

// ywa has no cf assigned for clip url
// use cf lookup of event id to find clip url - path to s3 to locate it

vtkTrackVid.start = function(clip) {
	
		var siteurl = document.location;
		var tsecs = clip.duration;
		var cfTime= Math.ceil((tsecs/60));

		var YWATracker = YWA.getTracker("10002108629376");

		YWATracker.setDocumentName('Vid-Start: '+ clip.vtkDescName+" "+ clip.vtkChan);
		YWATracker.setDocumentGroup("VideoLaunches - GSS"); 
		
		clip.vtkType=clip.vtkType.toLowerCase();

		if(clip.vtkType === 'showcase') {
			YWATracker.setAction('10;05');
		}

		if(clip.vtkType === 'feature') {
			YWATracker.setAction('11;05');
		}

		if(clip.vtkType === 'exhibit-hall') {
			YWATracker.setAction('12;05');
		}

		if(clip.vtkType === 'preroll') {
			YWATracker.setAction('13;05');
		}

		if(clip.vtkType === 'instream') {
			YWATracker.setAction('14;05');
		}

		if(clip.vtkType === 'postroll') {
			YWATracker.setAction('15;05');
		}

		if(clip.vtkType === 'premium') {
			YWATracker.setAction('16;05');
		}
		
		if(clip.vtkType === 'buyerguide') {
		        YWATracker.setAction('18;05');
		}

		if(clip.vtkType === 'live') {
			YWATracker.setAction('17;05');
		}

		if(clip.vtkDescName !== '') {
			YWATracker.setCF(18,clip.vtkDescName);
		}

		if(clip.vtkEventId !== '') {
			YWATracker.setCF(30,clip.vtkEventId);
		}

		if(clip.vtkShortName !== '') {
			YWATracker.setCF(26,clip.vtkShortName);
		}

		if(clip.vtkClientId !== '') {
			YWATracker.setCF(27,clip.vtkClientId);
		}

		YWATracker.setCF(17,siteurl);
		YWATracker.setCF(29,cfTime);

		if(clip.vtkType !== '') {
			YWATracker.setCF(21,clip.vtkType);
		}

		if(clip.vtkClient !== '') {
			YWATracker.setCF(20,clip.vtkClient);
		}

		if(clip.vtkTheme !== '') {
			YWATracker.setCF(19,clip.vtkTheme);
		}

		if(clip.vtkChan !== '') {
			YWATracker.setCF(28,clip.vtkChan);
		}

		YWATracker.submit();

		
		return this;
	

};


vtkTrackVid.finish = function(clip) {


		var vidFinish = YWA.getTracker("10002108629376");
		vidFinish.setCF(25,'Finished: '+clip.vtkDescName);
		vidFinish.setAction('09');
		vidFinish.submit_action();

	

		return this;
	
};



vtkTrackVid.cuepoint = function(clip,cuepoint) {


	var YWATracker = YWA.getTracker("10002108629376");
	var clipTime= cuepoint/1000;
	var midpoint = Math.floor((clip.duration*0.50)*1000);
	var cuepointLiveSec = cuepoint;

        // alert("clip midpoint should be :" + midpoint)
                       
        // alert (" Live cuepoint received is : " + cuepointLiveSec);


	if(clipTime === 30 && vtkTrackVid.counters.Sec30 === false) {
		YWATracker.setCF(22,'30sec: '+clip.vtkDescName);
		YWATracker.setAction('06');
		YWATracker.submit_action();
	
		return this;
	}

	if(clipTime === 60 && vtkTrackVid.counters.Sec60 === false) {
		YWATracker.setAction('07');
		YWATracker.setCF(23,'60sec: '+clip.vtkDescName);
		YWATracker.submit_action();

		return this;
	}

	

	if(cuepointLiveSec === midpoint) { // 50% mark cuepoint

	              // alert("we are about to post Midpoint");
				
			YWATracker.setAction('08');
			YWATracker.setCF(24,'MidPoint: '+clip.vtkDescName);
			YWATracker.submit_action();
	

			return this;

	}

	return this;  


};

//	Set a cuepoint on the current flowplayer instance
function setMidpointCuePoint (clip,midpoint){
	$f().onCuepoint(midpoint,function() {vtkTrackVid.cuepoint(clip,midpoint)} );
	return this;
}
