function omniVideoOnLoad () {
	s.Media.autoTrack = false;
	s.Media.playerName = "FTP Demo Video Player";
	s.eVar7 = s.pageName;  // sourcepage
	s.Media.trackVars = "events,pageName,eVar6,eVar7";
	s.Media.trackEvents = "event5,event6";
	OnWMPLoad();
}

function OnWMPLoad() {
    if (window.document && document.body) {
        var wmp = document.getElementById('contentPlayer');
        if (wmp) {
            if (window.attachEvent) {
                wmp.attachEvent('PlayStateChange', OnWMPStateChange);
            }
            else if (window.addEventListener) {
                wmp.addEventListener('PlayStateChange', OnWMPStateChange, false);
            }
        }
    }
    else {
        setTimeout(function() { OnWMPLoad(); } , 10);
    }
}

var hasFiredStop = false,
    hasFiredStart = false;
function OnWMPStateChange(state) {
    switch(state)
    {
        case 1: // Stop
            if (hasFiredStop) return;
            hasFiredStop = true;
            WL.eventHandler.trigger('scVideoEnd');
            break;
        case 2: // Pause
            break;
        case 3: // Playing
            if (hasFiredStart) return;
            hasFiredStart = true;
            WL.eventHandler.trigger('scVideoStart');
            break;
    }
};

if (window.AllowVideoTrack === undefined) window.AllowVideoTrack = true;

// videoMode - corresponds to the mode under which the video was played, i.e. single video, three video list, browse, browse with categories
// mediaName - The name of the media item as it will appear in reports.
// mediaLength - The length of the media item in seconds
function videoStart(mediaName, videoMode, mediaLength) {
    if (!window.AllowVideoTrack) return;
    window._wlCurrentMedia = s.prop4 = s.eVar4 = mediaName;
    WL.eventHandler.trigger('scVideoStart');
    //last minute solution - media player tracking not working as it should
    var atlasClassName;
    switch (mediaName) {
        case 'See Windows Live in Action':
            atlasClassName = 'atHowItWorksVideoStart';
            break;
        case 'Share Memories':
            atlasClassName = 'atShareMemoriesVideoStart';
            break;
        case 'Work from Anywhere':
            atlasClassName = 'atWorkAnywhereVideoStart';
            break;
    }
    if (atlasClassName) WL.Atlas.TriggerEvent(atlasClassName);
    /*
	s.events = "event5";
	var oldltvars = s.linkTrackVars;
	var oldltevts = s.linkTrackEvents;
	s.linkTrackEvents = "event5";
	s.linkTrackVars = "prop6,prop8,prop9,eVar6,eVar7,eVar8,eVar9,events";
	s.prop6 = mediaName;
	s.eVar8 = s.prop8 = "silverlight";  
	s.eVar9 = s.prop9 = videoMode;  
	s.tl( true, "o", "Video Start" ); 
	s.linkTrackEvents = oldltevts;
	s.linkTrackVars = oldltvars;
	
	var durationParts = mediaLength.split(":");
	var seconds = parseInt(durationParts[0] * 60) + parseInt(durationParts[1]);

	s.Media.open( mediaName, seconds, "DemoVideoPlayer" );
	s.Media.play( mediaName, 0 );
	*/
}

// mediaName - The name of the media item as it will appear in reports.
// mediaOffset - The seconds into the media item that play begins. The offset is a zero based number.
function videoPause(mediaName, mediaOffset) {
    if (!window.AllowVideoTrack) return;
	s.Media.stop( mediaName, mediaOffset );
}

// mediaName - The name of the media item as it will appear in reports.
// mediaOffset - The seconds into the media item that play begins. The offset is a zero based number.
function videoStop(mediaName, mediaOffset) {
    if (!window.AllowVideoTrack) return;
    s.prop4 = s.eVar4 = (mediaName || window._wlCurrentMedia);
    s.Media.stop(mediaName, mediaOffset);
    WL.eventHandler.trigger('scVideoEnd');
    if (mediaName == 'See Windows Live in Action') WL.Atlas.TriggerEvent('atHowItWorksVideoEnd');
}

// mediaName - The name of the media item as it will appear in reports.
function videoCompleted(mediaName) {
    if (!window.AllowVideoTrack) return;
    WL.eventHandler.trigger('scVideoEnd');
    //last minute solution - for How It Works video only
    if (mediaName == 'See Windows Live in Action') WL.Atlas.TriggerEvent('atHowItWorksVideoEnd');
    /*
	s.Media.trackEvents = "event6";
	s.events = "event6";
	s.Media.close(mediaName);
	*/
}

// mediaName - The name of the media item as it will appear in reports.
function sendToAFriend ( mediaName ) {
	var oldltvars = s.linkTrackVars;
	s.linkTrackVars = "prop13,prop15,prop16";
	s.prop13 = "Video"; // CM
	s.prop15 = mediaName;  // CE,   use the name of the video here
	s.prop16 = "Video: Send to a Friend";  // HL
	s.tl( true, "o", "Video: Send to a Friend" );
	s.linkTrackVars = oldltvars;
}

// clickEvent - corresponds to the Link Text prefixed with "Video: " (i.e. "Video: Play Video Again")
function otherClickEvent ( clickEvent ) {
	var oldltvars = s.linkTrackVars;
	var oldltevts = s.linkTrackEvents;
	s.linkTrackVars = "prop13,prop16";
	s.prop13 = "Video"; // CM
	s.prop16 = clickEvent;
	s.tl( true, "o", clickEvent );
	s.linkTrackEvents = oldltevts;
	s.linkTrackVars = oldltvars;
}
