
window.RWS.video = function(id, src, cfg) {

	var make_player = function(id, src, cfg) {

		var tmpl = '<div class="video-js-box"> \
	<video class="video-js" width="${Width}" height="${Height}" controls="controls" ${vautoPlay}> \
		<source src="${Source_MP4}" type=\'video/mp4\' /> \
		<object class="vjs-flash-fallback" width="${Width}" height="${Height}" type="application/x-shockwave-flash" data="/scripts/flowplayer/flowplayer-3.2.7.swf"> \
			<param name="movie" value="/scripts/flowplayer/flowplayer-3.2.7.swf" /> \
			<param name="allowfullscreen" value="true" /> \
			<param name="flashvars" value=\'config={"clip":{"url":"${Source_MP4}","autoPlay":${autoPlay},"autoBuffering":true}}\' /> \
		</object> \
	</video> \
	<!-- \
	<p class="vjs-no-video"><strong>Download Video:</strong> \
		<a href="${Source_MP4}">MP4</a><br /> \
		<a href="http://videojs.com">HTML5 Video Player</a> by VideoJS \
	</p> \
	--> \
</div>';

		var autoPlay = "false";
		var vautoPlay = '';

		if(typeof cfg.autoPlay != "undefined") {
			autoPlay = cfg.autoPlay ? "true" : "false";

			if(cfg.autoPlay) {
				vautoPlay = 'autoplay="autoplay"';
			}
		}

		var $tgt = jQuery("#" + id);

		tmpl = tmpl.replace(/\$\{Width\}/gm, $tgt.innerWidth());
		tmpl = tmpl.replace(/\$\{Height\}/gm, $tgt.innerHeight());	
		tmpl = tmpl.replace(/\$\{Source_MP4\}/gm, src);
		tmpl = tmpl.replace(/\$\{autoPlay\}/gm, autoPlay);
		tmpl = tmpl.replace(/\$\{vautoPlay\}/gm, vautoPlay);
		$tgt.html(tmpl);

		jQuery("video", $tgt)[0].load();

	};

	if(typeof window.VideoJS == "undefined") {

		if(document.createStyleSheet) {
			document.createStyleSheet("/scripts/videojs/video-js.css");
		} else {
			jQuery('head').append('<link rel="stylesheet" href="/scripts/videojs/video-js.css" type="text/css" />');
		}

		jQuery.ajax({
			type: "GET",
			url: '/scripts/videojs/video.js',
			cache: true,
			dataType: 'script',
			success: function(data, status) {

				make_player(id, src, cfg);

			}
		});

	} else {

		make_player(id, src, cfg);

	}	

};

