if(typeof FFLVPlayer == 'undefined') {
	var FFLVPlayer = new Object();

	FFLVPlayer.flvArr = [];
	FFLVPlayer.getBaseDirectory = function(fName) {
		var scripts = document.getElementsByTagName( 'script' );
		var script;
		var params;
		for ( var i=0; i<scripts.length; i++ ) {
			var s = scripts.item( i );
			if( s.src.indexOf( fName ) != -1 ) {
				script = s;
				break;
			}
		}
		if( script ) {
			params = script.src.replace( 'js/FFLVPlayer.js', '' );
		} else {
			return false;
		}
		return params;
	}
	FFLVPlayer.contentsRoot = FFLVPlayer.getBaseDirectory( 'js/FFLVPlayer.js' );
	document.write('<script type="text/javascript" src="' + FFLVPlayer.contentsRoot + 'js/swfobject.js"></script>');
	document.write('<script type="text/javascript" src="' + FFLVPlayer.contentsRoot + 'js/JavaScriptFlashGateway.js"></script>');
	
	FFLVPlayer.addPlayer = function(_divID, _w, _h, _moviePath, _imagePath, _frontColor, _bgColor, _highlighColor, _id, _autoStart) {
		var uid = new Date().getTime();
		this['BPObject' + uid] = new Object();
		var BPObject = this['BPObject' + uid] ;
		BPObject.objectName = 'BPObject' + uid;
		BPObject.uid = uid+_divID;

		BPObject.contentsRoot = this.contentsRoot;
		BPObject.divID = _divID;
		BPObject.imagePath =  typeof _imagePath == 'undefined' || _imagePath == '' ? 'undefined' : _imagePath.indexOf('http://') != 0 ? '../'+ _imagePath : _imagePath;
		BPObject.moviePath =  typeof _moviePath == 'undefined' || _moviePath == '' ? 'undefined' : _moviePath.indexOf('http://') != 0 ? '../'+ _moviePath : _moviePath;
		BPObject.movieWidth = _w;
		BPObject.movieHeight = _h;
		BPObject.movieID = typeof _id == 'undefined' || typeof _id == 'string' ? 'undefined' : _id;
		BPObject.frontColor =  typeof _frontColor == 'undefined' || _bgColor == '' ? '#FFFFFF' : _frontColor.split('0x').join('#');
		BPObject.bgColor =  typeof _bgColor == 'undefined' || _bgColor == '' ? '#000000' : _bgColor.split('0x').join('#');
		BPObject.highlighColor =  typeof _highlighColor == 'undefined' || _bgColor == '' ? '#999999' : _highlighColor.split('0x').join('#');
		BPObject.autoStart = _autoStart ? _autoStart : false;
		BPObject.ready = false;
		BPObject.onReadySWF = function(){
			BPObject.ready = true;
			alert(complete);
		}

		BPObject.pxy = new FlashProxy(BPObject.uid, BPObject.contentsRoot + 'swf/JavaScriptFlashGateway.swf');

		this.flvArr.push([BPObject.divID, BPObject.movieID, BPObject.objectName]);

		BPObject.attachPlayer = function(){
			var so = new deconcept.SWFObject(this.contentsRoot + 'swf/FFLVPlayer.swf?'+this.uid, this.uid, this.movieWidth, this.movieHeight, '8', this.bgColor);
			so.addParam('menu', 'false');
			so.addParam('base', '.');
			so.addParam('allowFullScreen', true);
			so.addParam('wmode', 'transparent');
			so.addParam('allowScriptAccess', 'always');

			so.addVariable('lcId', this.uid);
			so.addVariable('objectName', this.objectName);
			so.addVariable('onReadyMethd', this.objectName +'.onReadySWF');

			so.addVariable('moviePath', this.moviePath);
			so.addVariable('imagePath', this.imagePath);
			so.addVariable('movieWidth', this.movieWidth);
			so.addVariable('movieHeight', this.movieHeight);
			so.addVariable('frontColor', this.frontColor);
			so.addVariable('bgColor', this.bgColor);
			so.addVariable('highlighColor', this.highlighColor);
			so.addVariable('autoStart', this.autoStart);

			so.write(this.divID);
		}
		BPObject.attachPlayer();
	}
	FFLVPlayer.controll = function(_id, _method) {
		var i = 0;
		var arrLength = FFLVPlayer.flvArr.length;
		var type = _id && typeof _id == 'string' ? 0 : 1;
		for (i = 0; i < arrLength; i++) {
			if (FFLVPlayer.flvArr[i][type] == _id) {
				this[this.flvArr[i][2]].pxy.call('controll', _method);
				return true;
			}
		}
		return false;
	}
}
