﻿var _currentSong = "";
var _currentMarquee = null;

$(document).ready(function () {
	GetCurrentPlay();
});

function Popup(sender, width, height) {
	window.open(sender.href, 'popup', 'width=' + width + ',height=' + height);
}

function GetCurrentPlay() {
	$.ajax({
		type: 'GET',
		cache: 'false',
		url: 'EnOndeProxy.aspx',
		dataType: 'text',
		success: function (result) {
			var results = result.split('<br />');
			
			$("#specEnOnde .emission").html(results[1]);
			if (_currentSong != results[0]) {
				_currentSong = results[0];

				if (_currentMarquee == null) {
					$("#specEnOnde .song").html(_currentSong);
				} else {
					_currentMarquee.trigger("stop"); // stop the marquee
					$(".marquee").scrollLeft(268); // reset the marquee position to start
					$("#specEnOnde .song .marquee div").html(_currentSong.replace("</span></a>", "").replace("<a href=\"trouver_une_chanson.aspx\"><span>", "")); // change value of the song
				}

				if (_currentSong.length > 90) {
					setTimeout(StartMarquee, 3000);
				}
			}
			setTimeout(GetCurrentPlay, 30000);
		}
	});
}

function StartMarquee() {
	if (_currentMarquee == null) {
		_currentMarquee = $("#specEnOnde .song a span").marquee("marquee");
	} else {
		_currentMarquee.trigger("start");
	}
}
