/////////////////////////////////////////////////////////////////////////////////////
//                                                                                 //
//  Volume Control Gadget 1.1 by Orbmu2k © 2007                                   //
//                                                                                 //
//  Copyright © 2007 Orbmu2k.  All rights reserved.                                //
//                                                                                 //
//  http://blog.orbmu2k.de                                                         //
//                                                                                 //
//  Email: sidebargadget@orbmu2k.de                                                //
//                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////

var sound;
var t;
var vol;
var mute;
var imgSpeaker;
var imgCross;

function init()
{
    sound = GetLibrary();
    initObjects();
	t = setInterval("refreshdisplay()",75);
}

function terminate()
{
    UnregisterLibrary(); 
}

function initObjects()
{
    imgSpeaker = background.addImageObject("kmix.png", 4, 6);
    imgSpeaker.width = 24;
    imgSpeaker.height = 24;

    imgCross = background.addImageObject("cross.png", 18, 22)
    imgCross.width = 12;
    imgCross.height = 12;
}

function changeVolume()
{
    var v = sound.MasterVolume;

    if (event.wheelDelta >= 20)
		v += 3;
	else 
		v -= 3;
	
	if (v >= 100) v = 100;
	if (v <= 0) v = 0;

	sound.MasterVolume = v;
}

function muteVolume()
{
   sound.MasterMute = !sound.MasterMute;
}

function refreshdisplay()
{
    vol = sound.MasterVolume;
    mute = sound.MasterMute;
    
    imgCross.opacity = mute ? 100 : 0;
    if (mute)
        txtVolume.innerText = "Volume: Mute";
    else
        txtVolume.innerText = "Volume: " + vol + "%";
    
    divvol.style.width = (Math.round((vol / 8)) * 8);
    divpeakleft.style.width = (Math.round((sound.LeftPeak / 8)) * 8);
    divpeakright.style.width = (Math.round((sound.RightPeak / 8)) * 8);
}

