var PLnowPlaying=0;
var PLreload=1;

function thisMovie(movieName) {
  return (navigator.appName.indexOf("Microsoft") != -1) ? window[movieName] : document[movieName];
}

function premiumShow(showID) {
  // get flash player to display premium content screen
  // if a show is already playing, remove playing indicator
  PLnowPlaying = document.getElementById( 'PLnowPlaying' ).value;

  if ( PLnowPlaying == showID ) {
	// user clicking the stop button on locked shop they tried playing
	document.getElementById( 'show' + PLnowPlaying ).className='show';
	document.getElementById( 'play' + PLnowPlaying ).className='showlock';
	thisMovie('modustv').stopPlayback();
    document.getElementById( 'PLnowPlaying' ).value = false;
  } else if ( PLnowPlaying > 0 ) {
	// a show other than the locked show playing - stop it
	thisMovie('modustv').stopPlayback();
	document.getElementById( 'show' + PLnowPlaying ).className='show';
	document.getElementById( 'play' + PLnowPlaying ).className='showplay0';
    document.getElementById( 'PLnowPlaying' ).value = false;
  }

  if ( PLnowPlaying != showID ) {
	  document.getElementById( 'show' + showID ).className='show-playing';
	  document.getElementById( 'play' + showID ).className='showplaystop';
	  document.getElementById( 'show' + showID ).blur();
	  document.getElementById( 'PLnowPlaying' ).value = showID;
	  thisMovie('modustv').premiumShow();
	}
}

function playShow(showID) {
  PLnowPlaying = document.getElementById( 'PLnowPlaying' ).value;
  if ( PLnowPlaying == showID ) {
	// if they clicked the play button on a playing show, stop it (it will have a stop icon)
	// alternatives for using images behing playlist items commented out
	document.getElementById( 'show' + PLnowPlaying ).className='show';
	document.getElementById( 'play' + PLnowPlaying ).className='showplay0';
	document.getElementById( 'PLnowPlaying' ).value = 0;
	thisMovie('modustv').stopPlayback();
	return false;
  }
  // if a show is already playing, stop it, and remove playing indicator
  if ( PLnowPlaying > 0 ) {
	document.getElementById( 'show' + PLnowPlaying ).className='show';
	document.getElementById( 'play' + PLnowPlaying ).className='showplay0';
  }
  document.getElementById( 'show' + showID ).className='show-playing';
  document.getElementById( 'play' + showID ).className='showplaystop';
  document.getElementById( 'show' + showID ).blur();
  document.getElementById( 'PLnowPlaying' ).value = showID;
  thisMovie('modustv').loadShow(showID);
}

function playFinished() {
  // called by flash video player when current show has been completed
  //reset display for show that just finished
  PLnowPlaying = document.getElementById( 'PLnowPlaying' ).value;

  document.getElementById( 'show' + PLnowPlaying ).className='show';
  document.getElementById( 'play' + PLnowPlaying ).className='showplay0';
  if ( 
	  PLreload 
	  && document.getElementById( 'nextURL' + PLnowPlaying ) != undefined 
	  && document.getElementById( 'nextURL' + PLnowPlaying ).value != ''
	  ) {
	// reload page for next show
	window.location = document.getElementById( 'nextURL' + PLnowPlaying ).value;
  } else if ( 
			 document.getElementById( 'next' + PLnowPlaying ) != undefined 
			 && document.getElementById( 'next' + PLnowPlaying ).value > 0 
			 ) {
	// else change playlist dynamically and play in-place
	playShow(document.getElementById( 'next' + PLnowPlaying ).value);
  } else {
	// nothing else to play
	PLnowPlaying = false;
	document.getElementById( 'PLnowPlaying' ).value = false;
  }
}
