var song_seq = 0;
var song_seq_pre = 0;
var title;
var tID0;
var tID1;
var tID2;
var readyFlag = false;
var playFlag = false;

function playstart() {
	try {
		var obj = document.all("Player");
		Player.FileName = "http://www.pphony.com/bgm/asx.php?encStr="+enc_str;
		//playerControl("Play");
	} catch(e) {}
}	

function timer() {
	tID2 = setInterval('getInfo()', 500);
}

function playerControl(mode) {
	if (mode == "Play") {
		Player.AutoStart=1;
	
		try { parent.viewFrame.stop(); } catch(e) {}
		
		Player.Play();
		playFlag = true;
		try {
			//parent.viewFrame.title.innerHTML = color_str(title);
			parent.viewFrame.title.innerHTML = "<marquee scrollamount=2>" + title + "</marquee>";
		} catch (e) {}
		clearTimeout(tID2);
		timer();
	} else if (mode == "Pause") {
		Player.Pause();
		playFlag = false;
		try {
			parent.viewFrame.title.innerHTML = "¹è°æÀ½¾Ç PAUSE »óÅÂÀÔ´Ï´Ù.";
		} catch(e) {}
		clearTimeout(tID2);
	} else if (mode == "Stop") {
		Player.Stop();
		playFlag = false;
		try {
			parent.viewFrame.title.innerHTML = "¹è°æÀ½¾Ç STOP »óÅÂÀÔ´Ï´Ù. ¹è°æÀ½¾ÇÀ» µéÀ¸½Ã·Á¸é PLAY ¹öÆ°À» ´©¸£¼¼¿ä";
		} catch(e) {}
		clearTimeout(tID2);
	}
}

function getInfo() {
	//alert(Player.PlayState);
	try {
		var obj;
		obj = document.all("Player");
		if (obj.PlayState != 2) {
			parent.viewFrame.title.innerHTML = "¹è°æÀ½¾Ç ·ÎµùÁß..";
		} else {
			title = obj.GetMediaInfoString(8);
			song_seq = obj.GetMediaInfoString(9);
			if (song_seq != song_seq_pre) {
				//parent.viewFrame.title.innerHTML = color_str(title);
				if (title=="" || title==null || title=="undefined") {
					parent.viewFrame.title.innerHTML = "¹è°æÀ½¾Ç ·ÎµùÁß..";
				} else {
					parent.viewFrame.title.innerHTML = "<marquee scrollamount=2>" + title + "</marquee>";
				}
			}
			song_seq_pre = song_seq;
		}
	} catch(e) {}
}

function parseHex() {
	var rand_num = Math.floor(Math.random()*16);
	var hex_value = gf_DecToHex(rand_num);
	return hex_value;
}

function gf_DecToHex(x_dec) {
    var x_Hex = new Array();
    var x_serial = 0;
    var x_over16 = x_dec;
    var x_tempNum = 0;
    while(x_dec > 15) {
        var x_h = x_dec % 16; //³ª¸ÓÁö
        x_dec = parseInt(x_dec/16); //¸ò
        x_Hex[x_serial++] = (x_h > 9 ? String.fromCharCode(x_h + 55) : x_h); //16Áø¼öÄÚµåº¯È¯
    }
    //¸¶Áö¸·Àº ¸òÀÇ °ªÀ» °¡Áü
    x_Hex[x_serial++] = (x_dec > 9 ? String.fromCharCode(x_dec + 55) : x_dec); //16Áø¼öÄÚµåº¯È¯
    //¸ò,³ª¸ÓÁö,³ª¸ÓÁö,.....
    var retValue = "";
    for(var i=x_Hex.length ; i>0 ;i--) {
        retValue += x_Hex[i-1];
    }
    return retValue;
}
    
var colorValue="";
var hex;
var colorString;
function color_str(title) {
	for (var i=0; i<6; i++) {
		hex = parseHex();
		colorValue += hex;
		//alert(colorValue);
	}
	colorString = "<font color='#" + colorValue + "'>" + title + "</font>";
	return colorString;
}