$( document ).ready( function(){
   $( '#history' ).show();
   initPlayingNow()
});
var xml_reference = '';

function initPlayingNow(){
//	alert( window.location.hash );
	$.ajax({
	   type: "GET",
	   url: "../xml/play.xml",
	   dataType: "xml",
	   success: function( xml ) {
	   		xml_reference = xml;
	   		listPlayingNow();
	   }
	}); // $.ajax
} // function initPlayingNow


function listPlayingNow(){
	$( '#onair_data strong' ).empty();
	var thisArtist = '';
	$( xml_reference ).find( 'channel' ).each( function( i ){
		thisArtist = $( this ).find( 'artist' ).text();
		thisSong = $( this ).find( 'song' ).text();
    thisName = $( this ).find( 'name' ).text();
    thisPic = $( this ).find( 'pic' ).text();
    thisShow = $( this ).find( 'show' ).text();
    
   historyArtist_1 = $( this ).find('#history_1').attr('artist');
   historyArtist_2 = $( this ).find('#history_2').attr('artist');
   historyArtist_3 = $( this ).find('#history_3').attr('artist');
   historySong_1 = $( this ).find('#history_1').attr('song');
   historySong_2 = $( this ).find('#history_2').attr('song');
   historySong_3 = $( this ).find('#history_3').attr('song');
   historyTime_1 = $( this ).find('#history_1').attr('time');
   historyTime_2 = $( this ).find('#history_2').attr('time');
   historyTime_3 = $( this ).find('#history_3').attr('time');
   historyImg_1 = $( this ).find('#history_1').attr('img');  if( historyImg_1 == '' ){ historyImg_1 = '../images/history_48x48.png' };
   historyImg_2 = $( this ).find('#history_2').attr('img');  if( historyImg_2 == '' ){ historyImg_2 = '../images/history_48x48.png' };
   historyImg_3 = $( this ).find('#history_3').attr('img');  if( historyImg_3 == '' ){ historyImg_3 = '../images/history_48x48.png' };
   var divHistory = $( 'div#history' );
   $( 'div.history_1', divHistory ).html( '<img src="'+historyImg_1+'" alt="'+historyArtist_1+'"/>'+historyTime_1+'<br/><strong>'+historyArtist_1+'</strong><br/>'+historySong_1 );
   $( 'div.history_2', divHistory ).html( '<img src="'+historyImg_2+'" alt="'+historyArtist_2+'"/>'+historyTime_2+'<br/><strong>'+historyArtist_2+'</strong><br/>'+historySong_2 );
   $( 'div.history_3', divHistory ).html( '<img src="'+historyImg_3+'" alt="'+historyArtist_3+'"/>'+historyTime_3+'<br/><strong>'+historyArtist_3+'</strong><br/>'+historySong_3 );

	 $( '#presenter_name' ).text( thisName ).attr( 'title', thisShow );
	 $( '#presenter_img' ).attr( "style", "background: white url(../doc/mc/" + thisPic + ") top right no-repeat" );
	 $( '#onair_data strong' ).append( thisArtist + ' - ' + thisSong );
	});
	setTimeout("initPlayingNow()", 20000 );
}

