﻿//dependency: jquery

Share = function(serverURL) {

  Share.prototype.embedQT = 
    '<OBJECT WIDTH="300" HEIGHT="242" CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"> \
      <PARAM name="SRC" VALUE="http://{0}/ArcAsx.aspx?pt=qt&id={1}"> \
      <PARAM name="QTSRC" VALUE="http://{0}/ArcAsx.aspx?pt=qt&id={1}"> \
      <PARAM name="CONTROLLER" VALUE="true"> \
      <PARAM name="SCALE" VALUE="ASPECT"> \
      <EMBED SRC="http://{0}/media/stream.ashx?id={1}" QTSRC="http://{0}/media/stream.ashx?id={1}" WIDTH="300" HEIGHT="242" SCALE="ASPECT" \
        CONTROLLER="true" PLUGINSPAGE="http://www.apple.com/quicktime/download/"/> \
    </OBJECT>'.replace(/\{0\}/g,serverURL);

  Share.prototype.embedWM = 
    '<OBJECT height="306" width="322" CLASSID="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"> \
      <PARAM NAME="URL" VALUE="http://{0}/ArcAsx.aspx?pt=wm&id={1}"> \
      <PARAM NAME="stretchToFit" VALUE="1"> \
      <embed type="application/x-mplayer2" width="322" height="306" src="http://{0}/media/stream.ashx?pt=wm&id={1}" stretchToFit="1" showcontrols="1"/> \
    </OBJECT>'.replace(/\{0\}/g,serverURL);
    
  Share.prototype.embedFL = 
    '<object type="application/x-shockwave-flash" data="http://{0}/flvPlayer.swf?videoPath=http://{0}/media/StreamArchiveFlv.ashx?id={1}&imagePath=http://{0}/media/LargeThumb.ashx?id={1}&autoStart=false&volAudio=50&newWidth=320&newHeight=265" width="320" height="265"> \
      <param name="allowFullScreen" value="true"/> \
      <param name="movie" value="http://{0}/flvPlayer.swf?videoPath=http://{0}/media/StreamArchiveFlv.ashx?id={1}&imagePath=http://{0}/media/LargeThumb.ashx?id={1}&autoStart=false&volAudio=50&newWidth=320&newHeight=265" /> \
      <param name="quality" value="high" /> \
      <param name="scale" value="noScale" /> \
    </object>'.replace(/\{0\}/g,serverURL);

  Share.prototype.link = 'http://{0}/{1}'.replace(/\{0\}/g,serverURL);
};

Share.prototype = {  

  mediaID: 0,
  player: '_',
  username: '_',
  isLive: false,
  
  changeMedia: function(mediaID) {
    this.isLive = false;
    this.mediaID = mediaID;
    this.populateLinkBox();
    this.populateEmbedBox();
  },

  livestream: function(username) {
    this.isLive = true;
    this.username = username;
  },

  setLivecast: function(webcastID) {
    if(this.isLive) {    
      this.mediaID = webcastID;
      this.populateLinkBox();
      this.populateEmbedBox(true);
    }
  },

  populateLinkBox: function(username) {
    var url;
    if(this.isLive) url = this.link.replace(/\{1\}/g, this.username);
    else url = (this.mediaID == 0) ? '' : this.link.replace(/\{1\}/g, this.mediaID);
    $('#VideoURL').val(url);
  },
  
  populateEmbedBox: function(force) {
    $('#EmbedQT').val(Share.prototype.embedQT.replace(/\{1\}/g, this.mediaID));
    $('#EmbedWM').val(Share.prototype.embedWM.replace(/\{1\}/g, this.mediaID));
    $('#EmbedFlash').val(Share.prototype.embedFL.replace(/\{1\}/g, this.mediaID));
  }
  
};