function OpenMiastoMuzykiPlayer(s) {
   var w = window.open('http://www.rmfon.pl/play,'+s, "RMFplayerWindow2", 'width=820,height=710,menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no,status=no');
	if (window.focus) {if (w) w.focus()};
}

var NowPlayingHead = {
	url: '/inc/playlista_18.json.txt',
	data: null,
	executer: null,
	now: null,
	next: null,
	currentCover: '',
	fetchInterval: 20,
	fetch: function() {
	  new Ajax.Request(NowPlayingHead.url+'?'+Math.random(), {
		  method: 'get',
		  onSuccess: function (transport) {
			try {
				NowPlayingHead.data = eval('('+transport.responseText+')');
				NowPlayingHead.display();
			} catch (e) {
			}
		  }
      }); 
	},
	display: function() {
		try {
			NowPlayingHead.now = NowPlayingHead.data.find(function(s) { return s.order==0; });
			NowPlayingHead.next = NowPlayingHead.data.find(function(s) { return s.order==1; });

			if (NowPlayingHead.now && !Object.isUndefined(NowPlayingHead.now)) {
				var auth1 = NowPlayingHead.now.author;
				if (!!NowPlayingHead.now.bio) auth1 = '<a href="http://www.rmfon.pl/artysci/'+NowPlayingHead.now.bio+'.html" target="_blank">' + auth1 + '</a>';
				$('tg-teraz-artysta').update(auth1);
				$('tg-teraz-tytul').update(NowPlayingHead.now.title);

				if (NowPlayingHead.now.coverUrl) {
					if (NowPlayingHead.currentCover!=NowPlayingHead.now.coverUrl) {
						NowPlayingHead.currentCover = NowPlayingHead.now.coverUrl;
						$('tg-cover').update('<img src="'+NowPlayingHead.now.coverUrl+'">');
					}
				} else {
					NowPlayingHead.currentCover = '<img src="/img/np-zaslepka.jpg">';
					$('tg-cover').update(NowPlayingHead.currentCover);
				}
			} else {
				$('tg-teraz-artysta').update('');
				$('tg-teraz-tytul').update('');
				$('tg-cover').update('');
			}
			if (NowPlayingHead.next && !Object.isUndefined(NowPlayingHead.next)) {
				var auth2 = NowPlayingHead.next.author;
				if (!!NowPlayingHead.next.bio) auth2 = '<a href="http://www.rmfon.pl/artysci/'+NowPlayingHead.next.bio+'.html" target="_blank">' + auth2 + '</a>';
				$('tg-zachwile-artysta').update(auth2);
				$('tg-zachwile-tytul').update(NowPlayingHead.next.title);
			} else {
				$('tg-zachwile-artysta').update('');
				$('tg-zachwile-tytul').update('');
			} 
		} catch (e) {
		}
	},
	
	start: function() {
		if (NowPlayingHead.executer!==null) NowPlayingHead.executer.stop();
		NowPlayingHead.fetch();
		NowPlayingHead.executer = new PeriodicalExecuter(NowPlayingHead.fetch, NowPlayingHead.fetchInterval);
	},
	stop: function() {
		if (NowPlayingHead.executer) {
			NowPlayingHead.executer.stop();
			NowPlayingHead.executer = null;
		}
	}
}; 

