/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: JTricks.com :: http://www.jtricks.com/ */

function move_box(an, box) {
  var cleft = 0;
  var ctop = 0;
  var obj = an;
  while (obj.offsetParent) {
    cleft += obj.offsetLeft;
    ctop += obj.offsetTop;
    obj = obj.offsetParent;
  }
  box.style.left = cleft + 'px';
  ctop += an.offsetHeight + 8;
  if (document.body.currentStyle &&
    document.body.currentStyle['marginTop']) {
    ctop += parseInt(
      document.body.currentStyle['marginTop']);
  }
  box.style.top = ctop + 'px';
}

function show_hide_box(an, width, height, borderStyle) {
  var href = an.href;
  var boxdiv = document.getElementById(href);

  if (boxdiv != null) {
    if (boxdiv.style.display=='none') {
      move_box(an, boxdiv);
      boxdiv.style.display='block';
    } else
      boxdiv.style.display='none';
    return false;
  }

  boxdiv = document.createElement('div');
  boxdiv.setAttribute('id', href);
  boxdiv.style.display = 'block';
  boxdiv.style.position = 'absolute';
  boxdiv.style.width = width + 'px';
  /*boxdiv.style.height = height + 'px';*/
  boxdiv.style.border = borderStyle;
  boxdiv.style.backgroundColor = '#E2DFF2';

  var contents = document.createElement('iframe');
  contents.scrolling = 'no';
  contents.frameBorder = '0';
  contents.style.width = width + 'px';
  contents.style.height = height + 'px';
  contents.src = href;
  contents.style.backgroundColor = '#E2DFF2';

  // start modifications:
  
  // create a close button
  close_button = document.createElement('a');
  close_button.setAttribute('href', '#');
  if (close_button.attachEvent) {
    // IE browser
    close_button.attachEvent('onclick',hide_box);
  } else {
    // standards-based browser
    close_button.setAttribute('onclick',"this.parentNode.style.display = 'none';event.returnValue=false;return false;");
  }
  link_text = 'Close';
  text_node = document.createTextNode(link_text);
  close_button.appendChild(text_node);

  // use the following syntax style to manipulate
  // the styling of the "Close" link
  close_button.style.position = 'relative';
  close_button.style.right = '4px';
  close_button.style.fontFamily = 'Arial, Helvetica, sans-serif';
  close_button.style.fontSize = '10px';

  // make the "Close" link appear on the right of box
  boxdiv.style.textAlign = 'right';
 
  
  // add the link to the div which houses the iframe
  // move this to after the follow line of code
  // to move the link to the bottom of the box
  boxdiv.appendChild(close_button);
  // end modifications
  
  boxdiv.appendChild(contents);
  document.body.appendChild(boxdiv);

  move_box(an, boxdiv);
  return false;
}

function hide_box() {
    event.srcElement.parentNode.style.display = "none";
}


