var radio_current_page = null;
var is_diretta = false;
/*
function getHtmlMediaPlayer(width, height, url, autoStart) {
	var isIE = (-1 != navigator.userAgent.indexOf("MSIE"));

	var html = '';

	html += '<object id="media_player"';
	html += ' ';
	if (isIE) {
		html += 'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715,8,9,10" standby="Loading Microsoft¨ Windows¨ Media Player components..." type="application/x-oleobject"';
	}
	else {//if(-1 != navigator.userAgent.indexOf("Firefox")) {
		html += 'type="application/x-ms-wmp" data="' + url + '"';
	}
	html += ' ';
	html += 'width="' + width + '" height="' + height + '">' + '\n';

	html += '<param name="src" value="' + url + '" />' + '\n';
	html += '<param name="FileName" value="' + url + '" />' + '\n';
	html += '<param name="controller" value="true" />' + '\n';
	html += '<param name="ShowControls" value="true" />' + '\n';
	html += '<param name="AnimationatStart" value="true" />' + '\n';
	html += '<param name="TransparentatStart" value="true" />' + '\n';
	html += '<param name="loop" value="false" />' + '\n';
	html += '<param name="ShowStatusBar" value="true" />' + '\n';

	if (isIE && (autoStart == 'false')) {
		html += '<param name="autostart" value="true" />' + '\n';
	}
	else {
		html += '<param name="autostart" value="' + autoStart + '" />' + '\n';
	}

	html += '</object>' + '\n';

	$('player_cnt').update(html);

	if (isIE && (autoStart == 'false')) {
		document.getElementById('media_player').Stop();
	}
}*/

function getHtmlMediaPlayer(width, height, url, autoStart) {
	var isIE = (-1 != navigator.userAgent.indexOf("MSIE"));

	var html = '';

	html += '<object id="media_player" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715,8,9,10" standby="Loading Microsoft¨ Windows¨ Media Player components..." type="application/x-oleobject" width="' + width + '" height="' + height + '">' + '\n';

	html += '<param name="AnimationatStart" value="true" />' + '\n';
	html += '<param name="TransparentatStart" value="true" />' + '\n';
	html += '<param name="autoStart" value="' + autoStart + '" />' + '\n';
	html += '<param name="showControls" value="true" />' + '\n';
	html += '<param name="FileName" value="' + url + '" />' + '\n';
	html += '<param name="loop" value="true" />' + '\n';
	html += '<param name="ShowStatusBar" value="true" />' + '\n';

	html += '<embed ';
	html += 'type="application/x-mplayer2" ';
	html += 'pluginspage="http://microsoft.com/windows/mediaplayer/it/download/" ';
	html += 'id="media_player" ';
	html += 'name="media_player" ';
	html += 'displaysize="4" ';
	html += 'autosize="-1" ';
	html += 'bgcolor="darkblue" ';
	html += 'showcontrols="true" ';
	html += 'showtracker="-1" ';
	html += 'showdisplay="0" ';
	html += 'showstatusbar="-1" ';
	html += 'videoborder3d="-1" ';
	html += 'width="' + width + '" ';
	html += 'height="' + height + '" ';
	html += 'src="' + url + '" ';
	html += 'autostart="' + autoStart + '" ';
	html += 'designtimesp="5311" ';
	html += 'loop="true" ';
	html += '>';
	html += '</embed>' + '\n';
	html += '</object>' + '\n';

	return(html);
}

function body_onload(page) {
	if (page == 'palinsesto') {
		radio_current_page = 'palinsesto';
	}

	if (page == 'podcast') {
		go_to_podcast('');
	}
	else {
		update_body('radio_palinsesto_full.php');
	}

	update_player('radio_player.php');

	refresh_player_diretta();
}

function update_player(url) {
	new Ajax.Updater(
		'header_player',
		url,
		{
			evalScripts: true,
			onLoading:
				function(request, json) {
					Element.hide('header_player');
					Element.show('header_indicator');
				},
			onComplete:
				function(request, json) {
					Element.hide('header_indicator');
					Element.show('header_player');
					new Effect.Highlight('header_player', { startcolor: '#FFFF99', endcolor: '#B2B2B2' });
				}
		}
	);
}

function play_podcast(IdPodcast) {
	update_player('radio_player.php?IdPodcast=' + IdPodcast);
}

function play_diretta() {
	update_player('radio_player.php');
}

var id_player_diretta_timeout;

function refresh_player_diretta() {
	if (id_player_diretta_timeout) {
		clearTimeout(id_player_diretta_timeout);
	}

	id_player_diretta_timeout = setTimeout('update_player_info()', 1000 * 60 * 1);
}

function update_player_info() {
	if (is_diretta) {
		new Ajax.Updater(
			'header_title',
			'radio_player_info.php',
			{
				method: 'get',
				evalScripts: true,
				onLoading:
					function(request, json) {
						//Element.hide('box_agenzie_show');
						//Element.show('box_agenzie_indicator');
					},
				onComplete:
					function(request, json) {
						//Element.hide('box_agenzie_indicator');
						//Element.show('box_agenzie_show');
						//new Effect.Highlight('box_agenzie_cnt', {});
					}
			}
		);
	}
	refresh_player_diretta();
}

function update_body(url) {
	new Ajax.Updater(
		'body',
		url,
		{
			evalScripts: true,
			onLoading:
				function(request, json) {
					Element.hide('body');
					Element.show('body_indicator');
				},
			onComplete:
				function(request, json) {
					Element.hide('body_indicator');
					Element.show('body');
					new Effect.Highlight('body', {});
				}
		}
	);
}

function go_to_palinsesto_full() {
	radio_current_page = 'palinsesto';

	$('button_palinsesto').addClassName('selected');
	$('button_podcast').removeClassName('selected');

	update_body('radio_palinsesto_full.php');
}

function go_to_podcast(IdProgramma) {
	radio_current_page = 'podcast';

	$('button_palinsesto').removeClassName('selected');
	$('button_podcast').addClassName('selected');

	var url_podcast = 'radio_podcast.php';
	if (IdProgramma) {
		url_podcast += '?IdProgramma=' + IdProgramma;
	}
	update_body(url_podcast);
}

function podcast_update(data_dal, data_al, IdProgramma, keywords, page) {
	new Ajax.Updater(
		'body',
		'radio_podcast.php?data_dal=' + data_dal + '&data_al=' + data_al + '&IdProgramma=' + IdProgramma + '&keywords=' + keywords + '&Page=' + page,
		{
			method: 'get',
			evalScripts: true,
			onLoading:
				function(request, json) {
					Element.hide('body');
					Element.show('body_indicator');
				},
			onComplete:
				function(request, json) {
					Element.hide('body_indicator');
					Element.show('body');
					new Effect.Highlight('body', {});
				}
		}
	);
}

function podcast_update_form() {
	new Ajax.Updater(
		'body',
		'radio_podcast.php',
		{
			method: 'get',
			evalScripts: true,
			onLoading:
				function(request, json) {
					Element.hide('body');
					Element.show('body_indicator');
				},
			onComplete:
				function(request, json) {
					Element.hide('body_indicator');
					Element.show('body');
					new Effect.Highlight('body', {});
				},
			parameters:Form.serialize('podcast_form')
		}
	);
}
