koykemar 0 Newbie Poster

I am trying to create a music web player that changes song automatically, however the song is instead repeated and whenever next is click, and some codes are executed to stop the current song and start the next, the current song pauses for about 1 sec instead... can some please tell me how to solve these issues? oh, if i remove the "//alert("song is about to play"); line, the song only plays for about a sec and stop.

Here is the code:

<script type="text/javascript">
function cselector(ctype)
{
	num=1;
	for(count=num;count<10;count++){
		//alert("cselector selected="+ctype);
		//alert(count);
		switch(num){
			case 1:
				content=document.getElementsByTagName("audio")[0];
				//test=content.duration;
				//alert(test);
				op(ctype,content,count);
			break;
			case 2:
				content=document.getElementsByTagName("audio")[1];
				op(ctype,content,count);
				test=content.duration;
				alert(test);
			break;
			case 3:
				content=document.getElementsByTagName("audio")[2];
				op(ctype,content,count);
				test=content.duration;
				alert(test);
			break;
			case 4:
				content=document.getElementsByTagName("audio")[3];
				op(ctype,content);
			break;
			case 5:
				content=document.getElementsByTagName("audio")[4];
				op(ctype,content);
			break;
			case 6:
				content=document.getElementsByTagName("audio")[5];
				op(ctype,content);
			break;
			case 7:
				content=document.getElementsByTagName("audio")[6];
				op(ctype,content);
			break;
			case 8:
				content=document.getElementsByTagName("audio")[7];
				test=content.duration;
				alert(test);
				op(ctype,content);
			break;
			case 9:
				content=document.getElementsByTagName("audio")[8];
				op(ctype,content);
			break;
			case 10:
				content=document.getElementsByTagName("audio")[9];
				op(ctype,content);
			break;
			}	
	}
}


function op(ctype,content,count)
{
	//alert("parameters pushed:",+ctype+content);
	//count=0;
	while(count<10){
		switch(ctype){
			case 1:
				//alert("content about to be played");
				content.play();
			break;
			case 2:
				//alert("content about to be paused");
				content.pause();
			break;
			case 3:
				content.pause();
				atend=content.duration;
				content.currentTime(atend);
				next(count);
			break;
			case 4:
			//
			break;	
		}
	}
}

function next(i)
	{
			var song=document.getElementsByTagName("audio")[i];
			var num=i+1;
			var song=document.getElementsByTagName("audio")[num];
			op(1,song,num);			
	}

</script>

/*piece of html*/
<div class="btn" onclick="cselector(1)">PLAY</div>
                <div class="btn" onclick="cselector(2)">PAUSE</div>
                <div class="btn" id="nextbtn" onclick="cselector(3)">NEXT</div>
                <div class="btn">PREVIOUS</div>