window.flowplayerSWF = '/js/flowplayer/flowplayer.commercial-3.2.7.swf';
window.flowplayerAudioSWF = '/js/flowplayer/flowplayer.audio-3.2.2.swf';
window.flowplayerCanvas = {};
/*
window.gaTracker = {
	url: '/js/flowplayer/flowplayer.analytics-3.2.2.swf',
	events: {
		all: true
	},
	debug: false,
	accountId: 'UA-20349636-1'
};
*/
startFlowplayer = function (fDiv, fSWFPlayer, fClip, fOnStart, fOnFinish, fVideoID) {
	if (fSWFPlayer == '' || fSWFPlayer == undefined) {
		fSWFPlayer = '/js/flowplayer/flowplayer.commercial-3.2.7.swf';
	}

	if (fVideoID == undefined) {
		fVideoID = 0;
	}

	fPlayer = flowplayer(fDiv, {
		src: fSWFPlayer,
		wmode: 'transparent'
	}, {
		key: '#@46c198329c8bd3039f8',
		logo: {
			url: '/images/flowplayer.logo.png',
			bottom: 50,
			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);
				flowplayerTracker(fVideoID);
			},
			onFinish: function () {
				fOnFinish();
			}
		},

		canvas: window.flowplayerCanvas,
		onLoad: function () {
			this.unmute();
			this.setVolume(100);
		},
		onError: function (errorCode, errorMessage) {
			//alert(errorCode + '\n' + errorMessage);
		}

	}).ipad();
	fPlayer.load();
};

jQuery(function () {
	initEmbededFlowPlayers();
});

function initEmbededFlowPlayers() {
	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 = jQuery(this).attr('swfplayer');
		fVideoID = jQuery(this).attr('video-id');
		if (fVideoID == undefined || fVideoID == '') {
			fVideoID = 0;
		}

		fControls = jQuery(this).attr('controls');
		if (fControls == '' || fControls == undefined || fControls == 'true') {
			fControls = true;
		}

		if (fControls == true) {
			fControlsObj = {}
		} else {
			fControlsObj = { controls: null }
		}

		fType = jQuery(this).attr('type');
		if (fType == undefined || fType == '') {
			fType = 'video';
		}

		if (fType == 'audio') {
			fControlsObj = {
				audio: {
					url: '/js/flowplayer/flowplayer.audio-3.2.2.swf'
				}
			}
		}

		fPlayer = flowplayer(fDiv, fSWFPlayer, {
			key: fKey,
			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);
				},
				onBeforeFinish: function () {
					return false;
				},
				onFinish: function () {
				}
			},

			plugins: fControlsObj,

			onLoad: function () {
				this.unmute();
				this.setVolume(100);
				if (fAutoPlay == true) {
					this.play();
				}
			}

		}).ipad();
		fPlayer.load();

		jQuery(this).removeClass('embededFlowPlayer');
	});
}

function flowplayerTracker(fID) {

}
