window.gaTracker = {
	url: '/js/flowplayer/flowplayer.analytics-3.2.2.swf',
	events: {
		all: true
	},
	debug: false,
	accountId: 'UA-23180800-1'
};
window.flowPlayerSWF = '/js/flowplayer/flowplayer.commercial-3.2.7.swf';
window.flowPlayerKey = '#@02351015a880a4c43c9';

function startFlowplayer(fDiv, fSWFPlayer, fClip, fOnStart, fOnFinish, fName) {
	if (fName == undefined) {
		fName = fClip;
	}

	fPlayer = flowplayer(fDiv, window.flowPlayerSWF, {
		key: window.flowPlayerKey,
		logo: {
			url: '/images/flowplayer.logo.png',
			bottom: 30,
			left: 30,
			opacity: 1,
			fullscreenOnly: false
		},
		onMouseOver: function () {
			this.getPlugin("logo").fadeTo(0.5, 1000);
		},

		onMouseOut: function () {
			this.getPlugin("logo").fadeTo(0, 1000);
		},

		clip: {
			autoPlay: true,
			autoBuffering: true,
			url: fClip + '',
			onStart: function (clip) {
				var clipwidth = clip.metaData.width;
				var clipheight = clip.metaData.height;
				this.getPlugin("logo").fadeTo(0, 8000);
				fOnStart(clip, clipwidth, clipheight);
			},
			onFinish: function () {
				fOnFinish();
			},
			eventCategory: 'Video: ' + fName
		},
		plugins: {
			gatracker: window.gaTracker
		},
		onLoad: function () {
			this.unmute();
			this.setVolume(100);
		},
		onError: function (errorCode, errorMessage) {
			//alert(errorCode + '\n' + errorMessage);
		}

	}).ipad({
		'simulateiDevice': false
	});
	fPlayer.load();
}


jQuery(function () {
	cnt = 0;
	jQuery('.embededFlowPlayer').each(function () {
		cnt++;
		fDiv = jQuery(this).attr('id');
		if (fDiv == '') {
			fDiv = 'lfajsldfj' + cnt;
			jQuery(this).attr('id', fDiv);
		}
		fClip = jQuery(this).attr('href');

		fAutoPlay = jQuery(this).attr('autoplay');
		if (fAutoPlay == 'true' || fAutoPlay == true) {
			fAutoPlay = true;
		} else {
			fAutoPlay = false;
		}

		fLoop = jQuery(this).attr('loop');
		if (fLoop == 'true') {
			fLoop = true;
		} else {
			fLoop = false;
		}

		fKey = jQuery(this).attr('key');
		fSWFPlayer = window.flowPlayerSWF;
		fVideoID = jQuery(this).attr('video-id');
		if (fVideoID == undefined || fVideoID == '') {
			fVideoID = 0;
		}

		fName = jQuery(this).attr('video-name');
		if (fName == undefined || fName == '') {
			fName = 'ID: ' + fVideoID;
		}

		fPlayer = flowplayer(fDiv, fSWFPlayer, {
			key: window.flowPlayerKey,
			logo: {
				url: '/images/flowplayer.logo.png',
				bottom: 20,
				left: 30,
				opacity: 1,
				fullscreenOnly: false
			},

			onMouseOver: function () {
				this.getPlugin("logo").fadeTo(0.5, 1000);
			},

			onMouseOut: function () {
				this.getPlugin("logo").fadeTo(0, 1000);
			},
			clip: {
				autoPlay: fAutoPlay,
				autoBuffering: true,
				url: fClip,
				loop: fLoop,
				onStart: function (clip) {
					var clipwidth = clip.metaData.width;
					var clipheight = clip.metaData.height;
					this.getPlugin("logo").fadeTo(0, 8000);
					fOnStart(clip, clipwidth, clipheight);
					flowplayerTracker(fVideoID);
				},
				eventCategory: 'Video: ' + fName,

				onBeforeFinish: function () {
					return false;
				},
				onFinish: function () {
				}
			},

			plugins: {
				gatracker: window.gaTracker
			},

			onLoad: function () {
				this.unmute();
				this.setVolume(100);
				if (fAutoPlay == true) {
					this.play();
				}
			}

		}).ipad();
		fPlayer.load();
	});
});

function flowplayerTracker(fID) {
	if (fID == undefined || fID == '') {
		fID = 0;
	}
	if (jQuery('#flowplayer-iframe').length == 0) {
		jQuery('body').append('<iframe id="flowplayer-iframe" name="flowplayer-iframe" width="1" height="1" frameborder="0" style="display: none"></iframe>');
	}
	window.open('/net/remote/sitepages/public/?action=video-play&linkid=' + fID, 'flowplayer-iframe');
}
