var urld = null;			
var lpdd;				
var lbak = null;			
var oop = null;				
var loopx=2;				
var sval, medTT, alTXT;			
var zslen=0;				
var rndX = false;			
var rnd = [];				
var rndBJ = 0;				
var reN;				
var xdbj=0, xxL,xxR;			
var sewin = false;			
var mute = false;			


function newlist(zzs)		
{
  listbak(zzs);
  if(zzs)
  {
    urld = [];
    rnd = [];
  }
  rndBJ = urld.length;
}

function playlist(zzs)		
{
  if(urld.length<1)	
    urld[0] = new urlDataClass("列表为空","",0);
  sxdfbd();
  rtxt3.style.visibility = (urld.length<=1)?"hidden":"visible";
  rtxt3b.innerText = urld.length;
  newrnd(rndBJ);
  if(zzs)
  {
    if(rndX)
      playrnd();
    else
      openfile(0);
  }
}


function listbak(zzs)		
{
  if(urld==null || !zzs) return;
  if(urld.length<2) return;
  lbak = urld; 
}

function returnlist()		
{
  if(lbak==null) { dsts("没有列表可招回"); return; }
  var bbb = lbak;
  lbak = null;
  newlist(true);
  urld = bbb;
  playlist(true);
}


function UDC_dk()
{
  var s = /\.[^\.]+$/.exec(this.uu);
  return (s!=null)?s[0].toUpperCase():"***";
}

function UDC_oot()
{
  if(this.uu.slice(2,3)=="*") {
    var vvv="egy+nb@QwXvCWjKPRxVzDl/h7EOMtSa9f6*FpNr81i_0kqdG2LBcuZIAJYo34m-sT%5.UH3SYZ0hzt/y@qDTNECf1BpujiO.X6ks+oIR8GPVg9wbm%xJvKLWrn*F4HAe-QladM27Uc5_";
    var du = parseInt(this.uu.slice(0,2));
    var uu = "";
    var ht = (vvv.slice(70)+vvv.slice(70)).slice(du);
    for(var ii=3; ii<this.uu.length; ii++)
    {  
      var w = (ii-3)%10;
      var k = ht.indexOf(this.uu.slice(ii,ii+1),w)-w;
      uu += vvv.slice(k,k+1);
    }
    this.uu = unescape(uu);  }
  this.uu = this.uu.replace(/\\/g,"/");
  if(this.oo>=1 && this.oo<=2) return;
  var st = /^[^:\/]+:\/\//.exec(this.uu);
  if(st!=null)
  {
    st = st[0].toUpperCase();
    if(LX_M_x.indexOf(";"+st)!=-1) 
    { this.oo = 1; return; }
    if(LX_R_x.indexOf(";"+st)!=-1) 
    { this.oo = 2; return; }
  }
  if(this.uu.indexOf("?")!=-1) 
  { this.oo = 2; return; }
  var sd = this.dk()+";";
  if(LX_M_v.indexOf(sd)!=-1) 
  { this.oo = 1; return; }
  if(LX_R_v.indexOf(sd)!=-1) 
  { this.oo = 2; return; }
}

function urlDataClass(nn,uu,oo)		
{
  this.nn = nn;
  this.uu = uu;
  this.oo = oo;		

  this.dk = UDC_dk;
  this.oot = UDC_oot;

  this.oot();
}


function sxdfbd()		
{
 loplist.options.length = urld.length;
 for(var ii=0; ii<urld.length; ii++)
   loplist.options[ii].text = ii+1+"."+urld[ii].nn;
 loplist.selectedIndex = 0;
}



function newrnd(s)		
{
  for(var ii=s; ii<urld.length; ii++)
    rnd[rnd.length++] = ii;
}

function playrnd()		
{
  if(rnd.length==0) return;
  var rr,zzz;
  rr = Math.floor(Math.random()*rnd.length);
  zzz = rnd[rr];
  rnd[rr] = rnd[rnd.length-1];
  rnd.length--;
  openfile(zzz);
}


function openbd(zzs)	
{
  var zzo = furvl.value;
  furvl.click();
  var uur = furvl.value;
  if(zzo==uur || uur=="") return;
  var ls = new urlDataClass("",uur,0);
  if(ls.oo==0)
  {
    alert("你所选的文件不能播放！");
    return;
  }
  /^[^\?]+\/([^\/\?]+)\.[^\/\.\?]+($|\?.+$)/.exec(ls.uu);
  ls.nn = RegExp.$1;
  if(urld==null)
    zzs = true;
  newlist(zzs);
  urld[urld.length] = ls;
  playlist(zzs);
}

function seturladd(zzs)		
{
  var uur = window.showModalDialog("seturl.htm", self, "dialogHeight:120px;dialogWidth:326px;status:0;help:0;scroll:0"); 
  if(uur==null) return;
  var ls = new urlDataClass("",uur[0],uur[1]);
  /^[^\?]+\/([^\/\?]+)\.[^\/\.\?]+($|\?.+$)/.exec(ls.uu);
  ls.nn = RegExp.$1;
  if(urld==null)
    zzs = true;
  newlist(zzs);
  urld[urld.length] = ls;
  playlist(zzs);
}


///////////////////////////////////////////////////////

function closedObj()		
{
  clearTimeout(medTT);
  clearInterval(sval);
  if(xdbj!=0)
  {
    xdbj=2;
    xdbfsz();
  }
  oop.closed();
  rtxt1.innerText = "空闲";
  rtxt4.innerText = "";
}

function openfile(uuu)		
{
  if(oop!=null)
    closedObj();
//------------------
  oop = null;
  lpdd = uuu;
  rtxt2.innerText = urld[lpdd].nn;
  rtxt3a.innerText = lpdd+1;
  loplist.selectedIndex = lpdd;
//---------------------------------
  var zzo = urld[lpdd].oo;
  if(zzo==1)
  {
    if(or_m) { ort_m=or_player(ort_m); return; }
    oop = new mediaClass();
  }
  else if(zzo==2)
  {
    if(or_r) { ort_r=or_player(ort_r); return; }
    oop = new realClass();
  }
  else
  { 
    dsts("此文件无法播放");
    medTT = setTimeout("autonext();",1000);
    return; 
  }
//-------------------------------
  reN = 0;
  oop.open(urld[lpdd].uu);

  ylyyd();
  oop.mute(mute);
  jdhk.setposition(0);
  zslen=0;
  sval = setInterval("genzong()",300);
}


function or_player(n)
{
  if(n!="")
    alert(n);
  dsts("系统无播放控件!");
  medTT = setTimeout("autonext();",1000);
  return "";
}


function lenvar()
{
  var zzl = oop.length();
  if(zzl<=0) return;
  zslen=zzl;
  rtxt4.innerText = oop.sjxs(zzl);
}

function genzong()		
{
 try {

  var pos = oop.pos();
  if(zslen==0)
    lenvar();
  else 
  {
    if(!jdhk.moing)
      jdhk.setposition(Math.round(jdhk.mlength()/zslen*pos));
    if(xdbj!=0 && pos>xxR)
      oop.go(xxL);
  }
  dtut.innerText = oop.sjxs(pos);
  oop.ifending();

 } catch(hh){}
}



function aabf()		
{
  if(oop==null) { dsts(); return; }
  oop.play();
}

function aazt()		
{
  if(oop==null) { dsts(); return; }
  oop.pause();
}

function aatz()		
{
  if(oop==null) { dsts(); return; }
  oop.stop();
}

function aaht()		
{
  if(oop==null) { dsts(); return; }
  var v = oop.pos() - oop.gotov;
  if(v<0) v=0;
  oop.go(v);
}

function aaqj()		
{
  if(oop==null) { dsts(); return; }
  var v = oop.pos() + oop.gotov;
  if(v<=oop.length())
    oop.go(v);
}


function lbssdy()		
{
  if(urld==null) { dsts(); return; }
  if(urld.length<=1) { dsts("目前没有列表！"); return; }
  openfile(0);
}

function lbsy()		
{
  if(urld==null) { dsts(); return; }
  if(urld.length<=1) { dsts("目前没有列表！"); return; }
  if(lpdd<=0) { dsts("没有上一段了！"); return; }
  openfile(lpdd-1);
}

function lbxy()		
{
  if(urld==null) { dsts(); return; }
  if(urld.length<=1) { dsts("目前没有列表！"); return; }
  if(lpdd>=urld.length-1)  { dsts("没有下一段了！"); return; }
  openfile(lpdd+1);
}

function lbmmdy()		
{
  if(urld==null) { dsts(); return; }
  if(urld.length<=1) { dsts("目前没有列表！"); return; }
  openfile(urld.length-1);
}

function lhhgo()		
{
  home.focus();
  if(urld==null) { dsts(); return; }
  if(urld.length<=1) { dsts("目前没有列表！"); return; }
  openfile(loplist.selectedIndex);
}

function listedit()		
{
  if(urld==null) { dsts("请先播放一个文件"); return; }
  window.showModalDialog("listedit.htm", self, "dialogHeight:230px;dialogWidth:320px;status:0;help:0;scroll:0"); 
}


function ylyydxx()		
{
 if(zslen==0) return;
 var nx = jdhk.getposition();
 var zzs = Math.round(zslen/jdhk.mlength()*nx);
 oop.go(zzs);
}


function ylyyd()		
{
  if(oop==null) return;
  var nx = Math.floor(ylhk.getposition()/ylhk.mlength()*100);
  oop.volume(nx);
}


function jingbb()	
{
  mute=!mute;
  eval("jingyin.src=bb_jy"+(mute?"1":"0")+".src");
  if(oop!=null)
    oop.mute(mute);
}


function lomd()		
{
  loopx=(loopx+1)%3;
  eval("IM_xh.src=bb_lok"+loopx+".src");
  IM_xh.alt="循环："+["无循环","单曲循环","全部循环"][loopx];
}

function rndkk()	
{
  rndX=!rndX;
  eval("IM_sj.src=bb_rnd"+(rndX?"0":"1")+".src");
  IM_sj.alt="随机播放 "+(rndX?"开":"关");
}



function gonext()		
{
  if(loopx==1 || loopx==2 && urld.length<=1)
  {
    oop.go(0);
    setTimeout("oop.play();",1000);
    return;
  }
  if(urld.length<=1) return;

  if(rndX)
  {
    if(rnd.length==0 && loopx==2)
      newrnd(0);
    playrnd();
  }
  else
  {
    if(lpdd<urld.length-1)
    {
      openfile(lpdd+1);
      return;
    }
    if(loopx==2)
      openfile(0);
  }
}



function errorreplay()
{
  reN++;
  if(reN<=1)
  {
    dsts("错误！重试"+reN+"次");
    medTT = setTimeout("oop.play();",1000);
  }
  else
  {
    dsts("文件无法播放！");
    medTT = setTimeout("autonext();",1000);
  }
}

function autonext()		
{
  if(urld.length<=1) return;
  if(rndX)
  {
    if(rnd.length==0 && loopx!=0)
      newrnd(0);
    playrnd();
  }
  else
  {
    if(lpdd<urld.length-1)
    {
      openfile(lpdd+1);
      return;
    }
    if(loopx!=0)
      openfile(0);
  }
}



function mdip_tt(f)		
{
  if(oop==null) return;
  if(oop.constructor != mediaClass) return;
  var fs = ["未定义","已停止","已暂停","播放中","向前搜索","向后搜索","缓冲中..","等待中..", "播放完毕","转换曲目","准备就绪"];
  if(f<0 || f>=fs.length) return;
  rtxt1.innerText = fs[f];
  if(f == 8)
    medTT = setTimeout("gonext();",500);
}

function reap_tt(f)	
{
  if(oop==null) return;
  if(oop.constructor != realClass) return;
  if(f!="")
    rtxt1.innerText = f.slice(0,4);
}

function miderror()	
{
  if(oop==null) return;
  if(oop.constructor != mediaClass) return;
  errorreplay();
}

function reaerror()		
{
  if(oop==null) return;
  if(oop.constructor != realClass) return;
  errorreplay();
}



function dsts(t)		
{
  clearTimeout(alTXT);
  Jts1.innerText = t || "当前无法执行！";
  Jts1.style.display = "block";
  Jts2.style.display = "none";
  alTXT = setTimeout('Jts2.style.display="block";Jts1.style.display="none";',1000);
}



function xdbfsz()		
{
  if(oop==null) { dsts(); return; }
  xdbj=(xdbj+1)%3;
  eval("IM_xd.src=bb_xd"+xdbj+".src");
  IM_xd.alt="选段："+["标记选段开头","标记选段结束","取消选段"][xdbj];
  switch(xdbj)
  {
   case 0:
    jdhkl.style.backgroundPositionX = "9999"; 
    jdhk.style.backgroundPositionX = "9999";
   break;
   case 1:
     xxL = oop.pos();
     xxR = oop.length()-2;
     xdbjsz();
   break;
   case 2:
     xxR = oop.pos();
     if(xxL>=xxR)
     {
       var zz = xxL;
       xxL = xxR;
       xxR = zz;
     }
     xdbjsz();
    break;
  }
}

function xdbjsz()		
{
  var m = oop.length() || 1;
  jdhkl.style.backgroundPositionX = Math.round(xxL/m*100)+"%"; 
  jdhk.style.backgroundPositionX = Math.round(xxR/m*100)+"%";
}



function selectmenu()
{
  var d = menu.selectedIndex;
  home.focus();
  menu.selectedIndex = 0;
  switch(d)
  {
   case 1:  openbd(true);  break;
   case 2:  seturladd(true);  break;
   case 3:  openbd(false);  break;
   case 4:  seturladd(false);  break;
   case 5:  listedit();  break;
   case 6:  returnlist();  break;
  } 
}


function openlw()
{
  try {
    sewin.focus();
  } catch(hh)
  {
    sewin = window.open("select.htm","ListSelectWindow","width=370,height=414");
  }
}

function closelw()
{
  try {
    sewin.close();
  } catch(hh){}
}



var sTE = false;
function START()
{
  newlist(true);
  sTE = true;
}
function DATA(n,u,o)
{
  if(!sTE) return;
  o = o || 0;
  addlist(n,u,o);
}
var data = DATA;
function END()
{
  sTE = false;
  playlist(true);
}

function addlist(n,u,o)			
{
  urld[urld.length] = new urlDataClass(n,u,o);
}

function loadDataFile()
{
  if(openRND)
    rndkk();
  lodapl.src="js/data.js";
}



window.onload = function()
{
  loading.outerHTML = "";
  apxt.style.visibility = "visible";
  if(openPLAY==1)
    setTimeout('loadDataFile();',0);
  else
    if(openPLAY==2)
      if(confirm('您是否需要播放背景音乐？'))
        loadDataFile();
}

