var key, value;
key = 'music';
value = 'off';
var winRef;
var bMusicOn = false;

function LoadMusicCookieData() {
    bMusicOn = getCookie('music');
    var sound_on = document.getElementById('sound_on');
    var sound_off = document.getElementById('sound_off');
    if (sound_on && sound_off) {
        if (bMusicOn && bMusicOn == 'on') {
            SetStyle(sound_on, 'active');
            SetStyle(sound_off, '');
        } else {
            SetStyle(sound_on, '');
            SetStyle(sound_off, 'active');
        }
    }
}

function ToggleMusic(bOn)
{	
	if(bOn) {
		if (value != 'on') {
		    //load player
		    winRef = window.open('/musicPlayer.html', 'music_box', 'width=200,height=200');
		    //move as far to btoom right as possible
		    winRef.moveTo(2000, 2000);
		    TurnOn();
		    //alert("TURN ON");
		}
	}
	else {
	    if (value != 'off') {
	        if (!winRef) {
	            winRef = window.open('/musicPlayer.html', 'music_box', 'width=200,height=200');
	        }
		    winRef.close();
		    TurnOff();
		}
	}
}

function TurnOn() {
    var sound_on = document.getElementById('sound_on');
    var sound_off = document.getElementById('sound_off');
    if (sound_on && sound_off) {
        value = 'on';
        setCookie(key, value);
        SetStyle(sound_on, 'active');
        SetStyle(sound_off, '');
    }
}

function TurnOff() {
    if (value != 'off') {
        //alert("TURN OFF");
        var sound_on = document.getElementById('sound_on');
        var sound_off = document.getElementById('sound_off');
        if (sound_on && sound_off) {
            value = 'off';
            setCookie(key, value);
            SetStyle(sound_on, '');
            SetStyle(sound_off, 'active');
        }
    }
}

function SetStyle(ctl, className) {
    ctl.className = className;
}
