/*
Macromedia(r) Flash(r) JavaScript Integration Kit License

Copyright (c) 2005 Macromedia, inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment:

"This product includes software developed by Macromedia, Inc.
(http://www.macromedia.com)."

Alternately, this acknowledgment may appear in the software itself, if and
wherever such third-party acknowledgments normally appear.

4. The name Macromedia must not be used to endorse or promote products derived
from this software without prior written permission. For written permission,
please contact devrelations@macromedia.com.

5. Products derived from this software may not be called "Macromedia" or
"Macromedia Flash", nor may "Macromedia" or "Macromedia Flash" appear in their
name.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MACROMEDIA OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

*/

function Exception(name, message)
{
   if (name)
      this.name = name;
   if (message)
      this.message = message;
}

Exception.prototype.setName = function(name) {this.name = name;}

Exception.prototype.getName = function() {return this.name;}

Exception.prototype.setMessage = function(msg) {this.message = msg;}

Exception.prototype.getMessage = function() {return this.message;}

function FlashTag(src, width, height, bgcolor)
{
   this.src = src;
   this.width = width;
   this.height = height;
   this.version = '6,0,47,0';
   this.id = null;
   this.bgcolor = bgcolor;
   this.flashVars = null;
}

FlashTag.prototype.setVersion = function(v) {this.version = v;}

FlashTag.prototype.setId = function(id) {this.id = id;}

FlashTag.prototype.setBgcolor = function(bgc) {this.bgcolor = bgc;}

FlashTag.prototype.setFlashvars = function(fv) {this.flashVars = fv;}

FlashTag.prototype.toString = function()
{
   var ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
   var flashTag = new String();
   if (ie)
   {
      flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
      if (this.id != null)
         flashTag += 'id="'+this.id+'" ';
      flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
      flashTag += 'width="'+this.width+'" ';
      flashTag += 'height="'+this.height+'">';
      flashTag += '<param name="movie" value="'+this.src+'"/>';
      flashTag += '<param name="quality" value="high"/>';
      flashTag += '<param name="bgcolor" value="#'+this.bgcolor+'"/>';
      if (this.flashVars != null)
         flashTag += '<param name="flashvars" value="'+this.flashVars+'"/>';
      flashTag += '</object>';
   }
   else
   {
      flashTag += '<embed src="'+this.src+'" ';
      flashTag += 'quality="high" ';
      flashTag += 'bgcolor="#'+this.bgcolor+'" ';
      flashTag += 'width="'+this.width+'" ';
      flashTag += 'height="'+this.height+'" ';
      flashTag += 'type="application/x-shockwave-flash" ';
      if (this.flashVars != null)
         flashTag += 'flashvars="'+this.flashVars+'" ';
      if (this.id != null)
         flashTag += 'name="'+this.id+'" ';
      flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
      flashTag += '</embed>';
    }
    return flashTag;
}

FlashTag.prototype.write = function(doc) {doc.write(this.toString());}

function FlashSerializer(useCdata) {this.useCdata = useCdata;}

FlashSerializer.prototype.serialize = function(args)
{
   var qs = new String();
   for (var i = 0; i < args.length; ++i)
   {
      switch(typeof(args[i]))
      {
         case 'undefined':
            qs += 't'+(i)+'=undf';
            break;
         case 'string':
            qs += 't'+(i)+'=str&d'+(i)+'='+escape(args[i]);
            break;
         case 'number':
            qs += 't'+(i)+'=num&d'+(i)+'='+escape(args[i]);
            break;
         case 'boolean':
            qs += 't'+(i)+'=bool&d'+(i)+'='+escape(args[i]);
            break;
         case 'object':
            if (args[i] == null)
               qs += 't'+(i)+'=null';
            else if (args[i] instanceof Date)
               qs += 't'+(i)+'=date&d'+(i)+'='+escape(args[i].getTime());
            else // array or object
               try
               {
                  qs += 't'+(i)+'=xser&d'+(i)+'='+escape(this._serializeXML(args[i]));
               }
               catch (exception)
               {
                  throw new Exception("FlashSerializationException", "The following error occurred during complex object serialization: " + exception.getMessage());
               }
            break;
         default:
            throw new Exception("FlashSerializationException", "You can only serialize strings, numbers, booleans, dates, objects, arrays, nulls, and undefined.");
      }
      if (i != (args.length - 1))
         qs += '&';
   }
   return qs;
}

FlashSerializer.prototype._serializeXML = function(obj)
{
   var doc = new Object();
   doc.xml = '<fp>';
   this._serializeNode(obj, doc, null);
   doc.xml += '</fp>';
   return doc.xml;
}

FlashSerializer.prototype._serializeNode = function(obj, doc, name)
{
   switch(typeof(obj))
   {
      case 'undefined':
         doc.xml += '<undf'+this._addName(name)+'/>';
         break;
      case 'string':
         doc.xml += '<str'+this._addName(name)+'>'+this._escapeXml(obj)+'</str>';
         break;
      case 'number':
         doc.xml += '<num'+this._addName(name)+'>'+obj+'</num>';
         break;
      case 'boolean':
         doc.xml += '<bool'+this._addName(name)+' val="'+obj+'"/>';
         break;
      case 'object':
         if (obj == null)
            doc.xml += '<null'+this._addName(name)+'/>';
         else if (obj instanceof Date)
            doc.xml += '<date'+this._addName(name)+'>'+obj.getTime()+'</date>';
         else if (obj instanceof Array)
         {
            doc.xml += '<array'+this._addName(name)+'>';
            for (var i = 0; i < obj.length; ++i)
               this._serializeNode(obj[i], doc, null);
            doc.xml += '</array>';
         }
         else
         {
            doc.xml += '<obj'+this._addName(name)+'>';
            for (var n in obj)
            {
               if (typeof(obj[n]) == 'function')
                  continue;
               this._serializeNode(obj[n], doc, n);
            }
            doc.xml += '</obj>';
         }
         break;
      default:
         throw new Exception("FlashSerializationException", "You can only serialize strings, numbers, booleans, objects, dates, arrays, nulls and undefined");
         break;
   }
}

FlashSerializer.prototype._addName= function(name) {return name != null ? ' name="'+name+'"' : '';}

FlashSerializer.prototype._escapeXml = function(str) {return this.useCdata ? '<![CDATA['+str+']]>' : str.replace(/&/g,'&amp;').replace(/</g,'&lt;');}

function FlashProxy(uid, proxySwfName)
{
   this.uid = uid;
   this.proxySwfName = proxySwfName;
   this.flashSerializer = new FlashSerializer(false);
}

FlashProxy.prototype.call = function()
{
   if (arguments.length == 0)
      throw new Exception("Flash Proxy Exception", "The first argument should be the function name followed by any number of additional arguments.");
   var qs = 'lcId=' + escape(this.uid) + '&functionName=' + escape(arguments[0]);
   if (arguments.length > 1)
   {
      var justArgs = new Array();
      for (var i = 1; i < arguments.length; ++i)
         justArgs.push(arguments[i]);
      qs += ('&' + this.flashSerializer.serialize(justArgs));
   }
   var divName = '_flash_proxy_' + this.uid;
   if(!document.getElementById(divName))
   {
      var newTarget = document.createElement("div");
      newTarget.id = divName;
      document.body.appendChild(newTarget);
   }
   var target = document.getElementById(divName);
   var ft = new FlashTag(this.proxySwfName, 1, 1);
   ft.setVersion('6,0,65,0');
   ft.setFlashvars(qs);
   target.innerHTML = ft.toString();
}

FlashProxy.callJS = function()
{
   var functionToCall = eval(arguments[0]);
   var argArray = new Array();
   for (var i = 1; i < arguments.length; ++i)
      argArray.push(arguments[i]);
   functionToCall.apply(functionToCall, argArray);
}

// Macromedia code is above this line and Wimpy code is below it.

flash_enabled = false;
flash_version = 0;

if (navigator.plugins && navigator.plugins.length)
{
   var x = navigator.plugins['Shockwave Flash'];
   if (x.description)
   {
      flash_version = x.description.charAt(x.description.indexOf('.') - 1);
      if (flash_version <= 5)
         flash_version = parseInt('1' + flash_version);
   }
}

for (var i = 12; i > 0; i--)
{
    try
    {
        var flash = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i);
        flash_version = i;
        break;
    }
    catch (e) { }
}
if (flash_version >= 6)
   flash_enabled = true;

// Wimpy Player with JavaScript Controller Version 1.0
// ©2002-2005 plaino, inc.

wimpySwf = 'scripts/wimpy.swf';
wimpyConfigFile = '';
trackPlays = '';
voteScript = '';
defaultImage = '';
startPlayingOnload = 'no';
shuffleOnLoad = 'no';
randomOnLoad = 'no';
displayDownloadButton = 'no';
startOnTrack = '';
autoAdvance = 'no';
popUpHelp = 'yes';
scrollInfoDisplay = 'yes';
infoDisplayTime = '3';
bufferAudio = '2';
theVolume = '100';
defaultVisualExt = 'jpg';
randNum = 1;

function makeWimpyPlayer(wimpyApp, wimpySkin, theWidth, theHeight, theBkgdColor, thePlaylist)
{
   myuid = new Date().getTime();
   flashProxy = new FlashProxy(myuid, 'scripts/JavaScriptFlashGateway.swf');
   AmyConfigs = Array();
   if (wimpyApp)
      AmyConfigs[AmyConfigs.length] = "wimpyApp="+wimpyApp;
   AmyConfigs[AmyConfigs.length] = "wimpySkin="+wimpySkin;
   AmyConfigs[AmyConfigs.length] = "trackPlays="+trackPlays;
   AmyConfigs[AmyConfigs.length] = "voteScript="+voteScript;
   AmyConfigs[AmyConfigs.length] = "defaultImage="+defaultImage;
   AmyConfigs[AmyConfigs.length] = "startPlayingOnload="+startPlayingOnload;
   AmyConfigs[AmyConfigs.length] = "shuffleOnLoad="+shuffleOnLoad;
   AmyConfigs[AmyConfigs.length] = "randomOnLoad="+randomOnLoad;
   AmyConfigs[AmyConfigs.length] = "displayDownloadButton="+displayDownloadButton;
   AmyConfigs[AmyConfigs.length] = "startOnTrack="+startOnTrack;
   AmyConfigs[AmyConfigs.length] = "autoAdvance="+autoAdvance;
   AmyConfigs[AmyConfigs.length] = "popUpHelp="+popUpHelp;
   AmyConfigs[AmyConfigs.length] = "scrollInfoDisplay="+scrollInfoDisplay;
   AmyConfigs[AmyConfigs.length] = "infoDisplayTime="+infoDisplayTime;
   AmyConfigs[AmyConfigs.length] = "bufferAudio="+bufferAudio;
   AmyConfigs[AmyConfigs.length] = "theVolume="+theVolume;
   AmyConfigs[AmyConfigs.length] = "defaultVisualExt="+defaultVisualExt;
   AmyConfigs[AmyConfigs.length] = "forceXMLplaylist=yes";
   myConfigs = AmyConfigs.join("&");
   randNum++;
   flashVersion = "6,0,47,0";
   if (theBkgdColor != false)
   {
      bkgdColor = theBkgdColor
      tptBkgd_param = "";
      tptBkgd_embed = "";
   }
   else
   {
      bkgdColor = "000000";
      tptBkgd_param = '<param name="wmode" value="transparent" />';
      tptBkgd_embed = 'wmode="transparent" ';
   }
   js2wimpy_param = '<param name="flashvars" value="lcId='+myuid+'"/>';
   js2wimpy_embed = 'flashvars="lcId='+myuid+'" ';
   if (wimpyConfigFile.length > 4)
      altString = '&wimpyConfigs='+wimpyConfigFile;
   else
      altString = "&"+myConfigs;
   if (thePlaylist)
      writePlaylist = "&playlist="+thePlaylist;
   else
      writePlaylist = "";
   queryString = wimpySwf +'?x='+randNum+altString+writePlaylist;
   flashCode = '';
   flashCode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashVersion+'" width="'+theWidth+'" height="'+theHeight+'" name="wimpy'+randNum+'" id="wimpy'+randNum+'">';
   flashCode += '<param name="movie" value="'+queryString+'" />';
   flashCode += '<param name="loop" value="false" />';
   flashCode += '<param name="menu" value="false" />';
   flashCode += '<param name="quality" value="high" />';
   flashCode += '<param name="scale" value="noscale" />';
   flashCode += '<param name="salign" value="lt" />';
   flashCode += '<param name="bgcolor" value="'+bkgdColor+'" />';
   flashCode += tptBkgd_param;
   flashCode += js2wimpy_param;
   flashCode += '<embed src="'+queryString+'" width="'+theWidth+'" height="'+theHeight+'" bgcolor="'+bkgdColor+'" loop="false" menu="false" quality="high" scale="noscale" salign="lt" name="wimpy'+randNum+'" id="wimpy'+randNum+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" '+tptBkgd_embed+js2wimpy_embed+'/></object>';
   //document.write(flashCode);
   return flashCode;
}

// Wimpy code is above this line and PhoneMessage.com code is below it.
// ©2006 PhoneMessage.com

NORMAL_WAITING_TIME = 30000;
status_message = new StatusMessage();

function request(parameters, message, time)
{
   var pid = status_message.start(message, time);
   script = document.createElement('SCRIPT');
   script.type = 'text/javascript';
   script.src = 'server/rpc.php?uid=' + new Date().getTime() + '&pid=' + pid + '&' + parameters;
   document.getElementsByTagName('HEAD').item(0).appendChild(script);
}

function StatusMessage()
{
   this.statuses = Array();
   this.id = 1;
}

StatusMessage.prototype.start = function(message, time)
{
   var posx = mouseXCoordinate - 50 + (window.Event ? 0 : document.body.scrollLeft);
   var posy = mouseYCoordinate - 50 + (window.Event ? 0 : document.body.scrollTop);
   document.getElementById('status').style.top = posy;
   document.getElementById('status').style.left = posx;
   document.getElementById('status').noWrap = true;
   document.getElementById('status').style.color = '#0174D7';
   this.statuses[this.id] = message;
   document.getElementById('status').innerHTML = '<img src="images/hourglass.gif" width="9" height="14" align="top" vspace="0">&nbsp; ' + message;
   document.getElementById('status').style.display = 'block';
   status_message.repositionStatusMessage();
   setTimeout('status_message.giveUp(' + this.id + ');', time);
   return this.id++;
}

StatusMessage.prototype.repositionStatusMessage = function()
{
   if (parseInt(document.getElementById('status').style.left) + document.getElementById('status').offsetWidth > document.getElementById('status_container').offsetWidth + (document.body.offsetWidth + document.body.scrollLeft - document.getElementById('status_container').offsetWidth) / 2)
      document.getElementById('status').style.left = document.getElementById('status_container').offsetWidth + (document.body.offsetWidth - document.getElementById('status_container').offsetWidth) / 2 - document.getElementById('status').offsetWidth;
   if (parseInt(document.getElementById('status').style.top) + document.getElementById('status').offsetHeight > document.getElementById('status_container').offsetHeight + (document.body.offsetHeight + document.body.scrollTop - document.getElementById('status_container').offsetHeight) / 2)
      document.getElementById('status').style.top = document.getElementById('status_container').offsetHeight + (document.body.offsetHeight - document.getElementById('status_container').offsetHeight) / 2 - document.getElementById('status').offsetHeight;
}

StatusMessage.prototype.giveUp = function(id)
{
   var temp_statuses = Array();
   for (var key in this.statuses)
      if (key == id)
      {
         document.getElementById('status').style.color = '#660026';
         document.getElementById('status').innerHTML = '<img src="images/status_alert.gif" width="14" height="14" align="top" vspace="0">&nbsp; ' + 'Error: ' + this.statuses[id];
         setTimeout('status_message.changeStatus();', 2500);
      }
      else
         temp_statuses[key] = this.statuses[key];
   this.statuses = temp_statuses;
}

StatusMessage.prototype.finish = function(id, message, type)
{
   if (type == 1)
   {
      document.getElementById('status').style.color = '#0174D7';
      document.getElementById('status').innerHTML = message;
      status_message.repositionStatusMessage();
   }
   else if (type == 2)
   {
      document.getElementById('status').style.color = '#08AF3B';
      document.getElementById('status').innerHTML = '<img src="images/check_mark.gif" width="13" height="14" align="top" vspace="0">&nbsp; ' + message;
      status_message.repositionStatusMessage();
   }
   else
   {
      document.getElementById('status').style.color = '#660026';
      document.getElementById('status').innerHTML = '<img src="images/status_alert.gif" width="14" height="14" align="top" vspace="0">&nbsp; ' + message;
      status_message.repositionStatusMessage();
   }

   if (id == -1)
      setTimeout('status_message.changeStatus();', 2500);
   else if (this.statuses.length)
   {
      var temp_statuses = Array();
      for (var key in this.statuses)
         if (key == id)
            setTimeout('status_message.changeStatus();', type == 3 ? 3000 : 1500);
         else
            temp_statuses[key] = this.statuses[key];
      this.statuses = temp_statuses;
   }
}

StatusMessage.prototype.changeStatus = function()
{
   if (this.statuses.length)
   {
      document.getElementById('status').style.color = '#0174D7';
      document.getElementById('status').innerHTML = '<img src="images/hourglass.gif" width="9" height="14" align="top" vspace="0">&nbsp; ' + this.statuses[this.statuses.length - 1];
      status_message.repositionStatusMessage();
      setTimeout('status_message.changeStatus();', 1500);
   }
   else
   {
      document.getElementById('status').style.display = 'none';
      document.getElementById('status').innerHTML = '';
   }
}

function initMouseTracker()
{
   if (window.Event)
      document.captureEvents(Event.MOUSEMOVE);
   document.onmousemove = getXYCoordinates;
}

function getXYCoordinates(e)
{
   mouseXCoordinate = window.Event ? e.pageX : event.clientX;
   mouseYCoordinate = window.Event ? e.pageY : event.clientY;
}

window.onload = initMouseTracker;
