﻿// Returns the appropriate Flowplayer key depending on the current domain
var playingVideo;
function GetJssFlowplayerKey() {
	var key = '';
	var currentDomain = window.location.host;
	if (currentDomain.indexOf('localhost') != -1) {
		key = '#@d120d7af4975dee766a';
	} else if (currentDomain.indexOf('jointservicessupport.org') != -1) {
		key = '#@b1cde6a5fd600568088';
	}

	return key;
}

// Create a Flowplayer with JSS branding and skinning
// containerId - ID of element to add player to
// videoUrl - URL of video to play
// autoplay - whether to play the video as soon as it loads, defaults to false if left empty
function CreateJssFlowplayer(containerId, videoUrl, autoplay, eventCategory, onStart, onFinish, onStop) {
	// If autoplay is undefined, set it to false
	autoplay = typeof (autoplay) != 'undefined' ? autoplay : false;
	
	// if no category specified, use "Uncategorized"
	eventCategory = typeof (eventCategory) != 'undefined' ? eventCategory : "Uncategorized";

	onStart = typeof (onStart) != 'undefined' ? onStart : function () { void(0); };
	onFinish = typeof (onFinish) != 'undefined' ? onFinish : function () { void (0); };
	onStop = typeof (onStop) != 'undefined' ? onStop : function () { void (0); };
    
	var licenseKey = GetJssFlowplayerKey();

	playingVideo = flowplayer(
		containerId,
		{
			src: "/SharedClasses/flowplayer/flowplayer.commercial-3.2.7.swf", wmode: "opaque"
		},
		{
			screen: {
				bottom: 0	// make the video take all the height
			},
			// commercial version requires a product key
			key: licenseKey, 
			clip: {
				autoPlay: autoplay,
				autoBuffering: true,
				url: videoUrl,
				eventCategory: eventCategory,
                onStart: onStart,
                onFinish: onFinish,
                onStop: onStop
			},
			// Custom branding, requires commercial version
			// custom play button
			play: {
				url: '/SharedClasses/Flowplayer/play.swf',
				width: 140,
				height: 140
			},
			logo: {
				url: '/SharedClasses/Flowplayer/logo.swf',
				bottom: 0,
				left: 20,
				opacity: 0.4,

				// for SWF-based logos you can supply a relative size (to make the logo larger in fullscreen)
				width: 75,
				//height: 100,
				// if set to false, then the logo is also shown in non-fullscreen mode
				fullscreenOnly: false,

				// time to display logo (in seconds). 0 = show forever
				displayTime: 10,

				//if displayTime > 0 then this specifies the time it will take for
				//the logo to fade out. this happens internally by changing the opacity
				//property from its initial value to full transparency.
				//value is given in milliseconds.

				fadeSpeed: 10
			},
			// Setup colour scheme
			plugins: {
				gatracker: {
					url: "/SharedClasses/Flowplayer/flowplayer.analytics-3.2.2.swf",
					// track all possible events. By default only Start and Stop 
					// are tracked with their corresponding playhead time.
					events: {
					    all: true,
					    finish: "Finish"
					    
					},
					/*debug: true,*/
					accountId: "UA-9152698-1" // your Google Analytics id here
				},
				controls: {
					url: '/SharedClasses/Flowplayer/flowplayer.controls-3.2.5.swf',
					autoHide: "always",
					timeColor:"#ffffff",
					borderRadius:"0px",
					buttonOffColor:"rgba(130,130,130,1)",
					bufferGradient:"none",
					borderColor:"rgba(124, 72, 155, 0.15)",
					zIndex:1,
					sliderColor:"#000000",
					backgroundColor:"transparent",
					scrubberHeightRatio:0.6,
					volumeSliderGradient:"none",
					tooltipTextColor:"#ffffff",
					sliderGradient:"none",
					spacing:{"time":6,"volume":8,"all":2},
					timeBorderRadius:20,
					timeBgHeightRatio:0.8,
					volumeSliderHeightRatio:0.6,
					progressGradient:"none",
					height:26,
					volumeColor:"rgba(124, 72, 155, 1)",
					timeSeparator:" ",
					tooltips:{"marginBottom":5,"buttons":false},
					name:"controls",
					volumeBarHeightRatio:0.2,
					opacity:1,
					left:"50pct",
					timeFontSize:12,
					tooltipColor:"rgba(0, 0, 0, 0)",
					border:"0px",
					volumeSliderColor:"#ffffff",
					bufferColor:"rgba(153, 190, 61, 1)",
					buttonColor:"#ffffff",
					durationColor:"rgba(153, 190, 61, 1)",
					//autoHide:{enabled:true,hideDelay:500,mouseOutDelay:500,hideStyle:"fade",hideDuration:400,fullscreenOnly:true},
					backgroundGradient:"none",
					width:"100pct",
					sliderBorder:"1px solid rgba(128, 128, 128, 0.7)",
					display:"block",
					buttonOverColor:"#ffffff",
					progressColor:"rgba(124, 72, 155, 1)",
					timeBorder:"0px solid rgba(0, 0, 0, 0.3)",
					timeBgColor:"rgb(0, 0, 0, 0)",
					scrubberBarHeightRatio:0.2,"bottom":0,
					volumeBorder:"1px solid rgba(128, 128, 128, 0.7)",
					builtIn:false,
					margins:[2,12,2,12]
				}
			}
	});
}

