// $Id$
 
/**
 * Killswitch incase JS doesn't have the needed functionality.
 */
if (isJsEnabled()) {
  addLoadEvent(plagOverlay);
  window.onresize = function() {
    plagOverlay();
  }  
  window.onscroll = function() {
    plagScroll();
  }  
}
else {
  alert('Javascript support needed by this page is not available.  We recommend using Firefox.');
}

function plagOverlay() {
  var plag = $('plag');
  if (!plag) {
    document.body.insertBefore(plagCreateElement(), document.body.firstChild);    
    // add style definitions
    var plag = $('plag');    
    plag.style.position = 'absolute';    
  }
  clientHeight = document.documentElement.clientHeight;
  clientWidth = document.documentElement.clientWidth;
  
  plag.style.left = clientWidth - 90 + 'px';
  plag.style.top = clientHeight - 40 + 'px';  
}

function plagScroll() {
  var plag = $('plag'); 
 
  if (window.event) {
    var offset = document.documentElement.scrollTop;  
  }
  else {
    var offset = window.scrollY;
  }
  var basePos = (document.documentElement.clientHeight - 40) + offset + 'px';

  plag.style.top = basePos;
}

/**
 * Create a 'div' element containing a linked image to "http://www.plag.nl".
 */
function plagCreateElement() {
  var imgSrc = '/themes/dorpsstraat/img/plag.gif';
  var URL = 'http://www.plag.nl/';    
                        
  // create the image element
  var overlayImg = document.createElement('img');
  overlayImg.src = imgSrc;
            
  // wrap the image element in an 'a' element
  var overlayLink = document.createElement('a');
  overlayLink.target = '_blank';
  overlayLink.href = URL;
  overlayLink.appendChild(overlayImg);

  // create the div element
  var divOverlay = document.createElement('div');
  divOverlay.id = 'plag';
  divOverlay.appendChild(overlayLink);

  return divOverlay;  
}

