/*
 * A simple digital clock
 * DZ - 3/27/2010
 */
function showTime() {
	  //setInterval("DT.innerHTML=new Date().toLocaleString();",1000);
	var curTime = new Date();
	var month = curTime.getMonth() + 1;
	var date = curTime.getDate();
	var year = curTime.getFullYear();
	var dayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var day = dayArray[curTime.getDay()];
	var hour = curTime.getHours();
	var minute = curTime.getMinutes();
	var apm;
	
	if (minute < 10) minute = "0" + minute;

	if (hour < 12) {
		if (hour == 0) hour = 12;
		apm = "AM";
	}
	else {
		if (hour >=13 ) hour -= 12;
		apm = "PM";
	}
	
	document.getElementById("DT").innerHTML = month + "/" + date + "/" + year + " | " + day + " | " + hour + ":" + minute + " " + apm;
	setTimeout("showTime()", 1000);
}

/*
 * A timer for change to next song
 * DZ - 3/30/2010
 * Parameters:
 *      par: optional, if set to 1, will force the player to retrieve next clip
 */
function mvsDaemon(repeatSingle) {
	
	// for the first load: display the top clip
	if (firstLoad == 1) {
		firstLoadTry++;
		clipIndex = 0;
		if (getPlayerState() != 1 && getPlayerState()!= 2 && getPlayerState() != 3) {
			updateSubtitle(mvsSinger[clipIndex], mvsTitle[clipIndex], mvsPublishDate[clipIndex]);
			loadNewVideo(album[clipIndex], 0);
		}
		if (firstLoadTry == 10)
			firstLoad = 0; // give up after 10 tries
	}

	else {
		// Enforce the station is run
		if (getPlayerState() != 1 && getPlayerState()!= 2 && getPlayerState() != 3) { // Possible values are unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5).
			
			// next random clip, don't repeat current song
			if (repeatSingle != 1) { // only do this if not repeating a single song
				var currentIndex = clipIndex;
				while (currentIndex == clipIndex) {
					clipIndex = Math.floor(Math.random() * album.length);
					clipIndex %= album.length;
				}		
				updateSubtitle(mvsSinger[clipIndex], mvsTitle[clipIndex], mvsPublishDate[clipIndex]);
			}
			
			loadNewVideo(album[clipIndex], 0);
		}

	}
		
	// Check every 5 seconds
	setTimeout("mvsDaemon(repeatSingle)", 5000); 	
}


