// v2.6 START of autoimagemapsupport.js
// generate image map start code.

var mapimage, mapimagewidth, mapimageheight, mapcolumns, maprows, mapfocus, mapprodref;
var mapcolwidth, maprowheight, mapcolpos, maprowpos, mapspotwidth, mapspotheight, mapstartx, mapstarty;
var mapcol, maprow, mapselect, mapcode;
var mapattrib = '';			// set to impossible value
var attribname = '';		        // default is no map generation

function mapparams(mattrib, mimage, mimagewidth, mimageheight, mcolumns, mrows, mfocus, mprodref)
  {
  // set up the globals
  mapattrib = mattrib;			// name of Attribute Map is for
  mapimage = mimage;			// get the image name
  mapimagewidth = mimagewidth;   	// image width (pixels)
  mapimageheight = mimageheight; 	// image height (pixels)
  mapcolumns = mcolumns;		// number of columns
  maprows = mrows;			// number of rows
  mapfocus = mfocus;   			// sweet spot e.g. set to .8 for 80%
  mapprodref = mprodref; 		// set the current product reference
  document.write('<IMG BORDER=0 USEMAP="#Map' + mapprodref + '" SRC="' + mapimage + '" width="' + mapimagewidth + '" height="' + mapimageheight + '">');
  }

function mapset(fieldname,select)	// make the selected item active
  {
  var thisselect = document.getElementById(fieldname);
  if (thisselect) thisselect.selectedIndex = select - 1;
  }

function mapstart(attribref)
  {
  if ( (attribname == '') || (attribname != mapattrib) ) return;	// abandon if no map required
  mapselect = attribref;						// remember select name			
  mapcode = ('<map name="Map' + mapprodref + '">');                     // create the map  <map name="PRODUCTREFERENCE">
  mapcolwidth = mapimagewidth / mapcolumns;				// column width
  maprowheight = mapimageheight / maprows;				// row height
  mapspotwidth = Math.round(mapcolwidth * mapfocus);			// width of sweet spot
  mapspotheight = Math.round(maprowheight * mapfocus);			// height of sweet spot
  mapstartx = Math.round((mapcolwidth - mapspotwidth) / 2);    		// start upper left
  mapstarty = Math.round((maprowheight - mapspotheight) / 2);  		// start upper left
  mapcol = 0;								// current column
  maprow = 0;
  }

function mapoption(choice,value)
  {
  if ( (attribname == '') || (attribname != mapattrib) ) return;	// abandon if no map required
  // generate e.g. <area shape="rect" coords="25,35,15,30" href="javascript:mapset('v_5_1',1)">
  var x = Math.round(mapstartx + (mapcol * mapcolwidth));               // our X start coord
  var p = x + mapspotwidth;						// X end
  var y = Math.round(mapstarty + (maprow * maprowheight));		// Y start
  var q = y + mapspotheight;						// Y end
  mapcode += ('<area shape="rect" alt="' + value + '" coords="' + x + ',' + y + ',' + p + ',' + q 
            + '" href="javascript:mapset(\'' + mapselect + '\',' + choice + ')">');
  if ( ++mapcol >= mapcolumns ) 					// move on a col (and row if necessary)
    {
    mapcol = 0;
    maprow++;
    } 
  }

function mapend()
  {
  if ( (attribname == '') || (attribname != mapattrib) ) return;	// abandon if no map required
  attribname = '';							// disable subsequent map generation
  document.write(mapcode + '</map>');					// end map and bung it all out
  }
    
// END of autoimagemapsupport.js
