
// --- Events --------------------------------------------------------------- //

function kpzPlayerOnResize(e)
{
  var d = document.getElementById("kpz_player_div");

  d.style.left = ((document.body.clientWidth - 76) / 2) + "px";
}

// --- Interface ------------------------------------------------------------ //

function kpzPlayerPopup()
{
  window.open("http://live.galaxiefm.com/webplayer",
              "kpzPlayerWindow",
              "menubar=no,resizable=no,scrollbars=no,status=no,width=320,height=125");

  kpzPlayerStartAnimation(-64);
}

// --- //

function kpzPlayerIsShown()
{
  return document.cookie.indexOf("www_galaxiefm_com_player") != -1;
}

function kpzPlayerMarkShown(shown)
{
  var cookie = "www_galaxiefm_com_player=1;path=/;domain=galaxiefm.com";

  if ( !shown )
  {
    var dt = new Date();

    dt.setTime(dt.getTime() - 1);

    cookie += ";expires=" + dt.toGMTString();
  }

  document.cookie = cookie;
}

// --- //

function kpzPlayerDiv()
{
  if ( kpzPlayerIsShown() )
    return;

  document.write('<div id="kpz_player_div" style="position:absolute; top:-64px; left:0px; width:76px; height:34px; overflow:hidden; cursor:pointer; background-image:url(\'http://live.galaxiefm.com/images/webplayer/play.png\'); z-index:100" onmouseup="kpzPlayerPopup()"></div>');

  window.onresize = kpzPlayerOnResize;

  kpzPlayerOnResize(null);

  setTimeout("kpzPlayerStartAnimation(0)", 2000);
}

// --- //

function kpzPlayerGetString(url, width, height, name)
{
  return   '<object id       = "' + name + '"'
         + '        classid  = "CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
         + '        codebase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715"'
         + '        standby  = "Loading Microsoft Windows Media Player components..."'
         + '        type     = "application/x-oleobject"'
         + '        width    = "' + width  + '"'
         + '        height   = "' + height + '">'
         + '    <param name = "FileName"           value = "' + url + '">'
         + '    <param name = "AnimationatStart"   value = "false">'
         + '    <param name = "TransparentatStart" value = "true">'
         + '    <param name = "AutoStart"          value = "true">'
         + '    <param name = "ShowControls"       value = "1">'
         + '    <param name = "wmode"              value = "transparent" />'
         + '    <param name = "showdisplay"        value = "0" />'
         + '    <param name = "showstatusbar"      value = "0" />'
         + '    <param name = "showtracker"        value = "1" />'
         + '  <embed type         = "application/x-mplayer2"'
         + '         pluginspage  = "http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Plugin&"'
         + '         src          = "' + url         + '"'
         + '         name         = "' + name + '"'
         + '         showcontrols = "1"'
         + '         width        = "' + width  + '"'
         + '         height       = "' + height + '"'
         + '  </embed>'
         + '</object>';
}

// --- Div animation -------------------------------------------------------- //

var kpzPlayerTarget = null;
var kpzPlayerTimer  = null;

// --- //

function kpzPlayerStartAnimation(target)
{
  kpzPlayerTarget = target;
  kpzPlayerTimer  = setInterval("kpzPlayerAnimationInterval()", 17);
}

// --- //

function kpzPlayerAnimationInterval()
{
  var dp = document.getElementById("kpz_player_div");

  var top = parseInt(dp.style.top);

  top += (kpzPlayerTarget - top) / 12;

  dp.style.top = top + "px";

  if ( top != kpzPlayerTarget )
    return;

  clearInterval(kpzPlayerTimer);
}

// ------------------------------------------------------------------------- //
