var stub = "movie" ;
var unstub = /^movie(\d+)$/ ;
var size = { w:350, h:300 };

function go() {
  addDOM() ;
  ids = getrolls( stub) ;
  initrolls( ids) ;
}

function getrolls( stub) {
  i = 0 ;
  rolls = [] ;

  while ( 
	 (A = document.getEl( stub + ++i))
	 &&
	 (I = document.getEl( "I_" + stub + i))
	 ) {
    rolls[ rolls.length] = stub + i ;
  }
  return rolls ;
}

function launch( el) {

  pos = position( el.id, size) ;
  mypop( el.href, el, {                  // add one as 0s will be ignored
                        screenX:pos.x + 1
			, screenY:pos.y + 1
                        , width:size.w 
                        , height:size.h
				  }
	 ) ; return; 
}

// avoid opening twice
function mypop( href, el, opts) {
  if (el.popup &&  el.popup.close) el.popup.close() ; 
  el.popup = popup( opts, href) ;
  el.popup.focus() ;
} 

// work out where to put the movie
function position( id, size) {
  number = id.replace( unstub, "$1") ;
  rows = screen.availHeight / size.h ;
  cols = screen.availWidth / size.w ;

  pos = { 
       x:(((number - 1) % cols) * size.w)
       ,y:((Math.floor(number / cols) % rows) * size.h)
  } ;
  //  alert( pos.x + " : " + pos.y) ;
  return pos;
}

