

var PlayaImpl = {
	toggle :  function(el, tuneindex) {
		if(el.style.fontWeight=="") 
			this.start_Tune(el.id)
		else
			 this.end_Tune(el.id);
	},
	start_Tune : function(tuneindex) {
		Playa.doJump(tuneindex);
		this.state=1;
		this.startstop();
		this.unboldTheOtherTunes(tuneindex);
	},
  end_Tune : function(currentTuneIndex) {
  	document.getElementById(currentTuneIndex).style.fontWeight="";
  	document.getElementById(currentTuneIndex).style.color="#0084cb";
  	this.state=0;
  	this.startstop();
		Playa.doStop();
	},
	unboldTheOtherTunes : function(currentTuneIndex) {
		for(var i=0;i<Playa.playlistSize;i++) {
			if(i!=currentTuneIndex) {
				document.getElementById(i).style.fontWeight="";
				document.getElementById(i).style.color="#0084cb";
			}
			else {
				document.getElementById(i).style.fontWeight="bold";
				document.getElementById(i).style.color="#8EC6E5";
			}
		}
	},
	startstop :  function() {
			if (this.state == 1) {
				this.ms=0;
				then = new Date();
				then.setTime(then.getTime() - this.ms);
			}
			else {
				this.resetClock();
			} 
		},
		display : function() {
			setTimeout("PlayaImpl.display();", 50);
			if (this.state == 1)  {
				this.doClockStuff();
			}
		},
		doClockStuff  : function() {
			now = new Date();
				this.ms = now.getTime() - then.getTime();
				try {
					document.getElementById("time").innerHTML = this.time();
				}
				catch(ex) {
					
				}
		},
		resetClock : function() {
			document.getElementById("time").innerHTML = "00:00";
			this.ms=0;
		},
		two : function(x) {
			return ((x>9)?"":"0")+x;
		},
		time :  function() {
				var sec = Math.floor(this.ms/1000);
				var min = Math.floor(sec/60);
				sec=sec % 60;
				return this.two(min) + ":" + this.two(sec);
		}
};
PlayaImpl.ms = 0;
PlayaImpl.state = 0;
PlayaImpl.display();

Playa.onStateChange = function() {
	var sTitle="Now playing: ";
	if (Playa.path == "") {
		sTitle += Playa.title;
	} else {
		sTitle += "<"+"a href=\"" + Playa.path + "\" target=\"_blank\" title=\"Click to download\"" + ">" + Playa.title + "<" + "/a" + ">&nbsp;<span id=\"time\"></span>";
	}
	document.getElementById("songTitle").innerHTML = sTitle;
	try {
		PlayaImpl.unboldTheOtherTunes(Playa.playListPosition);
		PlayaImpl.startstop();
	}
	catch(ex){
	
	}
};
Playa.onPlayStop = function() {
	setTimeout('document.getElementById("songTitle").innerHTML="No tune is currently playing";',20);
};
