// JavaScript Document

function yes(j) {
	   if(j && j.now)				/*** First IF statement writes the "NOW PLAYING" song at the top of the list ***/
		{
			document.write(
				"<ul><li><a href='http://yes.com/i"+j.id+"' target='_blank'><img src='img/buttons/itunes.gif' style='margin-top:14px;' /></a><strong>NOW PLAYING: </strong><br />"+j.now.artist+" - "+j.now.song+"</li></ul>"
			);
		}
	   
	   if(j && j.songs)				/*** Second IF statement writes the rest of the recent songs into the list and does fancy date work ***/
	   {
			var html = "<ul>";
			for(var i=1;i<j.songs.length;i++)
			{
				var s = j.songs[i];
				var d = s.at;								// Set the Variable
				var stringParts = d.split(" ");				// Split into two sections on the space between date and time making an array of two parts
				var dateParts = stringParts[0].split("-");	// Split the date into a three part array on the dashes
				var timeParts = stringParts[1].split(":");	// Split the time into a three part array on the colons
				var iYear = dateParts[0];
				var iMonth = dateParts[1];
				var iDay = dateParts[2];
				var iHour = timeParts[0];
				var iMinute = timeParts[1];
				var iSecond = timeParts[2];	
				var iampm = 'am';
				if (iHour == '00') {						// Replacing ARMY time with regular time
					iHour = '12';	
				}
				else if (iHour == '12') {
					iampm = 'pm';
				}
				else if (iHour == '13') {
					iHour = '1';
					iampm = 'pm';	
				}
				else if (iHour == '14') {
					iHour = '2';	
					iampm = 'pm';	
				}
				else if (iHour == '15') {
					iHour = '3';	
					iampm = 'pm';	
				}
				else if (iHour == '16') {
					iHour = '4';	
					iampm = 'pm';	
				}
				else if (iHour == '17') {
					iHour = '5';	
					iampm = 'pm';	
				}
				else if (iHour == '18') {
					iHour = '6';	
					iampm = 'pm';	
				}
				else if (iHour == '19') {
					iHour = '7';	
					iampm = 'pm';	
				}
				else if (iHour == '20') {
					iHour = '8';	
					iampm = 'pm';	
				}
				else if (iHour == '21') {
					iHour = '9';	
					iampm = 'pm';	
				}
				else if (iHour == '22') {
					iHour = '10';	
					iampm = 'pm';	
				}
				else if (iHour == '23') {
					iHour = '11';	
					iampm = 'pm';	
				}
				html += "<li><a href='http://yes.com/i"+s.id+"' target='_blank'><img src='img/buttons/itunes.gif' /></a>"+iHour + ':' + iMinute+ '<small>' +iampm+ '</small> on '+iMonth + '/' + iDay+" - "+s.by+" - "+s.title+"</li>";
			}
		html += "</ul>";
		document.write(html);
	   }   
}