// <a href="/music/song.php?song=857&PHPSESSID=8066qhfcd6inp6ovdrsdbl8hb0" target="_top" class="current">




function NowPlayingController() {
  // Methods
	this.updatePolledSongId = NowPlayingController_updatePolledSongId;
	this.checkNewSong = NowPlayingController_checkNewSong;
	this.initialize = NowPlayingController_initialize;
	this.setStoredSongId = NowPlayingController_setStoredSongId;
	this.updateDOM = NowPlayingController_updateDOM;
	
	// Properties
	this.storedSongId = null;
	this.polledSongId = null;
	this.doneInit = false;
};


function NowPlayingController_initialize() {
	nowPlaying.updatePolledSongId();
	nowPlaying.setStoredSongId(nowPlaying.polledSongId);
	var tempSongId = 0;
	new Ajax.Request('http://www.folkalley.com/player/proc/nowplaying.php',
  {
    method:'post',
    parameters: {process: 'getCurrentSongId'},
    onComplete:function(resp){
    	songId = resp.responseText;
			new Ajax.Request('http://www.folkalley.com/player/proc/nowplaying.php',
			{		
				method:'post',
				parameters: {process: 'getSongDetails', songId: songId},
				onComplete:function(resp){
					songInfo = resp.responseText.evalJSON();
					//songInfo = resp.responseText;
					if (songInfo.artist_name != null) {
						artistText = '<a href="/music/song.php?song='+nowPlaying.polledSongId+'" target="_top" class="current">'+songInfo.artist_name+'</a>';
						songText = '<a href="/music/song.php?song='+nowPlaying.polledSongId+'" target="_top" class="current">'+songInfo.song+'</a>';
						$('artistArea').innerHTML = artistText;
						$('songArea').innerHTML = songText;
					}
				}
			})
		} 
  });
	

	
	
	nowPlaying.doneInit = true;
	nowPlaying.updateDOM();
}


function NowPlayingController_setStoredSongId(id) {
	nowPlaying.storedSongId = id;
}

function NowPlayingController_checkNewSong() {
	nowPlaying.updatePolledSongId();
	if (nowPlaying.polledSongId != nowPlaying.storedSongId) {
		//setTimeout('Effect.Fade("artistArea")', 1);
		//setTimeout('Effect.Fade("songArea")', 1);
		nowPlaying.setStoredSongId(nowPlaying.polledSongId);
		nowPlaying.updateDOM();
	}
	/*
	else {
		nowPlaying.updateDOM();
	}
	*/
}

function NowPlayingController_updatePolledSongId() {
	new Ajax.Request('http://www.folkalley.com/player/proc/nowplaying.php',
  {
    method:'post',
    parameters: {process: 'getCurrentSongId'},
    onComplete:function(resp){
    	songId = resp.responseText;
			nowPlaying.polledSongId = songId;
		} 
  });
}

function NowPlayingController_updateDOM() {	
	//setTimeout('Effect.Appear("artistArea")', 3000);
	//setTimeout('Effect.Appear("songArea")', 3000);
	new Ajax.Request('http://www.folkalley.com/player/proc/nowplaying.php',
  {
    method:'post',
    parameters: {process: 'getSongDetails', songId: nowPlaying.storedSongId},
    onComplete:function(resp){
    	songInfo = resp.responseText.evalJSON();
    	//songInfo = resp.responseText;
    	if (songInfo.artist_name != null) {
    		artistText = '<a href="/music/song.php?song='+nowPlaying.storedSongId+'" target="_top" class="current">'+songInfo.artist_name+'</a>';
    		songText = '<a href="/music/song.php?song='+nowPlaying.storedSongId+'" target="_top" class="current">'+songInfo.song+'</a>';
				setTimeout('$(\'artistArea\').innerHTML = artistText', 1000);
				setTimeout('$(\'songArea\').innerHTML = songText', 1000);
			}
		}
  });
}


