// JScript source code

/* VX Video Tracking Object
 * Copyright ROO Media Corporation
 * Author: Kevin Williams & Ramyar Jafarkhani
 */

function VXVidTracker (siteId) 
{
	//Object vars/properties
	this.SiteId=siteId;
	this.ClipId="";
	this.Title="";
	this.Channel="";
	this.Description="";
	this.Duration=0;
	this.PctViewed=0;
	this.CurrentPosition=0;
	this.Type="Video"
	this.PlayState=0;
	this.Action="";
	this.Url="";
	this.PreRoll=null;
	this.Previous=null;

	
	this.Clone = function(){
		var tracker = new VXVidTracker(this.siteId);
		
		tracker.ClipId=this.ClipId;
		tracker.Title=this.Title;
		tracker.Channel=this.Channel;
		tracker.Description=this.Description;
		tracker.Duration=this.Duration;
		tracker.PctViewed=this.PctViewed;
		tracker.CurrentPosition=this.Position;
		tracker.Type=this.Type;
		tracker.PlayState=this.PlayState;
		tracker.Action=this.Action;
		tracker.Url=this.Url;
		tracker.PreRoll=this.PreRoll;
		return tracker;
		
	}
	
	//Updates copies current tracker object and preroll if switching from ad to video then sets new values
	this.Update = function(clipId, title, channel, description, duration, pctViewed, currentPosition, type, playState, action,clipurl,isPctDurationUpdate){
		
		//Update only Duration if clip is interrupted during play.
		
		if(isPctDurationUpdate == 'Y')
			this.PctViewed = pctViewed;
		else
		{
			this.Previous = this.Clone();
			//Clone current value and save in previous
			
			//If we have switched from an ad to a video then set preroll = previous as well
			if(this.Type=="Ad" && type=="Video")
				this.PreRoll = this.Previous;
			//else
			//Commented because setting PreRoll to null will set Ad to null if Video clip is played till the end.
			//	this.PreRoll = null; 
			
			//Now set values -- need to add error handling
			
			this.ClipId = clipId;
			this.Title = title;
			this.Channel = channel;
			this.Description = description;
			this.Duration = duration;
			this.PctViewed = pctViewed;
			this.CurrentPosition = currentPosition;
			this.Type = type;
			this.PlayState = playState;
			this.Action = action;
			this.Url = clipurl;
		}
					
	}
	
}

//Create prototype for VXVidTrackingPublisher
function VXVidTrackingPublisher(aValue){this.mValue = aValue;inheritFrom(this, new CSimpleObservable());}
VXVidTrackingPublisher.prototype.get = function(){  return this.mValue;}
VXVidTrackingPublisher.prototype.set = function(aValue){  this.mValue = aValue;  this.notify(this);}