var vol = 100;

function setVol(v) {
	vol = v;
}

function playMp3(artist,mp3,id3,bgcolor,divid) {
 if(typeof(bgcolor)=="undefined") { bgcolor = "#FFFFFF"; }
if(typeof(divid)=="undefined") { divid= "mp3_player"; }
 var so = new SWFObject("http://www.younha.jp/mp3player/player.swf", "mymovie", "200", "60", "6", bgcolor);
  so.addVariable("artist_inst", artist);
  so.addVariable("mp3_name", mp3);
  so.addVariable("track_name", URLencode(id3));
  so.addVariable("vol", vol);
 so.write(divid);
}


// playMp3(artist,mp3,id3,bgcolor)
//
//  artist - FMSディレクトリ（インスタンス）名（≒アーティスト名）
//  mp3 - MP3ファイル名（拡張子不要）
//  id3 - プレーヤーに表示される曲情報。明示的に改行する場合は\nを挿入
//        その他、URLエンコードのため入力できない文字あり（半角+など）
//  bgcolor - [オプション] ページ背景色が白（#FFFFFF）以外のとき指定



// URLエンコード関数
function URLencode(str){
 // Unicode to URL encoded UTF-8
 var i, encoded_str, char_code, padded_str;
         encoded_str = "";
         for (i = 0; i < str.length; i++){
             char_code = str.charCodeAt(i);
             if (char_code == 0x20){
                // space -> "+"
                encoded_str += "+";}
             else { // else 1
                  if (((0x30 <= char_code) && (char_code <= 0x39)) || ((0x41 <= char_code) && (char_code <= 0x5a)) || ((0x61 <= char_code) && (char_code <= 0x7a))){
		     // [0-9a-z-A-Z]
                     // no escape
                     encoded_str += str.charAt(i);
                  }
		  else if ((char_code == 0x2a) || (char_code == 0x2e) || (char_code == 0x2d) || (char_code == 0x5f)) {
		     // [.-_]
                     // no escape
                     encoded_str += str.charAt(i);
		  }
                  else { // else 2
                       // for internal unicode to UTF-8
		       // Ref. http://homepage3.nifty.com/aokura/jscript/utf8.html
		       // Ref. http://homepage1.nifty.com/nomenclator/unicode/ucs_utf.htm
                       if ( char_code > 0xffff ) {
                          encoded_str += "%" + ((char_code >> 18) | 0xf0).toString(16).toUpperCase();
                          encoded_str += "%" + (((char_code >> 12) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
		       }
                       else if ( char_code > 0x7ff ) {
                          encoded_str += "%" + ((char_code >> 12) | 0xe0).toString(16).toUpperCase();
			  encoded_str += "%" + (((char_code >> 6) & 0x3f) | 0x80).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
                       }
                       else if ( char_code > 0x7f ) {
		          encoded_str += "%" + (((char_code >> 6) & 0x1f) | 0xc0).toString(16).toUpperCase();
			  encoded_str += "%" + ((char_code & 0x3f) | 0x80).toString(16).toUpperCase();
                       }
                       else {
                          // for ascii
                          padded_str = "0" + char_code.toString(16).toUpperCase();
                          encoded_str += "%" + padded_str.substr(padded_str.length - 2, 2);
                       }
                    } // else 2
                } // else 1
        } // for
        return encoded_str;
}

