var audioURL;
window.onload = function()
{
	audioURL = "http://www.bbc.co.uk/radio1/wm_asx/aod/radio1_hi.asx";
	var currentSetting = System.Gadget.Settings.read("stationPicker");
	if (currentSetting != ""){
		mediaPlayer.url  = currentSetting;}
	else{
		mediaPlayer.url = audioURL;}

	System.Gadget.settingsUI = "Settings.html";
        System.Gadget.onSettingsClosed = SettingsClosed;
}

function SettingsClosed() 
{
	var currentSetting = System.Gadget.Settings.read("stationPicker");
	if (currentSetting != "")
		mediaPlayer.url  = currentSetting;
}

function controlImageClick()
{		
	if(controlImage.src == "images/stop.png"){
		mediaPlayer.controls.stop();}
	else{
		mediaPlayer.controls.play();}
}

function playStateChange(newstate)
{
	switch (newstate){ 
	case 1: // Stopped
		playbackStatus.innerHTML = "Stopped";
		controlImage.src = "images/play.png";
		break;

	case 2: // Paused
		playbackStatus.innerHTML = "Paused";
		controlImage.src = "images/play.png";
		break;
	
	case 3: // Playing
		playbackStatus.innerHTML = "Playing";
		controlImage.src = "images/stop.png";
		break;

	case 6: // Buffering
		playbackStatus.innerHTML = "Buffering";
		break;

	case 7: // Waiting
		playbackStatus.innerHTML = "Waiting";
		break;

	case 8: // Media Ended
		playbackStatus.innerHTML = "Media Ended";
		controlImage.src = "images/play.png";
		break;

	case 9: // Transitioning
		playbackStatus.innerHTML = "Transitioning";
		break;

	case 10: // Ready
		playbackStatus.innerHTML = "Ready";
		controlImage.src = "images/play.png";
		break;
	}
}