// (C) 2007 by Jean-Christophe Koerber. All rights reserved.

function addForegroundItem (foreground, identity, image, width, height, line, address, text)
{
 foreground[foreground.length]=new ForegroundItem(identity, image, width, height, line, address, text);
}

function ForegroundItem (identity, image, width, height, line, address, text)
{
 this.identity=identity;
 this.image=image;
 this.width=width;
 this.height=height;
 this.line=line;
 this.address=address;
 this.text=text;
}

function processForegroundAnchor (foregroundItem)
{
 var element;
 var content;

 element=document.getElementById("anchor-"+foregroundItem.identity);

 if (element)
 {
  if (foregroundItem.address!="")
   element.href=foregroundItem.address;
  else
   element.href=foregroundItem.image;

  element.alt=foregroundItem.text;

  content="<div id=\"zone-"+foregroundItem.identity+"\"/></div>";

  element.innerHTML=content;
 }
}

function processForegroundZone (foregroundItem)
{
 var element;
 var content;

 element=document.getElementById("zone-"+foregroundItem.identity);

 if (element)
 {
  content="<img id=\"image-"+foregroundItem.identity+"\"";

  if (foregroundItem.width>0)
   content+=" width=\""+foregroundItem.width+"\"";

  if (foregroundItem.height>0)
   content+=" height=\""+foregroundItem.height+"\"";

  content+="></img>";

  if (foregroundItem.line!=true)
   content+="<br/>";

  content+="<i id=\"text-"+foregroundItem.identity+"\"></i>";

  element.innerHTML=content;
 }
}

function processForegroundImage (foregroundItem)
{
 var element;

 element=document.getElementById("image-"+foregroundItem.identity);

 if (element)
 {
  element.src=foregroundItem.image;
  element.alt=foregroundItem.text;
 }
}

function processForegroundText (foregroundItem)
{
 var element;

 element=document.getElementById("text-"+foregroundItem.identity);

 if (element)
 {
  element.innerHTML=foregroundItem.text;
 }
}

function buildForeground (foreground)
{
 var index;
 var maxIndex;
 var foregroundItem;

 if (foreground.length>0)
 {
  for (index=0, maxIndex=foreground.length; index<maxIndex; index++)
  {
   foregroundItem=foreground[index];

   processForegroundAnchor(foregroundItem);
   processForegroundZone(foregroundItem);
   processForegroundImage(foregroundItem);
   processForegroundText(foregroundItem);
  }
 }
}