/**
 * Method to add a drop shadow to the specific target element.
 * Requires accompanying style sheet specifying base styles for classes sh1 to sh4
 * Notes:
 * CSS ID - any positional styles must be applied to the id (not the class). Must not have any other visual styles (border, backgrounds, etc)
 * CSS class - no position styles (i.e. position, top, right, bottom or left), only visual styles
 * Changes to target's visibility property should be done after the shadow is applied.
 */
function addShadow(target, shadowClass, shadowSize, offsetTop, offsetLeft )
{
  if( document.getElementById && document.createElement )
  {
    var targ = getElt(target);

    if( targ.getAttribute("shadow") > "" )
    {
      refreshShadow( targ );
      return;
    }

    var id = targ.id;
    var wrap = document.createElement('div'); // inherits target ID and wraps all
    var shad = document.createElement('div'); // layer containing shadow
    var a = document.createElement('div');
    var b = document.createElement('div');
    var c = document.createElement('div');
    var d = document.createElement('div');

    wrap.setAttribute("shadow","true");
    shad.className = shadowClass;
    a.className = "sh1";
    b.className = "sh2";
    c.className = "sh3";
    d.className = "sh4";
    shad.appendChild(a);
    shad.appendChild(b);
    shad.appendChild(c);
    shad.appendChild(d);
    shad.id = id + ".shadow"; // add an id to shadow ot provide a handle to move or change visibility
    shad.setAttribute("size",shadowSize);
    shad.setAttribute("top",offsetTop);
    shad.setAttribute("left",offsetLeft);

    targ.id = id+".shadowed"; //change original target's ID so we can still get to it
    wrap.id = id;

    var ws = wrap.style;
    var ts = targ.style;
    ws.position =((getlayerstyle( targ ).position == "absolute")?("absolute"):("relative"));
    ws.visibility = ts.visibility;
    ws.top = ts.top;
    ws.left = ts.left;
    ws.bottom = ts.bottom;
    ws.right = ts.right;
    ws.zIndex = ts.zIndex;
    ts.top = ts.left = ts.bottom = ts.right = ts.zIndex = "";
    ts.visibility = "inherit";
    ts.position = "relative";
    targ.parentNode.appendChild(wrap);
    wrap.appendChild(shad);
    wrap.appendChild(targ);

    sizelayer( shad, getlayerwidth(wrap)+shadowSize+"px", getlayerheight(wrap)+shadowSize + "px" );

    shad.style.marginLeft = (getlayerleft(targ)-getlayerleft(wrap)) + (offsetLeft-(shadowSize/2)) + "px";
    shad.style.marginTop  = (getlayertop(targ)-getlayertop(wrap)) + (offsetTop-(shadowSize/2)) + "px";
  }
}
function refreshShadow( target )
{
  var targ = getElt(target);
  var shad = getElt(targ.id + ".shadow");
  if( typeof(shad) == "undefined" )
  {
    return;
  }
  var shadowSize = parseInt(shad.getAttribute("size"),10);
  sizelayer( shad, getlayerwidth(targ)+shadowSize+"px", getlayerheight(targ)+shadowSize + "px" );
}
