$(document).ready(function(){
	setInterval ( "updateFrontPage()", 60000 );
});

function updateFrontPage() {
	//First, need to check and see if the current playing track is different. Let's do this by comparing the existing track name to the latest one in the DB.
	var currentSongTitle = $("#nowPlayingSongTitle").text();
	//Now we need to do a JSON request to see if the actual song is different
	$.getJSON("/assets/php/serverside/nowPlayingLookup.php", { currentSongTitle: currentSongTitle }, function(data) {
			if (data.trigger == "yes") {
				//If the trigger is yes, then pull the data and update it on the page
				//fade out the now playing box
				$("#nowPlayingBox").fadeOut("normal", function() {
					$("#nowPlayingArtist").empty();
					$(".requestedBy").remove();
					$("#nowPlayingArtist").append(data.artist);
					$("#nowPlayingAlbumImg").empty();
					$("#nowPlayingAlbumImg").append('<img src=\"cdcovers/' + data.albumImg + '\" class=\"album\">');
					$("#nowPlayingAlbumImg").attr("href", data.albumURL);
					$("#nowPlayingSongTitle").empty();
					$("#nowPlayingSongTitle").append(data.song);
					$(".addToWishlist").attr("id","albumId_" + data.albumId + "");
					$("#nowPlayingAlbumDetails").empty();
					$("#nowPlayingAlbumDetails").append('From <a href=\"' + data.albumURL + '\">' + data.albumName + '</a>');
					if (data.requestNum != "0") {
						//If this was a request, append the request text
						$("#nowPlayingSongTitle").append(data.requestedBy);
					}
					//Post the reviews
					$("#nowPlayingReview").empty();
					$("#nowPlayingReview").append('<a href=\"reviews.php?albumId=' + data.albumId + '\" title=\"Read reviews for ' + data.albumName + ' by ' + data.artist + ' (' + data.numReviews + ' posted)\">' + data.stars + '</a>');
					//fade it back in
					$("#nowPlayingBox").fadeIn("normal");
					//Now, update the song history!
					var counter = 0;
					for (var i = 1; i < 11; i++) {
						var artist = data["x" + i]["artist"];
						var song = data["x" + i]["song"];
						var album = data["x" + i]["album"];
						var albumURL = data["x" + i]["albumURL"];
						$("#songHistory" + counter + "").empty();
						$("#songHistory" + counter + "").append(artist + ' - ' + song + '<BR><div class=\"histDetails\">From <a href=\"' + albumURL + '\">' + album + '</a></div>');
						counter++;
					}
				});
		};
	});
	//update request list
	updateRequestList();
};


