
  var isIE = ( navigator.userAgent.indexOf( "MSIE" ) != -1 );
  var isFirefox = ( navigator.userAgent.indexOf( "Firefox" ) != -1 );
  var clearImg = "http://valencialighting.net/resources/images/clear.gif";

  function loadCssPopup()
  {
    popupElement = document.createElement( "DIV" );
    document.body.insertBefore( popupElement, document.body.lastChild );
    popupElement.id = "cssPopup";
    popupElement.style.top = "120px";
    popupElement.style.left = "50%";
    popupElement.style.marginLeft = "-300px";    
    popupElement.style.width = "600px";
    popupElement.style.height = "390px";        
    popupElement.style.position = "absolute"; 
    popupElement.style.zIndex = 10000001;       // some ads have a z-index of 999999
    popupElement.style.display = "none";
    popupElement.style.backgroundColor = "#000000";
    popupElement.style.color = "#ffffff";
    popupElement.style.border = "2px solid #ffffff";
  }
  
  
  function showCssPopup() 
  {
    if( isIE ) { hideDropdowns(); }
    
    loadBackgroundOverlay();
    popupDiv = document.getElementById( 'cssPopup' );    
    if( popupDiv != null ) { popupDiv.style.display = ''; }
  }
  

  function closeCssPopup() 
  { 
    if( isIE ) { showDropdowns(); }
    
    popupDiv = document.getElementById( 'cssPopup' );
    if( popupDiv != null ) { popupDiv.style.display = 'none'; }
    closeBackgroundOverlay();
  }




  // fadeout overlay
  // ========================================================================================================================
  var coverDiv;

  function loadBackgroundOverlay()
  {
    coverDiv = document.createElement( "IMG" );
    document.body.insertBefore( coverDiv, document.body.lastChild ); 
    coverDiv.id = "coverDiv";
    coverDiv.src = clearImg;
    coverDiv.alt = "";
    coverDiv.style.height = getWindowHeight() + 'px';
    coverDiv.style.width = "100%";
    coverDiv.style.cursor = "not-allowed";
    coverDiv.style.left = "0px";
    coverDiv.style.top = "0px";
    coverDiv.style.position = "absolute"; 
    coverDiv.style.display = "block";
    coverDiv.style.visibility = "visible";
    coverDiv.style.backgroundColor = "#000000";
    coverDiv.style.zIndex = 10000000;
    coverDiv.style.opacity = 0.9;       // standard
    coverDiv.style.MozOpacity = 0.9;    // Mozilla
    if( coverDiv.style.setAttribute ) coverDiv.style.setAttribute( "filter", "alpha( opacity = 90 );" ); // IE 
  }


  function closeBackgroundOverlay()
  {
    coverDiv = document.getElementById( "coverDiv" );
    if( coverDiv ) document.body.removeChild( coverDiv );
  }


  function getWindowHeight()
  {
    var pageHeight;

    if( window.innerHeight && window.scrollMaxY ) // Firefox //Fix for IE7 (at then end)
      pageHeight = window.innerHeight + window.scrollMaxY;
    else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
      pageHeight = document.body.scrollHeight;
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
      pageHeight = document.body.offsetHeight + document.body.offsetTop; 

    return pageHeight;
  }




  // IE fix - dropdowns controls in IE aren't covered by the overlay, so hide them when showing the popup
  // =======================================================================================================
  var dropdownStyles = new Array();
  var dropdownStylesIndex = 0; 
  
  function hideDropdowns() 
  { 
    try
    { 
      dropdownStylesIndex = 0;
    
      for( i = 0; i < document.forms.length; i++ )
      {
        for( k = 0; k < document.forms[ i ].elements.length; k++ )
        {
          if( document.forms[ i ].elements[ k ].type == "select-one" )
          {
            dropdownStyles[ dropdownStylesIndex++ ] = document.forms[ i ].elements[ k ].style.visibility;   // back up the current value in a global array
            document.forms[ i ].elements[ k ].style.visibility = "hidden";
          }
        }
      }
    }
    catch( e ) {}
  }
  

  function showDropdowns() 
  { 
    try
    {
      dropdownStylesIndex = 0;
    
      for( i = 0; i < document.forms.length; i++ )
      {
        for( k = 0; k < document.forms[ i ].elements.length; k++ )
        {
          if( document.forms[ i ].elements[ k ].type == "select-one" )
          {
            document.forms[ i ].elements[ k ].style.visibility = dropdownStyles[ dropdownStylesIndex++ ];   // restore styles
          }
        }
      }
    }
    catch( e ) {}
  }




  // utility
  // ========================================================================================================================
  
  //  Unobtrusively add event handlers to objects without overwriting any existing events that are attached.
  function addEvent( obj, eventType, fn )
  {
    if( obj.addEventListener ) 
    { 
      obj.addEventListener( eventType, fn, false );
      return true; 
    }
    else if( obj.attachEvent )
    { 
      var r = obj.attachEvent( "on" + eventType, fn );
      return r; 
    }
    else { return false; } 
  }
  
  
  
  // ========================================================================================================================
  
  addEvent( window, 'load', loadCssPopup );
  
  
  function showAboutUs()
  {
    popupDiv = document.getElementById( 'cssPopup' );    
    if( popupDiv != null ) 
    { 
      var text = "<div style=\"font: 13px arial; line-height: 18px; padding: 10px;\">";
      text += "<div style=\"color: #FFE763; margin: 0 0 8px 0; font-size: 20px; font-family: Georgia, \"Times New Roman\", Times, serif !important;\">About Us</div>";
      text += "<img src=\"/resources/images/about-us_lamp.jpg\" width=\"100\" height=\"284\" align=\"right\">";
      text += "Valencia Lighting is a family owned and operated showroom with experienced, knowledgeable, and professional staff. Our goal is not to just sell you lights, but to make sure you buy the perfect fixture for your application. We strive to make our customers feel comfortable and confident in every purchase from a simple table lamp to a whole house full of lighting. We pride ourselves with great customer service and going above and beyond what's expected because we understand the importance in giving individual attention to every customer.  The difference between the bigger box stores and us is that we care. Our lower overhead and efficient staff means lower prices!";
      text += "<p>We believe in building strong relationships with builders, designers, as well as our customers. We have a large facility with 6500 square feet of showroom and warehouse for stock. You will find one of Southern California's biggest outdoor lighting selections as well as a wide variety of ceiling fans, beautiful bathroom vanity lighting, amazing chandeliers, and much more. Unfortunately, we do not sell replacement shades, replacement fluorescent bulbs, or recessed cans.</p>";
      text += "<p>We are your \"One-Stop Decorative Lighting and Fan Superstore.\"</p>";
      text += "<p align=\"right\">[<a href=\"javascript: closeCssPopup();\">Close</a>]</p>";
      text += "</div>";
      
      popupDiv.innerHTML = text; 
      
      showCssPopup();
      window.scrollTo( 0, 0 );
    }
  }