// JSON getTickertape
var gs = window.setInterval("getSong()",20000);
var sam_Message = '';
var sam_artist_objectid = '0';
var jazz_Message = '';
var jazz_artist_objectid = '0';
var world_Message = '';
var world_artist_objectid = '0';


// Define the callback function
function getTickertape(jsonData) { 

		sam_Message  = jsonData.sam.scrolltext;
		sam_artist_objectid  = jsonData.sam.artist_objectid;
		jazz_Message  = jsonData.sam_jazz.scrolltext;
		jazz_artist_objectid  = jsonData.sam_jazz.artist_objectid;
		world_Message  = jsonData.sam_world.scrolltext;
		world_artist_objectid  = jsonData.sam_world.artist_objectid;;

		if(message_sam != sam_Message)
		message_sam = sam_Message;
		if(message_jazz != jazz_Message)
		message_jazz = jazz_Message;
		if(message_world != world_Message)
		message_world = world_Message;
   		
		bObj.removeScriptTag(); 
}

function getSong() {

// The web service call
var req  = 'http://sites.nps.nl/jerome/templates/musicportal/tickertape_multi.js?' + Math.random(); 
//var req  = 'http:/masterclass.nps.nl/tickertape.js?' + Math.random(); 
// Create a new request object
bObj = new JSONscriptRequest(req); 
// Build the dynamic script tag
bObj.buildScriptTag(); 
// Add the script tag to the page
bObj.addScriptTag();

}
// END JSON getTickertape


// ROTATE STATIONS
var rot = window.setInterval("rotateStations()",15000);

function rotateStations() {
	if (window.rotActive == undefined || rotActive == 'jazz') {
		document.getElementById('webradio_jazz').style.display = 'none';		
		document.getElementById('webradio_world').style.display = '';
		window.rotActive = 'world';
	}	
	else if (window.rotActive == 'world') {
		document.getElementById('webradio_world').style.display = 'none';		
		document.getElementById('webradio_sam').style.display = '';
		window.rotActive = 'sam';		
	}
	else if (rotActive == 'sam') {
		document.getElementById('webradio_sam').style.display = 'none';		
		document.getElementById('webradio_jazz').style.display = '';
		window.rotActive = 'jazz';
	}

}
// END ROTATE STATIONS


// TICKERTAPE STUFF
var message_sam = ""; 
var message_jazz = ""; 
var message_world = ""; 

var maxTekens = 35;
function tickerTape() 
{
	// sam
	if ( document.getElementById('nowplaying_sam') != undefined )
		document.getElementById('nowplaying_sam').value = message_sam;
	if (message_sam.length>maxTekens)
		message_sam = message_sam.substring(1, message_sam.length) + message_sam.substring(0, 1);
	// jazz
	if ( document.getElementById('nowplaying_jazz') != undefined )
		document.getElementById('nowplaying_jazz').value = message_jazz;
	if (message_jazz.length>maxTekens)
		message_jazz = message_jazz.substring(1, message_jazz.length) + message_jazz.substring(0, 1);
	// world
	if ( document.getElementById('nowplaying_world') != undefined )
		document.getElementById('nowplaying_world').value = message_world;
	if (message_world.length>maxTekens)
		message_world = message_world.substring(1, message_world.length) + message_world.substring(0, 1);
	
} 
//speed the higher the number, the slower the movement
var s = window.setInterval("tickerTape()", 200); 
// END TICKERTAPE STUFF