
var fsInlinePlayer = null;
var global_shouldKeepVisible = false;
var global_useNewPlayer = false;

function createFlashPlayer(shouldKeepVisible, useNewPlayer)
{
    // Load in the inline player object
    window.fsInlinePlayer = new Object();
    var flashObject = '';
    
    global_shouldKeepVisible = !(shouldKeepVisible == null || shouldKeepVisible != true);
    global_useNewPlayer = (useNewPlayer != null && useNewPlayer == true);

    var playerWidth = (global_useNewPlayer ? 290 : 340);
    var playerHeight = (global_useNewPlayer ? 23 : 25);
    var playerURL = 'http://www.voicezam.com/flash/' + (global_useNewPlayer ? 'InlinePlayer2009.swf' : 'Audio-InlinePlayer.swf') + '?v=' + getVolumeCookie();

    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="' + playerWidth + '" height="' + playerHeight + '" id="fsInlinePlayer" align="middle"';
        if (!global_shouldKeepVisible)
            flashObject += ' style="width:0px; overflow:hidden;">';
        flashObject += '<param name="allowScriptAccess" value="always" />';
        flashObject += '<param name="movie" value="' + playerURL + '" />';
        flashObject += '<param name="quality" value="high" />';
        if (global_useNewPlayer)
            flashObject += '<param name="bgcolor" value="#000000" />';
        else
            flashObject += '<param name="bgcolor" value="#ffffff" />';
        flashObject += '</object>';
    }
    else
    {
        flashObject = '<embed src="' + playerURL + '"';
        if (!global_shouldKeepVisible)
            flashObject += ' style="visibility:hidden;"';
        flashObject += ' quality="high"';
        if (global_useNewPlayer)
            flashObject += ' wmode="transparent" bgcolor="#000000"';
        else
            flashObject += ' bgcolor="#ffffff"';

        flashObject += ' width="' + playerWidth + '" height="' + playerHeight + '" 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 = (global_useNewPlayer ? 290 : 340).toString() + 'px';
        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;
}