/*
###############################################################################
Purpose: defines an array of image sections and the number of images in that
section. The page calls the changeheader() function fo get a random image from
the section they pass as the first argument.
###############################################################################

###############################################################################
Configuration
###############################################################################

------------------------------------------------------------------
Define the sets of images
------------------------------------------------------------------

Each record in this array gives the name of the section (section_name) and the
number of possible random images in that section (section_items). The two
elements of data are separated by a vertical bar. the section_name forms the
prefix of the physical image file the rest of the file name is a hyphen, then
the random number between 1 and section_items, then an 'a' or 'b' to denote the
image used for s_dom_element_id_upper or for s_dom_element_id_lower

------------------------------------------------------------------
*/

var a_section_images = [
	"articles|2",
	"buying|4",
	"commercial|9",
	"community|4",
	"selling|4",
	"statistics|2",
	"vreb|3",


	"victoria|2",
	"find|2",
	"why|2",
];

// ------------------------------------------------------------------
// The path to the header images folder
// ------------------------------------------------------------------
var s_header_images_path   = "/images/headers/";

// ------------------------------------------------------------------
// the IDs of elements that are having the images randomly changed
// ------------------------------------------------------------------
var s_dom_element_id_upper = "mainimageflip";
var s_dom_element_id_lower = "bodycontent";



function changeheader(s_section){
	b_found = false;
	for(i=0; i < a_section_images.length && !b_found; i++){
	  var a_section = a_section_images[i].split("|");
	  if(a_section[0] == s_section){
	  	b_found = true;
	  }
	}
	if(!b_found){
		return b_found;
	}

	// ------------------------------------------------------------------
	// choose a random number between 0 and how many items there are in a_section[1].
	// ------------------------------------------------------------------
	var i_rand          = Math.floor(Math.random() * a_section[1]) + 1;


	// ------------------------------------------------------------------
	// Create variables for the upper and lower images
	// ------------------------------------------------------------------
	var s_img_url_upper = "'/images/headers/" + s_section + "-" + i_rand + "a.jpg'";
	var s_img_url_lower = "'/images/headers/" + s_section + "-" + i_rand + "b.jpg'";

	// ------------------------------------------------------------------
	// Alter the two images on the page
	// ------------------------------------------------------------------
	document.getElementById(s_dom_element_id_upper).src                   = eval(s_img_url_upper);
	//document.getElementById(s_dom_element_id_upper).alt                   = eval(s_img_url_upper);
	//document.getElementById(s_dom_element_id_lower).style.backgroundImage = "url(" + s_img_url_lower + ")";
	document.getElementById(s_dom_element_id_lower).style.background = "url(" + s_img_url_lower + ") top right no-repeat";

	return b_found;
}
