/*
  Rewritten, more flexible SoundPlayer JavaScript glue.
  NEW: Removed JQuery dependancy
*/
var soundplayer_olditem = null;
var soundplayer_oldhtml = '';
function soundplayer_restore() {
  soundplayer_olditem.innerHTML = soundplayer_oldhtml.replace('_new','');
}
function soundplayer(linkitem, key, id, notseen) {
  baseplayer(0,linkitem,key,id,notseen);
}
function commentplayer(linkitem, key, id, notseen) {
  baseplayer(1,linkitem,key,id,notseen);
}
function metsaplayer(linkitem, key, id, notseen) {
  baseplayer(2,linkitem,key,id,0);
}
function baseplayer(playertype, linkitem, key, id, notseen) {
  var html = '';
	var swf = '';
  var width = 0;
  
  if (playertype == 0) {
  	swf = '/static/CustomPlayer.swf';
 	  width = 360;
 	  height = 21;
  } else if (playertype == 2) {
  	swf = '/static/CustomPlayer.swf';
 	  width = 1;
 	  height = 1;
  } else {
  	swf = '/static/CommentPlayer.swf';
 	  width = 32;
 	  height = 32;
  }
  
  /* Mark post as seen */
  if (notseen) tellserver(key);
  
  /* %3F == ? */
  soundurl = '/action/getpostdata?key=' + key;
  
  html = '<object style="opacity: .5; -moz-opacity: .5; filter: alpha(opacity=50);" type="application/x-shockwave-flash" data="'+swf+'" width="'+width+'" height="'+height+'" id="test">' +
         '  <param name="FlashVars" value="url='+ soundurl +'">' +
         '  <param name="movie" value="'+swf+'"/>' +
         '  <param name="wmode" value="transparent"/>' +
         '</object>';

  /* Restore previous player html item */
  if (soundplayer_olditem != null) {
    //soundplayer_olditem.html(soundplayer_oldhtml);
    soundplayer_olditem.innerHTML = soundplayer_oldhtml.replace('_new','');
  }

  /* Save item and html of new player position */
  //soundplayer_olditem = $($linkitem).parent();
  //soundplayer_oldhtml = soundplayer_olditem.html();
  var op = linkitem;
  if (playertype == 2) {
    soundplayer_olditem = op;
  } else {
    soundplayer_olditem = op.parentNode;
  }
  soundplayer_oldhtml = soundplayer_olditem.innerHTML;

  /* Enable SoundPlayer */
  //soundplayer_olditem.html(html);
  soundplayer_olditem.innerHTML = html;

  return false;
}

/*
    General AJAx code for requests without feedback
*/
function oneWayAJAX(requestURL) {
  var xmlHttp;
  countertimer=null;
  try {
    xmlHttp = new XMLHttpRequest();
  } catch (e) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("");
        return false;
      }
    }
  }
  xmlHttp.open("GET", requestURL, true);
  xmlHttp.send(null);
}

function tellserver(id) {
  //oneWayAJAX('action/seenpost?id='+id);
}

