(function($){
	$.fn.flashplayer = function(options) {
		var $opts;
		
		$thumbs=$(this);
		$opts=$.extend({
			path:'/',
			lang:1,
			flexchannel:'',
			flexgateway:'',
			width:140,
			height:140,
			popUpWidth:980,
			popUpHeight:1080,
			flvFile:false,
			largePreview:false,
			showControls:true,
			loop:false
		},$.fn.flashplayer,options);
		
		function flashPlayerCheck() {
			var requiredMajorVersion = 9;
			var requiredMinorVersion = 0;
			var requiredRevision = 124;
			var hasProductInstall = DetectFlashVer(6, 0, 65);
			var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
			var footageId = -1;
			var styleUrl = 'http://www.f1online.de/f1online/moduleCustomer/flx/footagePlayerTile/assets/css/f1online.swf';
			var channelId = 'my-cfamf';
			var endpoint = 'http://www.f1online.de:80/flex2gateway/';
			var destination = 'ColdFusion';
			var source = 'public.akibase.cfc.FootageFacade';
			
			var flashVarsPrepend = 'channelId=' + channelId;
				flashVarsPrepend += '&endpoint=' + endpoint;
				flashVarsPrepend += '&destination=' + destination;
				flashVarsPrepend += '&source=' + source;
				flashVarsPrepend += '&styleUrl=' + styleUrl;
				flashVarsPrepend += '&footageId=' + footageId;
				
			if ( hasProductInstall && !hasRequestedVersion ) {
				var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
				var MMredirectURL = window.location;
			    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
			    var MMdoctitle = document.title;
	
				AC_FL_RunContent(
					"src", "playerProductInstall",
					"FlashVars", flashVarsPrepend+"&MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
					"width", "140",
					"height", "140",
					"align", "middle",
					"id", "f1FootagePlayer",
					"quality", "high",
					"wmode", "gpu",
					"bgcolor", "#ffffff",
					"name", "f1FootagePlayer",
					"allowScriptAccess","sameDomain",
					"type", "application/x-shockwave-flash",
					"pluginspage", "http://www.adobe.com/go/getflashplayer"
				);
			} else if (hasRequestedVersion) {
				AC_FL_RunContent(
						"src", "f1FootagePlayer",
						"width", "140",
						"height", "140",
						"align", "middle",
						"id", "f1FootagePlayer",
						"quality", "high",
						"wmode", "gpu",
						"bgcolor", "#ffffff",
						"name", "f1FootagePlayer",
						"flashvars",flashVarsPrepend,
						"allowScriptAccess","sameDomain",
						"type", "application/x-shockwave-flash",
						"pluginspage", "http://www.adobe.com/go/getflashplayer"
				);
			  } else {
			    var alternateContent = 'Alternate HTML content should be placed here. '
			  	+ 'This content requires the Adobe Flash Player. '
			   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
			    document.write(alternateContent);  // insert non-flash content
			  }
		}
		flashPlayerCheck();
		
		if($opts.flvFile!=false) {
			if($('#f1FootagePlayer').size()==0) {
				var flashVars  ='channelId='+$opts.flexchannel;
					flashVars +='&endpoint='+$opts.flexgateway;
					flashVars +='&destination='+'ColdFusion';
					flashVars +='&source='+'public.akibase.cfc.FootageFacade';
					flashVars +='&styleUrl='+'/f1online/moduleCustomer/flx/footagePlayerDetail/assets/css/f1online.swf';
					flashVars +='&footageId='+$opts.flvFile;
					flashVars +='&popUpWidth='+$opts.popUpWidth;
					flashVars +='&popUpHeight='+$opts.popUpHeight;
					flashVars +='&showControls='+$opts.showControls;
					flashVars +='&loop=false';
					
				/*	
				var param ='<param name="movie" value="/f1online/moduleCustomer/flx/footagePlayerDetail/f1FootagePlayerDetail.swf" />';
					param +='<param name="quality" value="high" />';
					param +='<param name="wmode" value="transparent" />';
					param +='<param name="bgcolor" value="#ffffff" />';
					param +='<param name="allowScriptAccess" value="sameDomain" />';
					param +='<param name="flashvars" value="'+flashVars+'" />';
					param +='<param name="base" value="/f1online/moduleCustomer/flx/footagePlayerDetail/" />';
					param +='<embed base="/f1online/moduleCustomer/flx/footagePlayerDetail/" src="/f1online/moduleCustomer/flx/footagePlayerDetail/f1FootagePlayerDetail.swf" quality="high" bgcolor="#ffffff" wmode="transparent" width="'+$opts.width+'" height="'+$opts.height+'" name="f1FootagePlayer" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" flashvars="'+flashVars+'" pluginspage="http://www.adobe.com/go/getflashplayer"></embed>';
				*/
				
				$('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="f1FootagePlayer" width="'+$opts.width+'" height="'+$opts.height+'" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="/f1online/moduleCustomer/flx/footagePlayerDetail/f1FootagePlayerDetail.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="allowScriptAccess" value="sameDomain" /><param name="flashvars" value="'+flashVars+'" /><param name="base" value="/f1online/moduleCustomer/flx/footagePlayerDetail/" /><embed base="/f1online/moduleCustomer/flx/footagePlayerDetail/" src="/f1online/moduleCustomer/flx/footagePlayerDetail/f1FootagePlayerDetail.swf" quality="high" bgcolor="#ffffff" wmode="transparent" width="'+$opts.width+'" height="'+$opts.height+'" name="f1FootagePlayer" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" flashvars="'+flashVars+'" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object>')
				.appendTo($('#detailview'));
			}
		}else{
			$thumbs.mouseenter(function(e){
				var Image=$(this);
				var id=Image.attr('imgNo');
				var flvFile=$(this).attr('flv');
				
				if($('#f1FootagePlayer').size()) {
					$('#f1FootagePlayer').remove();
					flashMovie=-1;
					$thumbs.show();
				}else{
					if($('#f1FootagePlayer').size()==0 && flashMovie==-1) {
						flashMovie=id;

						var flashVars ='channelId='+$opts.flexchannel;
							flashVars +='&endpoint='+$opts.flexgateway;
							flashVars +='&destination=ColdFusion';
							flashVars +='&source=public.akibase.cfc.FootageFacade';
							flashVars +='&styleUrl=/f1online/moduleCustomer/flx/footagePlayerTile/assets/css/f1online.swf';
							flashVars +='&footageId='+flvFile;
							flashVars +='&popUpUrl=/f1online/moduleCustomer/inc/showPicture.cfm?imgNo='+id+'&language='+$opts.lang;
							flashVars +='&popUpHeight='+$opts.popUpHeight;
							flashVars +='&showControls='+$opts.showControls;
							flashVars +='&showControls='+$opts.showControls;

						var flashObject=
						$('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="f1FootagePlayer" width="'+$opts.width+'" height="'+$opts.height+'" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="/f1online/moduleCustomer/flx/footagePlayerTile/f1FootagePlayer.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="allowScriptAccess" value="sameDomain" /><param name="flashvars" value="'+flashVars+'" /><param name="base" value="/f1online/moduleCustomer/flx/footagePlayerTile/" /><embed base="/f1online/moduleCustomer/flx/footagePlayerTile/" src="/f1online/moduleCustomer/flx/footagePlayerTile/f1FootagePlayer.swf" quality="high" bgcolor="#ffffff" wmode="transparent" width="'+$opts.width+'" height="'+$opts.height+'" name="f1FootagePlayer" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" flashvars="'+flashVars+'" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object>')
						.mouseout(function(e){
							flashMovie=-1;
							$('#f1FootagePlayer').remove();
							$('#imageResult_'+id).show();
							e.stopPropagation();
						});
						
						Image.hide();
						$('#player-'+id).append(flashObject);
						
					}
				}
				
				e.stopPropagation();
			});
		}
	}
})(jQuery);