﻿function silverlightEvent(mediaName, eventName, eventArg) {
	if (eventName == 'SocialMediaLinkClicked') shareClickHandler(eventArg);
	else mediaEventHandler(mediaName, eventName, eventArg, true);
}

function wmpEvent(newState) {
	var videoPos = Math.round(player.Wmp.getCurrentPosition());
	var videoLength = Math.round(player.Wmp.getDuration());
	var currentMediaName = player.Data.getCurrentMediaName();
	switch (newState) {
		case 1:
			var fireEvent = player.Wmp._isVideoStarted;
			player.Wmp._isVideoStarted = false;
			if (fireEvent) {
				// stopped code here
			}
			break;
		case 2:
			// paused code here
			break;
		case 3:
			// playing code here
			if (!player.Wmp._isVideoStarted) {
				player.Wmp._isVideoStarted = true;
				// started code here
				mediaEventHandler(currentMediaName, 'MediaStarted', videoLength, false);
			}
			break;
		case 8:
			this._isVideoStarted = false;
			// ended code here
			mediaEventHandler(currentMediaName, 'MediaEnded', videoLength, false);
			break;
	}
}

function shareClickHandler(shareKey) {
	
}

function mediaEventHandler(mediaName, eventName, eventArgs, isSilverlight) {
	var omnitureName = null, atlasStart = null, atlasEnd = null;
	switch (mediaName) {
		case 'overview':
			omnitureName = 'IE8_EV_Overview';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationaloverview_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationalvideooverview_end';
			break;
		case 'accelerators':
			omnitureName = 'IE8_EV_Accelerators';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationalaccelerators_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationalaccelerators_end';
			break;
		case 'howto_compatibility':
			omnitureName = 'IE8_EV_Compatibility';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationalcompatibility_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationalcompatibility_end';
			break;
		case 'howto_browsing':
			omnitureName = 'IE8_EV_EasierBrowsing';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationaleasierbrowsing_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationaleasierbrowsing_end';
			break;
		case 'sizzle':
			omnitureName = 'IE8_EV_FasterEasierSafer';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationalfastereasiersafer_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationalfastereasiersafer_end';
			break;
		case 'webslices':
			omnitureName = 'IE8_EV_Webslices';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationalwebslices_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationalwebslices_end';
			break;
		case 'security_howto':
			omnitureName = 'IE8_EV_SecurityPrivacy';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_educationalsecurityprivacy_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_educationalsecurityprivacy_end';
			break;
		case 'friends':
			omnitureName = 'IE8_SV_ConnectFriends';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_scenarioconnectwithfriends_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_scenarioconnectwithfriends_end';
			break;
		case 'music':
			omnitureName = 'IE8_SV_MusicEntertainment';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_scenariomusicentertainment_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_scenariomusicentertainment_end';
			break;
		case 'finance':
			omnitureName = 'IE8_SV_PersonalFinance';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_scenariopersonalfinance_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_scenariopersonalfinance_end';
			break;
		case 'ebay':
			omnitureName = 'IE8_PV_Ebay';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_partnerebay_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_partnerebay_end';
			break;
		case 'medium':
			omnitureName = 'IE8_PV_Medium';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_partnermedium_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_partnermedium_end';
			break;
		case 'stumble_upon':
			omnitureName = 'IE8_PV_Stumbleupon';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_partnerstumbleupon_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_partnerstumbleupon_end';
			break;
		case 'live':
			omnitureName = 'IE8_PV_LiveSearch';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_partnerwindowslivesearch_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_partnerwindowslivesearch_end';
			break;
		case 'IE8_Perf_Test2':
			omnitureName = 'IE8_CSV_PerformanceTesting';
			atlasStart = 'http://view.atdmt.com/action/asc_IE8_casestudyperformancetesting_start';
			atlasEnd = 'http://view.atdmt.com/action/asc_IE8_casestudyperformancetesting_end';
			break;
	}
	if (omnitureName && atlasStart && atlasEnd)
		fireVideoTrackingCalls(eventName, eventArgs, isSilverlight, omnitureName, atlasStart, atlasEnd);
}

function fireVideoTrackingCalls(eventName, eventArgs, isSilverlight, omnitureName, atlasStart, atlasEnd) {
	switch (eventName) {
		case 'MediaStarted':
			var duration = eventArgs.toString();
			CreateAtlasImage(atlasStart);
			videoStart(omnitureName, '', duration, isSilverlight);
			break;
		case 'MediaEnded':
			CreateAtlasImage(atlasEnd);
			videoCompleted(omnitureName);
			break;
	}
}