<!--- Tag Attributes --->
<!--- Variable name to return selected FilmID as --->
<CFPARAM NAME="ATTRIBUTES.ReturnVariable" TYPE="variableName">
<!--- Use "ows" datasource by default --->
<CFPARAM NAME="ATTRIBUTES.DataSource" TYPE="string" DEFAULT="ows">

<!--- Need to lock when accessing shared data --->
<CFLOCK SCOPE="Session" TIMEOUT="10">

  <!--- List of movies to show (list starts out empty) --->
  <CFPARAM NAME="SESSION.MovieList" TYPE="string" DEFAULT="">
  
  <!--- If this is the first time we're running this,  --->
  <!--- Or we have run out of movies to rotate through --->
  <CFIF SESSION.MovieList EQ "">
    <!--- Get all current FilmIDs from the database --->
    <CFQUERY NAME="GetFilmIDs" DATASOURCE="#ATTRIBUTES.DataSource#">
      SELECT FilmID FROM Films
      ORDER BY MovieTitle
    </CFQUERY>

    <!--- Turn FilmIDs into a simple comma-separated list --->
    <CFSET SESSION.MovieList = ValueList(GetFilmIDs.FilmID)>
  </CFIF>

  <!--- Pick the first movie in the list to show right now --->
  <CFSET ThisMovieID = ListFirst(SESSION.MovieList)>
  <!--- Re-save the list, as all movies *except* the first --->
  <CFSET SESSION.MovieList = ListRest(SESSION.MovieList)>

  <!--- Return Chosen Movie to Calling Template --->
  <CFSET "CALLER.#ATTRIBUTES.ReturnVariable#" = ThisMovieID>
</CFLOCK>