﻿//【 iWater - MIXER BGM player Version.1 】

a = ' \n  <object id="iwater" type="video/x-ms-wmv" style="width:0px; height:0px;">\n  <param name="src" value="';                      //for Mozilla, Netscape, IE
b = '" valuetype="ref">\n  <param name="autoStart" value="1" valuetype="data">\n  <param name="Volume" value="100" valuetype="data">\n  <embed src="';
c ='" type="video/x-ms-wmv" autoStart="1" showControls="0" style="width:0px; height:0px; visibility:hidden;"></embed>\n  </object>\n';   //for Opera


var songPlaying = false;
var id = null;
var songTitle = null;
var songTime = null;
var songPath = null;
var fornext = null;


function listTrack(path, title, mins, sec){
    if (id == null) { id = new Array(); count = 0;} else { count = id.length; }
    if (songPath == null) { songPath = new Array(); }
    if (songTitle == null) { songTitle = new Array(); }
    if (songTime == null) { songTime = new Array(); }

    if (title == null || title == '' ) { title1 = 'Track ' + (count + 1); } else { title1 = title; }
    if (mins == null || mins == '' ) { mins1 = 00; } else { mins1 = mins; }
    if (sec == null || sec == '' ) { sec1 = 30; } else { sec1 = sec; }
   
   time = mins1 * 60 + sec1 * 1;
   
    id[count] = path;
	songTitle[count] = title1;
    songTime[count] = time;
	count2 = count + 1;
	count3 = count;
    songsRandom = parseInt(Math.random()*id.length);
	}


function bgm_in(e){
    if(songPlaying) {clearTimeout(timer);}
    songPlaying = true;
    track = e;

    if(track > count){var track = 0;}
	if(track < 0){var track = count2 - 1;}

    bgm_next(track);

	backward = track - 1;                        //依照排列播放上一首
    forward = track + 1;                         //依照排列延續下一首
    now = track;

    var player = a + id[track] + b + id[track] + c;

	bgm_out(songTitle[track] + player);

    var time1 = songTime[track] * 1000 + RestSec * 1000; //此函數是以毫秒計算, 因此乘以1000 
	timer = setTimeout('bgm_in(nextTrack);',time1);
	timer;
	}


function bgm_out(f){
    document.getElementById("iwater_left").innerHTML=f;
    }


function bgm_stop(){
   if(!songPlaying){
	  alert(nthsPlaying);
	  return;
	  }
	else{
	  bgm_out(stoppedMsg);
	  clearTimeout(timer);
	  songPlaying = false;
      }
    }


//當網頁載入
function loading(){
   if(playWhileloading) {
     if(playingMode == 0){bgm_in(0);}                                  //照順序播放第一首歌
     if(playingMode == 1){bgm_in(random);}                             //隨機選取
     }
    }


//播放器按鈕列
//播放
function button_play(){
	if(songPlaying){
	  alert(sthsPlaying);                   //防止檔案重複下載
	  return;
	  }
	else{
      random = parseInt(Math.random()*(count2));
      bgm_in(random);
      }
    }

//上一首
function button_backward(){
	if(!songPlaying){
	  alert(nthsPlaying);
	  return;
	  }
	else{
      bgm_in(backward);
      }
    }

//下一首
function button_forward(){
	if(!songPlaying){
	  alert(nthsPlaying);
	  return;
	  }
	else{
      bgm_in(forward);
      }
    }


function bgm_next(track){
    if(playingMode == 0) {nextTrack = track + 1;}                             //依照排列延續下一首
	if(playingMode == 1) {nextTrack = parseInt(Math.random()*(count2));}     //隨機選取下一首
	if(nextTrack == track && count2 > 1) {bgm_next(track);}                    //避免與下首曲目重覆
	if(count2 == 1) {nextTrack = track;}                                    //只有一首歌
    }


function bgm_win(){ 
    window.open(selectPage,'_blank','width=320,height=350,top=50,left=50,scrollbars=1,resizable=1,status=1');
    }


function defaultMsg(){
    document.getElementById("iwater_left").innerHTML=defaultMsg1;
    }