if(typeof(window.FMP) === "undefined") {
	var FMP = window.FMP = new (function(){
		var msie = /msie/.test(navigator.userAgent.toLowerCase());
		this.get = function(id) {
			var o = document.getElementById(id);
			if (!o || o.nodeName.toLowerCase() !== "object") {
				o = msie ? window[id] : document[id];
			}
			return o;
		};
		this.create = function(id, width, height, url, vars, params, attrs){
			var _attrs = {
				width : width,
				height : height,
				id : id
			};
			appendObj(_attrs, attrs);
			var _params = { 
				allowfullscreen : "true", 
				allowscriptaccess : "always" 
			};
			appendObj(_params, params);
			var _vars;
			if (vars) {
				if (typeof(vars) === "object") {
					var arr = [];
					for (var v in vars) {
						arr.push(v + "=" + encodeURIComponent(vars[v]));
					}
					_vars = arr.join("&");
				} else {
					_vars = vars + "";
				}
			}
			if (_vars) {
				_params.flashvars = _vars;
			}
			var htm = '<object ';
			if (msie) {
				htm += 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="/fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" ';
			} else {
				htm += 'type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" data="'+url+'" ';
			}
			for (var a in _attrs) {
				htm += a + '="'+_attrs[a]+'" ';
			}
			htm += msie? '><param name="movie" value="'+url+'" />' : '>';
			for (var p in _params) {
				htm += '<param name="'+p+'" value="'+_params[p]+'" />';
			}
			htm += '<param name="wmode" value="transparent" />';
			htm += '</object>';
			return htm;
		};
		function appendObj(_obj, obj) {
			if (obj && typeof(obj) === "object") {
				for (var k in obj) {
					_obj[k] = obj[k];	
				}
			}
			return _obj;
		}
	})();
};

var urld = [];
var rnd = [];
var sTE = false;//是否可以添加新舞曲
var mode = 1; //0:顺序,1:随机;
var lastId = 4;

var player = {
	fmpObj:'',
	danceFile:'',
	fmp_loaded: function(key) {
		if(player.fmpObj) {
			player.fmpObj.addEventListener("model_state", "player.fmp_model_state");
		}
	},
	fmp_model_state: function(data) {//播放状态变换时调用
		//参数data就能返回当前播放状态
		if (data == "completed") {
			if(mode==1){
				playRnd();
			}
			else{
				play();
			}
		}
	},
	create: function(pId){
		var isiPad = navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
		if(isiPad){
			document.getElementById('loading').innerHTML = "由于iPad,iPhone,iPod设备不支持自动播放功能，所以您无法试听开场舞曲.";
		}
		else{
			var htm = FMP.create("fmp", "960", "86", "cmp.swf", {api:"player.fmp_loaded",skin:"playindex.swf",context_menu:"2"});
			document.getElementById(pId).innerHTML = htm;
			player.fmpObj = FMP.get("fmp");
		}
	}
};

function START(){
	urld = [];
	rnd = [];
	lst = [];
	sTE = true;
}

function DATA(n, u, i){
	if(!sTE) return;
	urld[urld.length] = new dataClass(n, u, i);
}

function END(){
	var $loplist = $('#loplist');
	sTE = false;
	if(urld.length<1){
		urld[0] = new dataClass("列表为空", "", 0);
	}
	for(var ii=0; ii<urld.length; ii++){
		$loplist.append("<option value='" + ii + "' >" + (ii+1) + "." + urld[ii].name + "</option>");
	}
	$loplist[0].selectedIndex = 0;
	for(var ii=0; ii<urld.length; ii++){
		lst[ii] = ii;
	}

	if(mode==1){
		setTimeout("playRnd()", 2000);
	}
	else{
		setTimeout("play()", 2000);
	}
}

function dataClass(name, url, id){
	this.name = name;
	this.url = url.replace(/\\/g,"/");
	this.id = id;
}

function openfile(index){
	var $loplist = $('#loplist');
	$('#loplist')[0].selectedIndex = index;
	player.dancename = urld[index].name;
	player.danceFile = urld[index].url;
	player.dancetype = urld[index].type;
	player.danceid = urld[index].id;
	if(urld[index].id==1){
		player.fmpObj.list_xml('<list><m label="'+player.dancename+'" src="'+player.danceFile+'" type="'+player.dancetype+'" id="'+player.danceid+'"/></list>', false);
		player.fmpObj.sendEvent('view_play');
	}

}

function goToPlay(){
	$('#home').focus();
	var $loplist = $('#loplist');
	lastId = $loplist[0].selectedIndex+1;
	openfile($loplist[0].selectedIndex);
}

//顺序播放
function play(){
	if (lastId > lst.length-1)
	{openfile(0);}
	else
	{openfile(lastId++);}
}

//随机播放
function playRnd(){
	for(var ii=0; ii<urld.length; ii++){
		rnd[rnd.length++] = ii;
	}
	//alert(rnd);
	var rnum, firstNum;
	rnum = Math.floor(Math.random()*rnd.length);
	firstNum = rnd[rnum];
	lastId = firstNum+1;
	rnd[rnum] = rnd[rnd.length-1];
	rnd.length--;
	openfile(firstNum);
}
function onloadData(){
var movie = document.getElementById("fmp");
var nPercentLoaded = Math.abs(movie.PercentLoaded()); 
if(nPercentLoaded==100)  {
		setTimeout("$('#lodapl')[0].src = 'lb.php';$('#loading').hide();", 1000);
}
else{
		setTimeout("onloadData()", 1000);
	}
}

window.onload = function(){
	onloadData();
}