﻿function getListenLiveCurrentSong() {
	$.getJSON($("#ListenLive").attr("proxyserviceurl")
				, { ParametersJson: $("#ListenLive").attr("proxyserviceparameters"), CacheBustDateTimeStamp: new Date().toString() }
				, function(json) {
					json = JSON.parse(json.d);
					if ((!json.Error) && (json.Songs.length == 1)) {
						$("#ListenLive .CurrentSong").html(json.Songs[0].title);
						$("#ListenLive .CurrentArtist").html(json.Songs[0].artist);
					} else {
						$("#ListenLive .CurrentSong").html('error');
						$("#ListenLive .CurrentArtist").html('error');
					}
				}
		);
}

$('#ListenLive').ready(function() {

	$('#ListenLive .ListenLink').click(function(ev) {
		var url = $('#ListenLive .ListenLink').attr('href');
		window.open(url, 'listenlive', 'width=680,height=511,status=no,resizable=no,scrollbars=no;');
		return false;
	});

	getListenLiveCurrentSong();

	var getListenLiveCurrentSongSetIntervalId;
	if (getListenLiveCurrentSongSetIntervalId == undefined) {
		getListenLiveCurrentSongSetIntervalId = setInterval('getListenLiveCurrentSong();', 15000);
	}

});

