/*
 This file contains a collection of music related utility functions for use on Holiwater
*/
document.domain = "holiwater.com";
var pauseCount = 0;
var musicPlaying = true;
function ToggleMusic()
{
    if ( musicPlaying ) {
        PauseMusic();
    } else {
        StartMusic();
    }
    return musicPlaying;
}

// Starts the music but only if it's
function StartMusic()
{
    if ( parent.frames && parent.frames['audioframe'] )  {
        var audio = parent.frames['audioframe'].vpholiwaterplayer;
        if ( audio ) {
            if ( --pauseCount <= 0 ) {
                audio.sendEvent("PLAY","true");
                musicPlaying = true;
                pauseCount = 0;
            }
        }
    }
}

// Pauses the music and increments a pause count. Future StartMusics will only start the music if the count decrements back to 0 again.
// Allows for stacking of pauses.
function PauseMusicStacked()
{
    if ( parent.frames && parent.frames['audioframe'] )  {
        var audio = parent.frames['audioframe'].vpholiwaterplayer;
        if ( audio ) {
            audio.sendEvent("PLAY","false");
            musicPlaying = false;
            pauseCount++;
        }
    }
}

// Pauses the music in an unstacked fashion. The next StartMusic will restart it. You can call this method multiple times
// but it will only take one StartMusic to restart the music again.
function PauseMusic()
{
    if ( parent.frames && parent.frames['audioframe'] )  {
        var audio = parent.frames['audioframe'].vpholiwaterplayer;
        if ( audio ) {
            audio.sendEvent("PLAY","false");
            musicPlaying = false;
            pauseCount = 1;
        }
    }
}

// Shows an specific on/off icon in an IMG tag based on a flag.
// onOff - true = show the ON image, false = show the OFF image
// imageId - the element ID of the IMG tag to change
// onImage - the URL of the ON image
// offImage - the URL of the OFF image
function ShowIcon(onOff, imageId, onImage, offImage)
{
    document.getElementById(imageId).src = onOff ? onImage : offImage;
}
