// The layer class constructor
function TheLayer(elementId, timeout) {          
  // Find the layer div element
  this.layerDiv = document.getElementById(elementId);        
  if( typeof this.layerDiv === 'undefined' ) {
    alert("Error: Cannot find element for layer!");
    return false;
  }                
  
  /**
   * Set the first child of the layer element for content
   * this.contentDiv = this.layerDiv.lastChild;
   */
  this.contentDiv = document.getElementById('layerAds_contentDiv');
  if( typeof this.contentDiv === 'undefined') {
    alert("Error: Child element for layer div cannot be found!");
    return false;
  }
    
  /**
   * Set the limit of views until the layer is shown
   *  Default will be 5, if none is set or value is invalid
   */
  if( typeof timeout === 'undefined' || isNaN(parseInt(timeout)) ) {
    this.timeout = 3000;
  } else {
    this.timeout = parseInt(timeout);
  }  
  
  // Define the class functions
  this.show = showLayer; 
  this.hide = hideLayer; 

  window.setTimeout("showLayer()", timeout); 
  return this;                  
};    

// Functions for the layer class
function showLayer() {
  if( typeof this.layerDiv !== 'undefined' ) {
    this.layerDiv.style.display = 'block';
  } else {
    var layerDiv = document.getElementById('layerAds_layerDiv');
    layerDiv.style.display = 'block';
  }    
  //document.body.style.overflow = 'hidden';      
}

function hideLayer() {      
  if( typeof this.layerDiv !== 'undefined' ) {      
    this.layerDiv.style.display = 'none';        
  } else {
    var layerDiv = document.getElementById('layerAds_layerDiv');
    layerDiv.style.display = 'none';
  }
  //document.body.style.overflow = 'auto';
}      

