/* Grab_random.js
   three public functions:

   right_bar()   
   spits out a random image and caption for the right column
   
   bullet()
   spits back a random 110x30 bullet graphic
   
   featured_creation()
   spits out a random image and stats for a featured creation
   */
   
// return a random integer between 0 and n
function random_int(max_n){
  return (Math.round(Math.random() * max_n))
  }
  
// create appropriate code for right column image and caption
// according to index number 'idx'
function generate_right_bar_table(idx){

  // set up the table
  // (FIXED)
  document.write('<table width="200" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="images/')
  
  // select the image
  // (VARIABLE)
  if (idx==0){document.write('giant.jpg" width="200" height="389" alt="Nice Shades"')}
  if (idx==1){document.write('gonk.jpg" width="200" height="400" alt="Gonk... Gonk... Boom!"')}
  if (idx==2){document.write('hammer.jpg" width="200" height="400" alt="A Shining Beacon of Justice"')}
  if (idx==3){document.write('hatchet.jpg" width="200" height="370" alt="Time to Rip You a New Axe Hole"')}
  if (idx==4){document.write('milk.jpg" width="200" height="437" alt="Got Milk?"')}
  if (idx==5){document.write('monster.jpg" width="200" height="359" alt="Popping Soldiers Like Water Balloons"')}
  if (idx==6){document.write('sheep.jpg" width="200" height="349" alt="Baa"')}
  if (idx==7){document.write('spaceman.jpg" width="200" height="400" alt="A Grim Killer"')}
  if (idx==8){document.write('timmies.jpg" width="200" height="375" alt="The Bane of All that is Good"')}
	
  // border between frames, set up sub-table
  // (FIXED)
  document.write('></td></tr><tr><td><table width="200" border="0" cellspacing="0" cellpadding="8"><tr>')
  document.write('<td><font face="Arial, Helvetica, sans-serif" size="-1" color="#333333"><b>')

  // titlebar text
  // (VARIABLE)
  if (idx==0){document.write('Four in One Blow</b><br><font size="-2">&quot;NELUG Gets Medieval&quot;<br>')
              document.write('<a href="http://www.nelug.org/">NELUG</a> - Nov. 18, 2000')}
  if (idx==1){document.write('The Deadly Gonk</b><br><font size="-2"><a href="http://www.nelug.org/">')
              document.write('NELUG</a> - April 30, 2000')}
  if (idx==2){document.write('The Hammer of Discipline</b><br><font size="-2">&quot;NELUG Gets Medieval&quot;<br>')
              document.write('<a href="http://www.nelug.org/">NELUG</a> - Nov. 18, 2000')}
  if (idx==3){document.write('Burying the Hatchet</b><br><font size="-2">&quot;BrikWars 1942!&quot;<br>')
              document.write('<a href="http://www.nelug.org/">NELUG</a> - July 26, 2000')}
  if (idx==4){document.write('It Does a Body Good</b><br><font size="-2">Mike Rayhawk, 2002')}
  if (idx==5){document.write('Recipe for Troopersauce</b><br><font size="-2">&quot;The Battle of Mount Jar Jar&quot;<br>')
              document.write('<a href="http://www.bloconline.org/">BLOC</a> - April 15, 2000')}
  if (idx==6){document.write('Flying Sheep</b><br><font size="-2">&quot;NELUG Gets Medieval&quot;<br>')
              document.write('<a href="http://www.nelug.org/">NELUG</a> - Nov. 18, 2000')}
  if (idx==7){document.write('The Deadly SpaceMan</b><br><font size="-2">Mike Rayhawk, 2001')}
  if (idx==8){document.write('The Fall of Brick Civilization</b><br><font size="-2">Mike Rayhawk, 2002')}
			  
  // sub-sub-table
  // (FIXED)			  
  document.write('<br></font></font><table border="0" cellspacing="0" cellpadding="8">')
  document.write('<tr><td><font face="Arial, Helvetica, sans-serif" size="-1" color="#666666">')

  // sub-sub-table text
  // (VARIABLE)
  if (idx==0){document.write('Eric Joslin&#146;s armored giant strikes a suave pose after smashing ')
              document.write('four enemy troopers with a single swing of his mighty flail.')}
  if (idx==1){document.write('Shaun Sullivan&#146;s innocuous-seeming Gonk droids turn out to be deadly ')
              document.write('walking kamikaze bombs, much to the surprise and dismay of these enemy troopers.')}
  if (idx==2){document.write('The Hammer of Discipline, usually a mallet kept at the gaming table for players ')
              document.write('to use on one another, is converted to a mighty weapon within the game by Eric Joslin.')
			  document.write('&nbsp; Here, his champion has slain both horse and rider with a single mighty blow of the Hammer.')}
  if (idx==3){document.write('&quot;After wiping out one of the other German sentries, the Jeep crew moved into town. A hail ')
              document.write('of small arms fire engulfed the crew. Unable to swing his heavy machine gun around in time to ')
			  document.write('hit one pistol-wielding German, this Private decided a more hands-on approach was needed...&quot;')
			  document.write('<font size="-2"> - Eric Joslin</font>')}
  if (idx==4){document.write('&quot;Milk does a body good. Not only does it give a Trooper strong bones and muscles, it ')
              document.write('envelops him in a protective energy field. This field appears as a glowing white aura with ')
			  document.write('large black spots and an occasional large pink udder.&quot; <font size="-2">- 2.4.4: Magical ')
			  document.write('Potions</font>')}
  if (idx==5){document.write('Knowing that soldiers are unable to resist the compulsion to destroy Timmies wherever they ')
              document.write('may hide, this evil burp-monster kept a captive Timmy in his lair in order to lure troopers ')
			  document.write('up for a good smashing.')}
  if (idx==6){document.write('Unable to reach the enemy wizard in time to prevent him from casting a deadly spell, this giant ')
              document.write('made a desperate grab for whatever projectile was closest at hand.&nbsp; With no time to tear a ')
			  document.write('boulder up from the ground, the giant surprised his target by instead hurling a nearby sheep.')}
  if (idx==7){document.write('Bioengineered and optimized for combat, the deadly SpaceMan is arguably the most dangerous form ')
              document.write('of minifig life ever devised by scientists.')}
  if (idx==8){document.write('Once upon a time, the brick universe was a pure and wonderful place, full of high-quality sets ')
              document.write('and solid construction techniques.&nbsp; Then Timmy arrived and their deadly juniorization began ')
			  document.write('to corrupt all aspects of brick reality!&nbsp; For this reason, the vile Timmy is hated and ')
			  document.write('feared by all virtuous minifigs.')}

  // end sub-sub-table
  // (FIXED)
  document.write('</font></td></tr></table><font face="Arial, Helvetica, sans-serif" font size="-2">')
  
  // links
  // (VARIABLE)
  if (idx==0){document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw/medi1/linedancing2.html">full image</a> | ') 
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=13900">gallery</a> | ')
              document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw/medi1.html">write-up</a>')}
  if (idx==1){document.write('<a href="http://www.nelug.org/bw043000pics/bw043000_11.jpg">full image</a> | ')
              document.write('<a href="http://www.nelug.org/bw043000/">gallery</a>')}
  if (idx==2){document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw/medi1/torsten.html">full image</a> | ')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=13900">gallery</a> | ')
			  document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw/medi1.html">write-up</a></')}
  if (idx==3){document.write('full image: (<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=9309">top</a>) (')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=9310">bottom</a>) | ')
			  document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=947">gallery</a> | ')
			  document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw1942.html">write-up</a>')}
  if (idx==4){document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=148568">full image</a> | ')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=14915">gallery</a>')}
  if (idx==5){document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=3811">full image</a> | ')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=374">gallery</a> | ')
			  document.write('<a href="http://www.netpluscom.com/%7Edrew/lego/brikwar/brikwar.html">write-up</a></')}
  if (idx==6){document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw/medi1/sheeptoss2.html">full image</a> | ')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=13900">gallery</a> | ')
			  document.write('<a href="http://people.thirteen.net/%7Eeric/lego/bw/medi1.html">write-up</a>')}
  if (idx==7){document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=148564">full image</a> | ')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=14915">gallery</a>')}
  if (idx==8){document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=148574">full image</a> | ')
              document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=14915">gallery</a>')}

  // end table
  // (FIXED)
  document.write('</font></td></tr></table></td></tr></table>')
  }

// generate code for a bullet graphic according to index
function generate_bullet(idx){
  document.write('<img src="images/bull')
  if (idx<10){document.write('0')}
  document.write((idx)+'.gif" width="95" height="25" vspace="5" hspace="5">')
  }

//generate code for two table cells for the f_c stats table
function fc_stats_row(stat, val){
  document.write('<tr><td align="center"><font size="-1" color="#663300">')
  document.write(stat)
  document.write(':</font></td><td align="center" bgcolor="#FFFFFF"><font size="-1" color="#663300">')
  document.write(val)
  document.write('</font></td></tr>')
  }

//generate one cell in the weapon table
function fc_weap_cell(val){
  document.write('<td align="center"><font size="-2" color="#663300">')
  document.write((val))
  document.write('</font></td>')
  }

//generate code for one weapon row in the f_c weapons table
function fc_weapon_row(weapon, pwr, ur, rng, dmg, notes){
  document.write('<tr bgcolor="#FFFFFF"><td><font size="-2" color="#663300">')
  document.write((weapon))
  document.write('</font></td>')
  
  fc_weap_cell(pwr)
  fc_weap_cell(ur)
  fc_weap_cell(rng)
  fc_weap_cell(dmg)
  fc_weap_cell(notes)

  document.write('</tr>')
  }


// generate code for the Featured Creation table according to index
function generate_featured_creation(idx){
  document.write('<table border="1" cellspacing="0" cellpadding="2" bgcolor="#F7F2E1" bordercolor="#D7CCB5">')
  document.write('<tr><td colspan="2"><font size="-1"><b><font color="#996633" size="-2">FEATURED CREATION</font><br><font color="#000000">')

  document.write('Panzer VI Tiger Tank')
  document.write('</font></b><font color="#663300"> by <b>')

  document.write('Shaun Sullivan')
  document.write('</b></font></font></td></tr><tr><td align="center"><table border="0" cellspacing="0" cellpadding="3"><tr> <td colspan="2"><font size="-1">')

  document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=120278"><img src="images/fans/tank.jpg" width="200" height="94" border="1"></a>')
  document.write('</font></td></tr><tr><td align="center"><font size="-2">')
  
  document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?i=120278">full image</a>')
  document.write('</font></td><td align="center"><font size="-2">')
  
  document.write('<a href="http://www.brickshelf.com/cgi-bin/gallery.cgi?f=11143">BrickShelf gallery</a>')
  document.write('</font></td></tr><tr><td colspan="2" align="center"><font size="-2" color="#996633">image copyright ')
  
  document.write('(c)2002 Shaun Sullivan')
  document.write('</font></td></tr></table></td><td align="center"><table border="1" cellspacing="0" cellpadding="2" bordercolor="#F7F2E1" width="100">')

  fc_stats_row("Move","11&quot;")

  fc_stats_row('Turn','0&quot;')
  fc_stats_row('A/D','3&quot;')
  fc_stats_row('Pwr','14')
  fc_stats_row('CC&quot;','21&quot;')
  fc_stats_row('AV','6d10+8')

  document.write('</table></td></tr>')
  document.write('<tr><td colspan="2"><table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#F7F2E1">')

  document.write('<tr><td><b><font size="-2" color="#663300">Weapon</font></b></td>')

  fc_weap_cell('<b>Pwr</b>')
  fc_weap_cell('<b>UR</b>')
  fc_weap_cell('<b>Rng&quot;</b>')
  fc_weap_cell('<b>Dmg</b>')
  fc_weap_cell('<b>Notes</b>')

  document.write('</tr>')

  fc_weapon_row('88mm Gun', '12', '7', '20&quot;', '4d10', 'exp, slow')
  fc_weapon_row('2 x MG34 MG', '2', '3 (6*)', '20&quot;', '2d6+2', '(* - auto)')

  document.write('</table></td></tr></table>')
  }



/* -------------------------------------------------------------------
   PUBLIC FUNCTIONS
   ------------------------------------------------------------------- */

// choose a random index for right-column content and generate the code
function right_bar(){
  var rand_idx=(random_int(8))
  generate_right_bar_table(rand_idx)
  }
  
// choose a random bullet graphic and generate the code
function bullet(){
  var rand_idx=(random_int(30))
  generate_bullet(rand_idx)
  }

// choose a random index for the featured-creation table and generate the code
function featured_creation(){
  // var rand_idx=(random_int(0))
  generate_featured_creation(0)
  }
