// Byrgius Technologies
// 2006

var basePath = window.document.location.toString();
    basePath = basePath.replace( /.com\/.*$/, '.com\/' );

var omPath    = "omPlayer/"
var omScript  = "omplayer_lite.swf";
var omWindow  = "play.html";
var wmvWindow = "wmv_play.html";

function wmvPopup( filePath, width, height ){
  var path = basePath + omPath + wmvWindow + '?filePath='+filePath;
  var name = 'wmv' + Math.floor(Math.random()*12345);
  var parm = 'width='+width+',height='+height;
  window.open( path, name, parm );
}

function omPopup( AID, autoPlay, width, height ){
  var path = basePath + omPath + omWindow + '?AID='+AID+'&autoPlay='+autoPlay;
  var name = 'omp' + Math.floor(Math.random()*12345);
  var parm = 'width='+width+',height='+height;
  window.open( path, name, parm );
}

function omPlayer() {
  this.path                 = basePath + omPath;
  this.script               = omScript;
  this.bgcolor              = null; // or #000000
  this.videoStyle           = 2;
  this.videoStyleSelectable = false;
  this.autoPlay             = null;
  this.autoStart            = false;
  this.AID                  = null;
  this.MID                  = null;
  this.autoLoadID           = null;
  this.width                = '100%';
  this.height               = '100%';
  this.winWidth             = '580';
  this.winHeight            = '520';
  this.hideParent           = 0;
  this.subDisplay           = false;

  // ----------------------------------------------------------------------------------------------------------------
  this.render = function() {

    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
      var pos = parms[i].indexOf('=');
      if (pos > 0) {
        var key = parms[i].substring(0,pos);
        var val = parms[i].substring(pos+1);
        eval('this.'+key+' = val');
      }
    }

    this.writeSWF();
    // this.winResize();
  }

  // ----------------------------------------------------------------------------------------------------------------
  this.writeSWF = function() {

    swf_id = 'omPlayer' + (Math.round((Math.random()*1000000)+1));

    query = '';
    if (this.AID != null) {
      query += "&AID="+this.AID;
    }
    if (this.autoPlay != null) {
      query += "&autoPlay="+this.autoPlay;
    }
    if (this.MID != null) {
      query += "&autoLoadID="+this.MID;
      query += '&autoStart='+this.autoStart;
    }
    query += "&playListURL=" + ( this.playListURL?this.playListURL:(this.path+'omxmlgen.php') );
    query += '&videoStyle='+this.videoStyle;
    query += '&videoStyleSelectable='+this.videoStyleSelectable;

    query += '&hideParent='+this.hideParent;
    query += '&subDisplay='+this.subDisplay;

    if (this.autoLoadID != null)
      query += '&autoLoadID='+this.autoLoadID;

    param = ''; embed = '';
    if(this.bgcolor == null){
      param = '<param name="wmode" value="transparent" />';
      embed = 'wmode="transparent" ';
    } else {
      param = '<param name="bgcolor" value="'+this.bgcolor+'" />';
      embed = 'bgcolor="'+this.bgcolor+'" ';
    }

    flashCode = '';
    flashCode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab// - version=7,0,0,0" width="'+this.width+'" height="'+this.height+'" name="'+swf_id+'" id="'+swf_id+'" />';
    flashCode += '<param name="movie" value="'+this.path+this.script+'?'+query+'" />';
    flashCode += '<param name="scale" value="noscale" />';
    flashCode += '<param name="loop" value="false" />';
    flashCode += '<param name="menu" value="false" />';
    flashCode += '<param name="quality" value="high" />';
    flashCode += '<param name="salign" value="lt" />';
    flashCode += param;
    flashCode += '<embed src="'+this.path+this.script+'?'+query+'" width="'+this.width+'" height="'+this.height+'" '+embed+' loop="false" menu="false" quality="high" scale="noscale" salign="lt" name="'+swf_id+'" id="'+swf_id+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    flashCode += '</object>';

    document.write(flashCode);

  }

  // ----------------------------------------------------------------------------------------------------------------
  this.winResize = function() {
    var new_w = this.winWidth;
    var new_h = this.winHeight;
    var old_w = window.innerWidth || window.document.body.offsetWidth;
    var old_h = window.innerHeight || window.document.body.offsetHeight;
    if (!new_w) { new_w = old_w; }
    if (!new_h) { new_h = old_h; }
    new_w -= old_w;
    new_h -= old_h;
    new_h += 30;
    window.resizeBy(new_w + 24,new_h + 24);
  }

  return 1;
}

function wmvPlayer() {
  this.path                 = basePath;
  this.width                = '400';
  this.height               = '320';
  this.winWidth             = '580';
  this.winHeight            = '520';

  // ----------------------------------------------------------------------------------------------------------------
  this.render = function() {

    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
      var pos = parms[i].indexOf('=');
      if (pos > 0) {
        var key = parms[i].substring(0,pos);
        var val = parms[i].substring(pos+1);
        eval('this.'+key+' = val');
      }
    }

    this.writeWMV();
  }

  // ----------------------------------------------------------------------------------------------------------------
  this.writeWMV = function() {

    wmpCode = '';

    // wmpCode += '<embed allowScriptAccess="never" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" width="'+this.width+'" height="'+this.height+'"';
    // wmpCode += ' autostart="1" showcontrols="1" volume="50" src="http://localhost/MarkMaverick.com/'+this.filePath+'"></embed>';

    // wmpCode += '<object name="omPlayer" width="'+this.width+'" height="'+this.height+'" type="application/x-oleobject" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
    // wmpCode += '<param name="url" value="'+this.path+this.filePath+'"><param>';
    // wmpCode += '<param name="autostart" value="true"></param>';
    // wmpCode += '<param name="showcontrols" value="true"></param>';
    // wmpCode += '<embed width="'+this.width+'" height="'+this.height+'" src="'+this.path+this.filePath+'" type="application/x-oleobject" autostart="true"></embed>';
    // wmpCode += '</object>';

    // wmpCode += '<OBJECT id="omPlayer" width="'+this.width+'" height="'+this.height+'" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">';
    // wmpCode += '  <PARAM NAME="URL" VALUE="'+this.path+this.filePath+'">';
    // wmpCode += '  <PARAM NAME="AutoStart" VALUE="True">';
    // wmpCode += '  <PARAM NAME="uiMode" value="mini">';
    // wmpCode += '  <PARAM NAME="PlayCount" value="1">';
    // wmpCode += '</OBJECT>';

    wmpCode += '<object id="omPlayer" width="'+this.width+'" height="'+this.height+'" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft® Windows® Media Player components..." type="application/x-oleobject">';
    wmpCode += '<param name="FileName" value="'+this.path+this.filePath+'">';
    wmpCode += '<param name="ShowStatusBar" value="True">';
    wmpCode += '<embed type="application/x-mplayer2" pluginspage = "http://www.microsoft.com/Windows/MediaPlayer/" src="'+this.path+this.filePath+'" align="middle" width="'+this.width+'" height="'+this.height+'"></embed>';
    wmpCode += '/object>';

    document.write(wmpCode);

  }

  return 1;
}