var userId =        'SI06836';     // {string}             Unique identifier for Share International media; required.
var playerType =    'popup';       // {popup*|inline}      Popup (new) window or inline (inpage) placement.
var playerMenu =    'true';        // {true|false*}        'true' for jukebox style player; 'false' for single video.
var playerSize =    '100';         // {100*|200|full}      Relative player size, in percent, or full screen.
var playerQuality = 'high';        // {high*|low|          Relative quality of the Flash stream.
var mediaId =       '';	           // {string}             If no default media is preferred, then set to ''.
var mediaSuite =    '1';           // {1*|2|3|4|5}         Suite of media selections (jukebox only).
var mediaType =     'video';       // {video*|audio}       Not yet implemented.

var qsArray = new Array('userId','mediaId','mediaSuite','mediaType','playerType','playerMenu','playerSize','playerQuality','playerBgColor','autoPlay');
var playerMenu = window.playerMenu || 'true';
if (playerMenu) {var winWidth = 625; var winHeight = 410;} else {var winWidth = 360; var winHeight = 375;}
var leftPos = Math.round((screen.availWidth - winWidth)/2).toString();
var topPos = Math.round((screen.availHeight - winHeight)/2).toString();
var winDefinition = 'width='+winWidth+',height='+winHeight+',top='+topPos+',left='+leftPos+',menubar=0,toolbar=0,status=1,resizable=1,scrollbars=0,dependent=0';

function winQS() {																										// This function creates the QS.
	var QS='';for(var i=0;i<qsArray.length;i++){try{QS+='&'+qsArray[i]+'='+escape(eval(qsArray[i]).toString())}catch(e){}}QS=QS.substring(1,QS.length);return QS;
	}

function playMedia(mId) {
  if (window.winHandle) {																							// Include the 'window.' prefix to avoid an 'undefined' error if the popup has not yet been created
  	if (!winHandle.closed) {																					// If the popup window is still open, then
	  	winHandle.focus(); 																							//   focus and
	  	return false;																										//   return false so that the calling link will not take further action.
	  	}} 																															// If the popup has been closed, then reopen per below
  if (mId) mediaId = mId; 
	if (window.location.hostname == 'localhost') {
  	winURL = 'http://localhost/share-media.org/ShareMediaPlayer.html?' + winQS();
  } else {
  	winURL = 'http://www.share-media.org/ShareMediaPlayer.html?' + winQS();
    }
  winHandle = window.open(winURL,'ShareMedia',winDefinition); 				// Open the popup window
  if (window.winHandle) {																							// Ensure that the popup has been created
    return false;
  } else {
    var targ; var e = window.event;
    if (e.target) {targ = e.target;}
    else if (e.srcElement) {targ = e.srcElement;}
    if (targ.nodeType == 3) {targ = targ.parentNode;}
    targ.href = winURL;
    winHandle.focus();
    return true;
    }}

function playMedia2(mId) {
  var winURL = 'index2.htm?m=' + mId;
  window.location.href = winURL;
  return true;
  }

function queryString(qs) { 																						// optionally pass a querystring to parse
	this.params = new Object();
	this.get = Querystring_get;
	if (qs == null)
		qs = location.search.substring(1,location.search.length);
	if (qs.length == 0) return
	qs = qs.replace(/\+/g, ' ');																				// Turn <plus> back to <space>; // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	var args = qs.split('&') 																						// parse out name/value pairs separated via &
	for (var i=0;i<args.length;i++) {																		// split out each name=value pair
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])
		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		this.params[name] = value
	  }}

function Querystring_get(key, default_) {
	if (default_ == null) default_ = null;															// Changes UNDEFINED to NULL
	var value=this.params[key]
	if (value==null) value=default_;
	return value
  }

function showPopupPlayer(mId) {
  // Stop the inline player
	document.getElementById('MEDIA_PLAYER').src = '';
	document.getElementById('IFRAME_MEDIA_PLAYER').style.display = 'none';
	document.getElementById('ALTERNATE_TEXT').style.display = 'inline';
  document.getElementById('BASE_TARGET').target = '_self';
  // Show the popup player
  playerBgColor = '#fffff0';
  playerType = 'popup';
  playerMenu = 'true';
  return playMedia('x');																									// Send a dummy mediaId, to emulate the actual behavior when serving from localhost
  }


