document.write("<sc"+"ript LANGUAGE='JavaScript' FOR='mbox' EVENT='PlayStateChange(os, ns)' > managePlayStateChange(os,ns); actOnEnd(ns);</scr"+"ipt>");
document.write("<sc"+"ript LANGUAGE='JavaScript' FOR='mbox' EVENT='PositionChange(op, np)' >managePositionEvent(np);</scr"+"ipt>");
document.write("<sc"+"ript LANGUAGE='JavaScript' FOR='mbox' EVENT='ErrorState(iErrorState)' >manageErrorEvent(iErrorState);</scr"+"ipt>");

var slide_use = 1;
var dragApproved = false;
var Cue=0;
//var volume=0;
var volLength = 50;
var volSPoint = 213;
var toggleFlag = false;

var listenMode = 0; // 0, 1
var rdoRepeat = 1; // 0, 1, 2
var playStateInfo;

function actOnEnd(value){
  playStateInfo = value;
  if(value == 3)
  {
    next(); 
  }
}

/* About Playing Control */
var RepeatFlag = 0; /* 0:None/1:One/2:All */
var listenFlag = 1; /* play time Setting 0 : ÀüÃ¼ µè±â , 1: 60ÃÊ µè±â */ 

function mMute(){
	if(typeof mbox == 'object'){	
		if(mbox.Mute){
			mbox.Mute(0);
			document.all.strMuteStatus.innerHTML = "Mute Off (¼Ò¸®ÄÑ±â)";
 
		}else{
			mbox.Mute(1);
			document.all.strMuteStatus.innerHTML = "Mute On (¼Ò¸®²ô±â)";
		}
  }
}
function Play_Pause(name){
  if(playStateInfo == 2){
		mPause();
	}else{
		mPlay();
	}
}
function mPlay(){ 
try{
	if(typeof mbox == 'object') 
	//mbox.Play(); 
	candy_alert("½ºÆ®¸®¹Ö ¼­ºñ½º¸¦ Àá½Ã ÁßÁöÇÕ´Ï´Ù. ¸¹Àº ¾çÇØ¹Ù¶ø´Ï´Ù.","home");
// 	if(mbox.GetVersion) mbox.Play(); 
	}catch(e){}
}
function mStop(){
try{
 	if(typeof mbox == 'object') mbox.Stop(); 

// 	if(mbox.GetVersion) mbox.Stop(); 
	}catch(e){}
}
function mPause(){
try{
	if(typeof mbox == 'object')	mbox.Pause(); 
	}catch(e){}
}
function movePrevious(){
	if(playIdx > 0){
		playIdx--; setPlayMusic(playIdx);
	}
	else
		candy_alert("Ã³À½°îÀÔ´Ï´Ù");
}
function moveNext(){
	if(playIdx < pListArr.length - 1){
		playIdx++; setPlayMusic(playIdx);
	}
	else
		candy_alert("¸¶Áö¸·°îÀÔ´Ï´Ù");
}
function next(){
	
/*
ÇÃ·¹±×°¡ 0 ÀÌ¸é. ÁßÁö 
ÇÃ·¹±×°¡ 1 ÀÌ¸é ÇöÀç °î ÇÃ·¹ÀÌ
ÇÃ·¹±×°¡ 2 ÀÌ¸é ´ÙÀ½°î ÇÃ·¹ÀÌ 
*/

//	if(document.MusicPlayfrm.rdoRepeat[0].checked) 
//		RepeatFlag = 0;
//	else if(document.MusicPlayfrm.rdoRepeat[1].checked) 
//		RepeatFlag = 1;
//	else if(document.MusicPlayfrm.rdoRepeat[2].checked) 
//		RepeatFlag = 2;

	if(rdoRepeat=="0") 
		RepeatFlag = 0;
	else if(rdoRepeat=="1") 
		RepeatFlag = 1;
	else if(rdoRepeat=="2") 
		RepeatFlag = 2;


	if(RepeatFlag == 0)
	{
		return;
	} 
	if(RepeatFlag == 1){
		mStop(); 
		setPlayMusic(playIdx);
	}else if(RepeatFlag == 2 && playIdx == pListArr.length - 1){ 
		setPlayMusic(0);
	}else if(RepeatFlag == 2 && playIdx < pListArr.length - 1){ playIdx++; setPlayMusic(playIdx);}

}
var playIdx = 0;
var listIdx = -1;
var pListArr = new Array;
var cPlayArr = new Array;

var install_one=0;
function CandyRingSessionLoader(idx)
{
//	if(install_one==1){
	//top.location.reload();	
	try{
			document.body.removeChild(mbox);
	}catch(e){}
/*
			var newobj=document.createElement("<OBJECT ID=\"mbox\" WIDTH=0 HEIGHT=0 onreadystatechange=\"setPlayMusic("+idx+")\" CLASSID=\"CLSID:7A02704D-EAC8-45AF-B408-27D6FBA6C26D\" CODEBASE=\"/common/ax/CandyBarBGM.cab#version=1,0,0,2\" style=\"display:none;visibility:hidden\"></OBJECT>");
			document.body.appendChild(newobj);
*/	
	//setTimeout("setPlayMusic("+idx+")",1);
//	}
//top.ifrm_hidden.location.href="/FRM/shop/ring/CandyRingLoader.php?idx="+idx;
//	top.location.reload();	
}

function CandyRingLoader(idx)
{
	return;
	install_one++;
try{
		document.body.removeChild(mbox);
}catch(e){}
/*
		var newobj=document.createElement("<OBJECT ID=\"mbox\" WIDTH=0 HEIGHT=0 onreadystatechange=\"CandyRingSessionLoader("+idx+")\" CLASSID=\"CLSID:7A02704D-EAC8-45AF-B408-27D6FBA6C26D\" CODEBASE=\"/common/ax/CandyBarBGM.cab#version=1,0,0,2\" style=\"display:none;visibility:hidden\"></OBJECT>");
		document.body.appendChild(newobj);
*/
//		setTimeout("document.location.reload();",1);

}


function addPlayInfo(strid, title, pname){
//		showdiv('hidden');
		listIdx++;
		pListArr[listIdx] = new Array;
		pListArr[listIdx][0] = strid;
		pListArr[listIdx][1] = title;
		pListArr[listIdx][2] = pname;
//		showdiv('visible');
}
function setOnePlayInfo(strid, title, pname){
		showdiv('hidden');
		pListArr[0] = new Array;
		pListArr[0][0] = strid;
		pListArr[0][1] = title;
		pListArr[0][2] = pname;
		showdiv('visible');
}

function parent_setOnePlayInfo(){
		//parent.showdiv('hidden');
		pListArr[0] = new Array;
		pListArr[0][0] = parent.pListArr[0][0];
		pListArr[0][1] = parent.pListArr[0][1];
		pListArr[0][2] = parent.pListArr[0][2];
		//parent.showdiv('visible');
}

function playSong(){
//	any_open("/POP/shop/ring/ring_gift.php?GO=shop&mode=buy&subscribers=0",100,100,'n','notsale','n');
				document.all.cSong.innerHTML = '°³ÆíÀ» À§ÇØ ¼­ºñ½º¸¦ Àá½Ã Áß´ÜÇÕ´Ï´Ù. ¾çÇØ¹Ù¶ø´Ï´Ù. ¼­ºñ½º ÁßÁö 5¿ù12ÀÏ~';
		return false;
/// ¼­ºñ½º Á¤Áö
		if(cPlayArr.length == 0) return
		var strid = cPlayArr[0];
		if(strid == '')
		{
			candy_alert('ÇØ´ç °îÀÇ STRID  Á¤º¸°¡ ¾ø½À´Ï´Ù.');
			// next(); 	// °î Á¤º¸°¡ ¾øÀ» °æ¿ì ´ÙÀ½ °îÀ¸·Î(¹æ¾îÄÚµå)
		}else{
    		if(typeof mbox == 'object') mbox.MusicInfo(strid);
			showPlayMusicInfo();
 			return true; 
		}
		return false;
}

function setPlayMusic(idx){
			setTimeout('playSong()',0);

//	if(!getCookie("setN")){
//	parent.logining();
//	return false;
//listenMode =1;
//	}
	if (!mbox.GetVersion) {
//		CandyRingLoader(idx);
	}else{
	if(install_one==1){
//	top.location.reload();	
	}
//
try{
		mStop();	
	switch(window.name){
		case "RING_A" : {parent.RING_B.mStop();break;}	
		case "RING_B" : {parent.RING_A.mStop();break;}	
		case "ringWindow2" : {parent.ringWindow.mStop();break;}	
		case "ringWindow" : {parent.ringWindow2.mStop();break;}	
		case "minicontent" : {parent.mStop();break;}
		default : {minicontent.mStop();break;}
	}
}catch(e){}		
	
//
		if(pListArr.length <= idx)
		{
			var strWrongIdx = "ÀüÃ¼ " + pListArr.length + "Áß " + idx + "¹øÂ° °îÀº  ÇÃ·¹ÀÌ ÇÒ¼ö ¾ø½À´Ï´Ù. ";
 
			candy_alert(strWrongIdx);
			return ;
		}
		setSongInfo(true); //ÇÃ·¹ÀÌ ÁØºñÁß ¸àÆ®
		playIdx = idx;
		cPlayArr = pListArr[playIdx];
		setTimeout('playSong()',0);

	}
}
function setSongInfo(ready,ns){

	  	if(ready)
		{
			document.all.cSong.innerHTML = 'ÇÃ·¹ÀÌ ÁØºñÁß';
		}else{
			if(cPlayArr[1])
			{
				switch(ns){
					case 1:{document.all.cSong.innerHTML = ('<font color=#FF0000>Àá½Ã¸ØÃã:: </font>'+cPlayArr[1] + ' - ' + cPlayArr[2] + '<font color=#FF0000> ::Àá½Ã¸ØÃã</font>');break;}
					case 2:{document.all.cSong.innerHTML = (cPlayArr[1] + ' - ' + cPlayArr[2]);break;}
					case 4:{document.all.cSong.innerHTML = ('<font color=#FF0000>Á¤ÁöµÊ:: </font>'+cPlayArr[1] + ' - ' + cPlayArr[2]+'<font color=#FF0000> ::Á¤ÁöµÊ</font>');break;}
					default:{document.all.cSong.innerHTML = (cPlayArr[1] + ' - ' + cPlayArr[2]);break;}
					}
			}else{
				document.all.cSong.innerHTML = 'ÇÃ·¹ÀÌ ÁØºñÁß';
			}
		}
try{
		if(slide_use==2)ShowHighighlight(playIdx);
	}catch(e){}
		

}

function showPlayMusicInfo(){
	setSongInfo(false);
}

function displayControlIcon(value){
	switch(value){
		case 0 :
			break;
		case 1 :
			// pause visualization
			break;
		case 2 :
			break;
		case 3 :
			break;
		default :
			break;
	}
}

function showMusicDetailInfo(){
	  var bit = parseInt(mbox.GetBitRate() / 1000);
	  var Fre = parseInt(mbox.GetFrequency() / 1000);
	  //document.all.p_rate.innerHTML = bit+'kbps ';
}


/******************************* EVENT ********************************/
function managePlayStateChange(os, ns)
{
	var strStatus="";
	switch (ns)
	{
		case 0:
			strStatus = "NULL";
			break;
		case 1:
			strStatus = "Pause";
			toggle_icon(0);
			setSongInfo(false,ns);
			break;
		case 2:
			strStatus = "Playing";
			setSongInfo(false,ns);
			toggle_icon(1);
			break;
		case 3:
			strStatus = "PlayEnd";
			toggle_icon(0);
			break;
		case 4:
			strStatus = "Stop";
			toggle_icon(0);
			setSongInfo(false,ns);
			break;
		case 5:
			strStatus = "Seeking";
			break;
		case 6:
			strStatus = "Seeking";
			break;
		case 7:
			strStatus = "DownLoad";
			break;
		case 8:
			strStatus = "DownLoad";
			break;
		case 9:
			strStatus = "Buffering";
			break;
		case 10:
			strStatus = "Buffering";
			break;
	}

try{
 	document.all.strPlayStatus.innerHTML = strStatus;
}catch(e){}
}

function managePositionEvent(np){

	checkListenFlag(np);
	if(dragApproved==false)mvTracker(np);
}

function manageErrorEvent(iErrorStatus)
{

/*
	WACORE_ERROR_SUCCESS	= 0,
	WACORE_ERROR_FILELOADERR,
	WACORE_ERROR_DEVICEERR,
	WACORE_ERROR_CONNECTERR,
	WACORE_ERROR_PLAYERR,
	WACORE_ERROR_MEMORYERR,
	WACORE_ERROR_CACHEERR
*/
	var strError="";
	switch(iErrorStatus)
	{
		case 0:
			strError = "No Error";
			break;
		case 1:
			strError = "ÆÄÀÏ ·Îµå ¿¡·¯";
			break;
		case 2:
			strError = "µð¹ÙÀÌ½º ¿¡·¯";
			break;
		case 3:
			strError = "ÄÁ³ØÆ® ¿¡·¯";
			break;
		case 4:
			strError = "ÇÃ·¹ÀÌ ¿¡·¯";
			break;
		case 5:
			strError = "¸Þ¸ð¸® ¿¡·¯";
			break;
		case 5:
			strError = "Ä³½¬ ¿¡·¯";
			break;
	}
//	document.all.strErrorStatus.innerHTML = strError;
}
/******************************* EVENT ********************************/

function checkListenFlag(sec){

//  if(document.MusicPlayfrm.listenMode[0].checked)
  if(listenMode=="0")
     listenFlag  = 0;
  else 
     listenFlag  = 1;

  if(sec > 60 && listenFlag == 1){ 
		mStop(); 
//		var answer=candy_confirm("60ÃÊ µè±â¸ðµåÀÔ´Ï´Ù.\r\n·Î±×ÀÎÇÏ½Ã¸é ÀüºÎ µéÀ¸½Ç ¼ö ÀÖ½À´Ï´Ù.\r\n·Î±×ÀÎÇÏ½Ã°Ú½À´Ï±î?");
//		if(answer) parent.logining();
  }
}

// Position Move
function PlayPosition(iPosition)
{
	dragApproved=false;
	if( mbox.CurrentPosition >= mbox.GetPlayTime() )
		candy_alert('ÀüÃ¼ ÇÃ·¹ÀÌ ½Ã°£À» ³Ñ°Ü¼­´Â ÀÌµ¿ÇÒ¼ö ¾ø½À´Ï´Ù');

	mbox.CurrentPosition = iPosition;
}


function GetMusicBitRate()
{
	candy_alert(mbox.GetBitRate());
}

function GetMusicChannel()
{
	candy_alert(mbox.GetChannel());
}

//°ø¹éÃ¼Å©
function space(str)
{
    var index,len
    while(true)
    {
      index = str.indexOf(" ");
      if (index == -1)
      break;
      len = str.length;
      str = str.substring(0,index) + str.substring((index + 1),len);
    }

    return str.length;
}

function setVol(){
//	var x = document.MusicPlayfrm.vol.value;
	var x = document.rankform.vol.value;
	if(space(x) != 0 ) document.mbox.Volume = x;
}

function showdiv(arg){
if(slide_use==1){
	document.all.Duration_Bar.width = 0;
	document.all["MENU1"].style.top = event.clientY - event.offsetY + document.body.scrollTop -46;
	document.all["MENU1"].style.left = event.clientX - event.offsetX + document.body.scrollLeft+20;
	document.all["MENU1"].style.visibility = arg;
}
}
function toggle_icon(arg){
if(slide_use==1){
	switch(arg){
		case 0:{
			neoplayer.cells(0).style.display = 'block';
  			neoplayer.cells(1).style.display = 'none';
  			break;
  		}
		case 1:{
			neoplayer.cells(0).style.display = 'none';
  			neoplayer.cells(1).style.display = 'block';
  			break;
  		}
  	}

}else if(slide_use==0){
	switch(arg){
		case 0:{
//			neoplayer.cells(2).style.display = 'block';
//  			neoplayer.cells(3).style.display = 'none';
  			break;
  		}
		case 1:{
//			neoplayer.cells(2).style.display = 'none';
//  			neoplayer.cells(3).style.display = 'block';
  			break;
  		}
  	}

}else{

}
}	

function mvTracker(np)   
{
var cue_width = ((slide_use==2)?223:113);
if(slide_use==2){
document.all.strPosition.innerHTML = np+"/"+mbox.GetPlayTime();
}

if(slide_use>0 && dragApproved == false){
	var size = Math.round(cue_width * np/mbox.GetPlayTime()); //113,223
	document.all.Duration_Bar.width= size;
}
//	setTimeout('mvTracker()',0);
}
	function initMouseDragEvent(length) 
	{
		var durTime = mbox.GetPlayTime();

//		iex = event.clientX;
//		iey = event.clientY;
//		tempx = Slide_Bar.style.pixelLeft;
//		tempy = Slide_Bar.style.pixelTop;
		dragApproved = true;
		
		var mov = parseInt(event.offsetX);
		if(mov<0)mov=0;
		
		if(length==0){
			 CueLength= 113;
		}else{
 			 CueLength=223;
		}

		if(mov>CueLength)mov=CueLength;
		document.all.Duration_Bar.width= mov;
		Cue =Math.round(durTime*(mov/CueLength));  
 		return false;
		
//		if(document.all && dragApproved == true) 
//		{
//			document.onmouseup = new Function('dragApproved=false;PlayPosition(Cue)');
//		}
	}

	function initSlideDragEvent(length) 
	{
		iex = event.clientX;
		iey = event.clientY;
		tempx = Slide_Bar.style.pixelLeft;
		tempy = Slide_Bar.style.pixelTop;
		dragApproved = true;
		
		
		if(length==0){
			document.onmousemove = SlideControl0;
		}else{
			document.onmousemove = SlideControl1;
		}
		
//		if(document.all && dragApproved == true) 
//		{
//			document.onmouseup = new Function('dragApproved=false;PlayPosition(Cue)');
//		}
	}
	function SlideControl0() 
	{
		var durTime = mbox.GetPlayTime();
		var CueSPoint = Duration_Bar.style.pixelLeft;
		var tempx = Slide_Bar.style.pixelLeft;
		var CueLength = 113;
		if(dragApproved == true) 
		{
//			var mov = tempx + event.clientX - iex;
			var mov = parseInt(event.offsetX);
			if(mov<0)mov=0;
 			if(mov>113)mov=CueLength;
				document.all.Duration_Bar.width= mov;
				Cue =Math.round(durTime*(mov/CueLength));  
			return false;
		}
	}
	function SlideControl1() 
	{
		var durTime = mbox.GetPlayTime();
		var CueSPoint = Duration_Bar.style.pixelLeft;
		var tempx = Slide_Bar.style.pixelLeft;
		var CueLength = 223;
		if(dragApproved == true) 
		{
			//var mov = tempx + event.clientX - iex;
			var mov = parseInt(event.offsetX);
			if(mov<0)mov=0;
 			if(mov>223)mov=CueLength;
			document.all.Duration_Bar.width= mov;
			Cue =Math.round(durTime*(mov/CueLength));
		return false;
		}
	}

function subpause(name)
{
switch(name){
	case "parent":{
			try{
				parent.Play_Pause();
				break;
			}catch(e){}
			}	
	case "minicontent":{
			try{
				minicontent.Play_Pause();
				break;
			}catch(e){}
			}	
	
	
}
}
	function initVolumeMouseDragEvent() 
	{
			var vmov = parseInt(event.offsetX);
			if(vmov<0)vmov=0;
 			if(vmov>40)vmov=38;
			volumeSize.style.width = vmov;
			var volume = parseInt((vmov*100)/volLength);
			document.mbox.Volume = volume;
	}
	function initVolumeDragEvent() 
	{
		iex = event.clientX;
		iey = event.clientY;
		tempx = volumeBar.style.pixelLeft;
		tempy = volumeBar.style.pixelTop;
		dragApproved = true;
		document.onmousemove = volumeControl;
		if(document.all) 
		{
			document.onmouseup = new Function('dragApproved=false');
			//document.onselectstart = new Function('dragApproved=false');
		}
	}
	function volumeControl() 
	{
		if(dragApproved == true) 
		{
			var vmov = parseInt(event.offsetX);
			if(vmov<0)vmov=0;
 			if(vmov>40)vmov=38;
//				volumeBar.style.pixelLeft = 213;
//				per = (tempx + event.clientX - iex - volSPoint) / volLength;
//				per = Math.ceil(2500*(per+0.01));
//				if(per > 2450) per = 2500;
//				if(per < 100) per = 1;
				volumeSize.style.width = vmov;
				var volume = parseInt((vmov*100)/volLength);
				document.mbox.Volume = volume;
//				mp.Volume = volume;

			return false;
		}
	}

	function ToggleList(arg){

	switch (arg){
	case "Y": // ¸®½ºÆ® °¨Ãß±â
//		this.resizeTo(300,191);
//		PlayListBox.resizeTo(270,0);
		this.resizeTo(300,206);
		PlayListBox.resizeTo(270,15);
  		Expand_List.cells(0).style.display = 'block';
  		Expand_List.cells(1).style.display = 'none';
  		break;

	case "N": // ¸®½ºÆ® º¸¿©ÁÖ±â
//		document.all('PlayListBox').src="candybar_mplayer_list.php?subscribers="+s_arg;
//		this.resizeTo(300,400);
//		PlayListBox.resizeTo(270,194);
		this.resizeTo(300,415);
		PlayListBox.resizeTo(270,209);
  		Expand_List.cells(0).style.display = 'none';
  		Expand_List.cells(1).style.display = 'block';
		if(toggleFlag==false){
		parent.PlayListBox.location.reload();
//		toggleFlag=true;
		}
  		break;

		}
	}

function ShowHighighlight(turn){
	for( var x =0 ; x < pListArr.length ; x++)
		{ 
			if(x==turn){   
					PlayListBox.document.all('CandyRing'+ x).style.color='#279BEF';  
				}else{  
					PlayListBox.document.all('CandyRing'+ x).style.color='black'; 
				}
		}
}
