/**
 * @singleton
 * @classDescription To be a universal way of playing flv's on websites, rather than creating a .fla for each video that needs to be played.
 * I:
 * 	- Attach a flv to the desired location
 *  - Play a flv based on attributes passed in
 *  
 * @author georgeh
 * @since 2008-11-24
 */
/**
 * @require AC_RunActiveContent.js, any valid skin swf, matching flv player swf
 */
 
 /** usage:
 
 	<script type="text/javascript" src="/js/FlvPlayer.js" language="javascript"></script>
	<script type="text/javascript" language="javascript">
		FlvPlayer.attachVideo({
			width: number,
			height: number,
			skinHeight: number,
			skin: "string to skin (include extension)",
			flvSrc: "string to flv (include extension)"
			autoPlay: true / false (no quotes),
			autoSize: true / false (no quotes),
			maintainAspectRatio: true / false (no quotes),
			skinAutoHide: true / false (no quotes),
			swfPath: "path to flvPlayer.swf" (do not include .swf extension)
		});
	</script> 
 **/

var FlvPlayer = new function() {
	return {
		attachVideo: function(parameters) {
			
			var swf = {
				width: 320,
				height: 240,
				path: "/swf/flvPlayer"
			}
			
			var video = {
				width: 320,
				height: 240
			}
			
			var flashVars = "?";
			flashVars += "flvSrc=" + parameters.flvSrc;
			
			if(typeof parameters.width == "number") {
				flashVars += "&width=" + parameters.width;
				video.width = parameters.width;
			}
			
			if(typeof parameters.height == "number") {
				flashVars += "&height=" + parameters.height;
				video.height = parameters.height;
			}
			
			if(typeof parameters.skin == "string") {
				flashVars += "&skin=" + parameters.skin;
			}
			
			if(typeof parameters.swfPath == "string") {
				swf.path = parameters.swfPath;
			}
			
			if(typeof parameters.autoPlay == "boolean") {
				flashVars += "&autoPlay=" + parameters.autoPlay;
			}
			
			if(typeof parameters.autoSize == "boolean") {
				flashVars += "&autoSize=" + parameters.autoSize;
			}
			
			if(typeof parameters.maintainAspectRatio == "boolean") {
				flashVars += "&maintainAspectRatio=" + parameters.maintainAspectRatio;
			}
			
			if(typeof parameters.skinAutoHide == "boolean") {
				flashVars += "&skinAutoHide=" + parameters.skinAutoHide;
			}
			
			swf.width = video.width;
			swf.height = video.height;
			
			if(typeof parameters.skinHeight == "number") {
				swf.height += parameters.skinHeight;
			}
			
			var hasCorrectFlashVersion = DetectFlashVer(8,0,0);
			if(hasCorrectFlashVersion) {
				AC_FL_RunContent(
					'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
					'width', swf.width,
					'height', swf.height,
					'src', swf.path+flashVars,
					'quality', 'high',
					'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
					'align', 'middle',
					'play', 'true',
					'loop', 'true',
					'scale', 'showall',
					'wmode', 'transparent',
					'devicefont', 'false',
					'id', 'FlvPlayer',
					'bgcolor', '#ffffff',
					'name', 'FlvPlayer',
					'menu', 'true',
					'allowFullScreen', 'false',
					'allowScriptAccess','sameDomain',
					'movie', swf.path+flashVars,
					'salign', ''
				);
			} else {
				if(typeof parameters.noFlashImg == "string") {
					document.write('<a href="http://get.adobe.com/flashplayer/" target="_blank"><img src="'+parameters.noFlashImg+'" alt="" /></a>')
				} else {
					if(typeof parameters.noFlashText == "string") {
						document.write(parameters.noFlashText);
					} else {
						document.write('<div style="width: '+swf.width+'px;"><strong>We\'re sorry, but you need at least flash player 8 to properly view this video.</strong><br />Please <a href="http://get.adobe.com/flashplayer/" target="_blank">click here</a> to download and install it.</div>')
					}
				}
			}
		}
	};
}();

