
function playlist_detail (o)
{
    if ( typeof(o) == "string" )
	o = document.getElementById(o);

    if ( ! o ) return;

    o.className = "long";
    var pc = document.getElementById('playlist_content');
    var items = pc.getElementsByTagName("div");
    for (var i = 0; i < items.length; i++)
    {
	if ( items[i].className != "short" && items[i].className != "long" )
	    continue;
	if ( items[i] != o ) items[i].className = "short";
	else items[i].className = "long";
    }
}

function view_schedule_playlist (which)
{
    var sc = document.getElementById('schedule_content');
    var pc = document.getElementById('playlist_content');
    var vsc = document.getElementById('view_schedule');
    var vpc = document.getElementById('view_playlist');

    if ( ! sc || ! pc || ! vsc || ! vpc ) return;

    if ( which == "schedule" )
    {
	sc.style.display = "block";
	pc.style.display = "none";
	vsc.style.display = "none";
	vpc.style.display = "block";
    }
    else if ( which == "playlist" )
    {
	sc.style.display = "none";
	pc.style.display = "block";
	vsc.style.display = "block";
	vpc.style.display = "none";
    }
}

var PLAYLIST_UPDATE_INTERVAL = 5 * 60;	// 5 minutes
var PLAYLIST_DATA_ID = "playlist_data";
var PLAYLIST_DATA_URL = "/stybin/playlist_show.mpl";
var PLAYLIST_DATA_PARAMS = "max=10;display=click";
var playlist_url;
var playlist_timer;
var current_playlist_data;

function playlist_init (params, interval)
{
    if ( ! interval ) interval = PLAYLIST_UPDATE_INTERVAL;
    if ( ! params ) params = PLAYLIST_DATA_PARAMS;
    playlist_url = PLAYLIST_DATA_URL + "?" + params;
    playlist_timer = setInterval (playlist_update, interval * 1000);
}

function playlist_callback()
{
    var new_playlist_data = document.getElementById(PLAYLIST_DATA_ID).innerHTML;
    if ( current_playlist_data != new_playlist_data )
    {
	// do anything worthwhile on a new song being displayed
	// but be careful since if someone mouses over to highlight a song other than the
	// first one, that will make this assume a new song has come in
    }
}

function playlist_update ()
{
    var url = playlist_url;
    url += "&t=" + (new Date()).getTime();	// make it bypass cache

    // save off a copy of the current recent playlist so we can compare after update to see if it changed
    current_playlist_data = document.getElementById(PLAYLIST_DATA_ID).innerHTML;
    sndReq (PLAYLIST_DATA_ID, url, playlist_callback);
}
