// randcom_content.js
// random content every time you refresh a page, pretty simple
// James Asher
// 10/5/04


// just the URI to the image
// leave null if you don't want an image
var images = new Array();

// just the URI for where you want to go when you click the image
// leave null if you don't want it to be a link
// if you use the image_dir variable (below), then just put image name
// and not full path to it
var links = new Array();

// the text you want under the image, can be formatted
// leave null if you don't want text
// if you use the links_dir variable (below), then just put file name
// and not full path to it
var text = new Array();

// shorthand for directories, leave null if you don't want to use them
var images_dir = 'graphics/';
var links_dir = '';

//for each entry, the numbers must be the same

images[1]  = '8-leaf-corn-field.jpg';
links[1]   = '';
text[1]    = 'No-till corn at 8-leaf stage';

images[2]  = 'Carbon-Cycle1.jpg';
links[2]   = '';
text[2]    = 'The carbon cycle';

images[3]  = 'cons_stripcropping.jpg';
links[3]   = '';
text[3]    = 'Conservation strip cropping';

images[4]  = 'No-Till-Corn-Af-Corn.jpg';
links[4]   = '';
text[4]    = 'No-till continuous corn';

images[5]  = 'NT-Milo-at-N-Farm-Closeup.jpg';
links[5]   = '';
text[5]    = 'No-till grain sorghum';

images[6]  = 'Putting-Soil-Sample-into-th.jpg';
links[6]   = '';
text[6]    = 'Taking soil sample for analysis';

images[7]  = 'tully_profile2.jpg';
links[7]   = '';
text[7]    = 'Soil with high soil organic carbon level';

function random_content() {
 var size = Math.floor(Math.random()*images.length);
 if (size==0) {
  size = 1;
 }
 write_content(size);
}

function attach_html(html) {
 var rightContent = document.getElementById('rightContent');
 rightContent.insertBefore(html,rightContent.firstChild);
 return true;
}

function write_content(s) {
 var html = document.createElement('div');
 html.style.marginBottom = '0';

 var the_image = '';
 var the_link  = '';
 var the_text  = '';

 if (links[s] != '') {
  if (images[s] != '') {
   if (text[s] != '') {
    the_image = document.createElement('img');
    the_image.setAttribute('src',images_dir + images[s]);
    the_image.setAttribute('alt','Image: '+text[s]);
    the_link = document.createElement('a');
    the_link.setAttribute('href', links[s]);
    the_link.appendChild(the_image);
    the_text = document.createElement('p');
    the_text.style.textAlign = 'center';
    var the_text_text = document.createTextNode(text[s]);
    the_text.appendChild(the_text_text);
    var p = document.createElement('p');
    p.style.margin = '0';
    p.appendChild(the_link);
    html.appendChild(p);
    html.appendChild(the_text);
    attach_html(html);
    return true;
   } else {
    the_image = document.createElement('img');
    the_image.setAttribute('src',images_dir + images[s]);
    the_image.setAttribute('alt','Image: '+links[s]);
    the_link = document.createElement('a');
    the_link.setAttribute('href', links[s]);
    the_link.appendChild(the_image);
    html.appendChild(the_link);
    attach_html(html);
    return true;
   }
  } else {
   if (text[s] != '') {
    the_image = document.createElement('img');
    the_image.setAttribute('src',images_dir + images[s]);
    the_image.setAttribute('alt','Image: '+text[s]);
    the_text = document.createElement('p');
    the_text.style.textAlign = 'center';
    var the_text_text = document.createTextNode(text[s]);
    the_text.appendChild(the_text_text);
    var p = document.createElement('p');
    p.style.margin = '0';
    p.appendChild(the_image);
    html.appendChild(p);
    html.appendChild(the_text);
    attach_html(html);
    return true;
   } else {
    the_link = document.createElement('a');
    the_link.setAttribute('href', links[s]);
    var the_link_text = document.createTextNode(links[s]);
    the_link.appendChild(the_link_text);
    var p = document.createElement('p');
    p.style.margin = '0';
    p.appendChild(the_link);
    html.appendChild(p);
    attach_html(html);
    return true;
   }
  }
 } else {
  if (images[s] != '') {
   if (text[s] != '') {
    the_image = document.createElement('img');
    the_image.setAttribute('src',images_dir + images[s]);
    the_image.setAttribute('alt','Image: '+text[s]);
    the_text = document.createElement('p');
    the_text.style.textAlign = 'center';
    var the_text_text = document.createTextNode(text[s]);
    the_text.appendChild(the_text_text);
    var p = document.createElement('p');
    p.style.margin = '0';
    p.appendChild(the_image);
    html.appendChild(p);
    html.appendChild(the_text);
    attach_html(html);
    return true;
   } else {
    the_image = document.createElement('img');
    the_image.setAttribute('src',images_dir + images[s]);
    the_image.setAttribute('alt','Image: '+images[s]);
    var p = document.createElement('p');
    p.style.margin = '0';
    p.appendChild(the_image);
    html.appendChild(p);
    attach_html(html);
    return true;
   }
  } else {
   if (text[s] != '') {
    the_text = document.createElement('p');
    the_text.style.textAlign = 'center';
    var the_text_text = document.createTextNode(text[s]);
    the_text.appendChild(the_text_text);
    html.appendChild(the_text);
    attach_html(html);
    return true;
   } else {
     alert('The random content generator is broken, whooops. Tell someone.');
    return false;
   }
  }
 }
}
