function focusPlayer() {
  var elm = $('ply');
  var myHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
  var myWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth
  if(typeof(elm) != 'undefined' && typeof(elm.style) != 'undefined') {
    $('lightbox').style.height=myHeight+'px';
    $('lightbox').style.width=myWidth+'px';
    fade('lightbox', 0.85, 30, 600);
    $('lightbox').onclick = unfocusPlayer;
  }
}

function unfocusPlayer() {
  var elm = $('ply');
  if(typeof(elm) != 'undefined' && typeof(elm.style) != 'undefined') {
    fade('lightbox', 0, 30, 600);
    $('lightbox').onclick = null;
  }
}

function fade(id, to, fps, duration) {
  if (!fps) fps = 30;
  if (!duration) duration = 1000;
  if (!to) to = 0;

  var origOpacity = ( !$(id).getStyle('opacity') || $(id).getStyle('display')=='none' ? 0 : $(id).getStyle('opacity') );
  var diff = origOpacity - to;

  var frames = Math.round(fps * (duration / 1000));
  var interval = duration / frames;
  var delay = interval;
  var frame = 0;
  
  if( origOpacity == 0 ) $(id).style.display='block';
  
  while (frame <= frames) {
    var opacity = origOpacity - ((diff / frames) * frame);

    setTimeout("setOpacity('"+id+"','"+opacity+"')", delay);
    if( frame == frames && to==0 ) setTimeout("$('"+id+"').style.display='none'", delay);

    frame++;
    delay = interval * frame;
  }
}

function slide(id, to, fps, duration) {
  if (!fps) fps = 40;
  if (!duration) duration = 400;
  if (!to) to = 0;
  
  var rawHeight = $(id).getStyle('height');
  var origHeight = ( !rawHeight || rawHeight=='' || rawHeight=='null' || $(id).getStyle('display')=='none' ? 0 : rawHeight.substring(0, rawHeight.length-2) );
  var diff = origHeight - to;

  var frames = Math.round(fps * (duration / 1000));
  var interval = duration / frames;
  var delay = interval;
  var frame = 0;
  
  if( origHeight == 0 ) {
    $(id).style.display='block';
    $(id).style.height=0+'px';
  }
  
  while (frame <= frames) {
    var height = origHeight - ((diff / frames) * frame);

    setTimeout("setHeight('"+id+"','"+height+"')", delay);
    if( frame == frames && to==0 ) setTimeout("$('"+id+"').style.display='none'", delay);

    frame++;
    delay = interval * frame;
  }
}

function setHeight(id, to) {
  var element = $(id);
  element.style.height=to+'px';
  if( to < 0 ) element.style.display='none';
}

function setOpacity(id, to) {
  var element = $(id);
  element.style.filter = (to == 1) ? '' : 'alpha(opacity=' + to * 100 + ')';
  element.style.opacity = to;
  if( to < 0 ) element.style.display='none';
}

var player;

function playerReady(obj) {
	var id = obj['id'];
	var version = obj['version'];
	var client = obj['client'];
	player = document.getElementById(id);
  
  player.addViewListener('PLAY', 'focusPlayer');
  player.addViewListener('ITEM', 'focusPlayer');
  player.addViewListener('STOP', 'unfocusPlayer');
};