Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
/**
* Volume widget presentation code
*
* Web control interface script for Amarok
* Written by Dan Fuhry - 2008
*
* This script is in the public domain. Use it for good, not evil.
*/
var current_volume = 0;
function set_volume_fill(amount)
{
amount = 10 * ( Math.round(amount / 10) );
if ( amount == 0 )
amount = -10;
for ( var i = 0; i <= amount; i += 10 )
{
if ( !$('volbtn_' + i).hasClass('volume_button_active') )
{
$('volbtn_' + i).addClass('volume_button_active');
}
}
for ( ; i <= 100; i += 10 )
{
if ( $('volbtn_' + i).hasClass('volume_button_active') )
{
$('volbtn_' + i).rmClass('volume_button_active');
}
}
}
function volume_over(amount)
{
set_volume_fill(amount);
}
function volume_out()
{
set_volume_fill(current_volume);
}
function set_volume(level)
{
setAjaxLoading();
if ( level == current_volume )
return false;
ajaxGet('/action.json/volume/' + level, function()
{
if ( ajax.readyState == 4 && ajax.status == 200 )
{
unsetAjaxLoading();
var response = (' ' + ajax.responseText).substr(1);
// quickie JSON parser :)
response = eval('(' + response + ')');
// update volume
if ( response.volume != current_volume )
{
set_volume_fill(response.volume);
current_volume = response.volume;
}
}
});
}