
var fsInlinePlayer = null;
var global_shouldKeepVisible = false;

function createFlashPlayer(shouldKeepVisible)
{
    // Load in the inline player object
    window.fsInlinePlayer = new Object();
    var flashObject = '';
    
    global_shouldKeepVisible = !(shouldKeepVisible == null || shouldKeepVisible != true);

    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        flashObject = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="340" height="25" id="fsInlinePlayer" align="middle"';
        if (!global_shouldKeepVisible)
            flashObject += ' style="width:0px; overflow:hidden;">';
        flashObject += '<param name="allowScriptAccess" value="always" />';
        flashObject += '<param name="movie" value="http://www.voicezam.com/flash/Audio-InlinePlayer.swf?v=' + getVolumeCookie() + '" />';
        flashObject += '<param name="quality" value="high" />';
        flashObject += '<param name="bgcolor" value="#ffffff" />';
        flashObject += '</object>';
    }
    else
    {
        flashObject = '<embed src="http://www.voicezam.com/flash/Audio-InlinePlayer.swf?v=' + getVolumeCookie() + '"';
        if (!global_shouldKeepVisible)
            flashObject += ' style="visibility:hidden;"';
        flashObject += ' quality="high" bgcolor="#ffffff" width="340" height="25" id="fsInlinePlayer" name="fsInlinePlayer" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    }

    document.write(flashObject);
    fsInlinePlayer = document.getElementById('fsInlinePlayer');
    fsInlinePlayer.playRead = function(val) { string1 = '<invoke name="playRead" returntype="javascript"><arguments><string>'+val+'</string></arguments></invoke>'; fsInlinePlayer.CallFunction(string1); }
    fsInlinePlayer.stopRead = function() { string1 = '<invoke name="stopRead" returntype="javascript"></invoke>'; fsInlinePlayer.CallFunction(string1); }
}

function hideFlash(flashContainer)
{
    if (flashContainer != null && flashContainer != undefined && !global_shouldKeepVisible)
    {
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
            flashContainer.style.overflow = 'hidden';
            flashContainer.style.width = '0px';
        }
        else
        {
            flashContainer.parentNode.style.visibility = 'hidden';
            flashContainer.style.visibility = 'hidden';     
        }
    }
}

function showFlash(flashContainer)
{
    if (flashContainer != null && flashContainer != undefined)
    {
        flashContainer.style.overflow = 'visible';
        flashContainer.style.width = '340px';
        flashContainer.style.visibility = 'visible';
        flashContainer.parentNode.style.visibility = 'visible';
    }
}

function stopRead()
{
    hideFlash(fsInlinePlayer);
    fsInlinePlayer.stopRead();
}

function playRead(src)
{
    if (fsInlinePlayer != null && fsInlinePlayer.playRead != null)
    {
        fsInlinePlayer.playRead(src);
        showFlash(fsInlinePlayer);
    }
}

function jsVolumeChanged(newVolume)
{
    setVolumeCookie(newVolume);
}

function setVolumeCookie(volumeLevel)
{
    // Set the cookie to expire a year from now
    createCookie('MZPLAYER_Volume', volumeLevel, 365);
}


function getVolumeCookie()
{
    // Find the cookie if it exists
    var theVolume = readCookie('MZPLAYER_Volume');
    
    // Make sure the volume is between 0 and 100
    if (theVolume == null) theVolume = '60';
    theVolume = parseInt('0' + theVolume, 10);
    
    if (theVolume < 0 || theVolume > 100) theVolume = 60;
    setVolumeCookie(theVolume);
    return theVolume;
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}