// Thanks for doing your part to liber(IE)t the world from IE6!
// Original copy written by Jonathan Howard (jon@StaringIsPolite.com)
// Modified by G. Birch on 3/21/09 to change wording and change browser options
// GNU LGPL License v3
// SevenUp is released into the wild under a GNU LGPL v3
//
// Browser sniffing technique lovingly adapted from http://www.thefutureoftheweb.com/
// Simple CSS Lightbox technique adapted equally lovingly from http://www.emanueleferonato.com/
// Go read their blogs :)

// Constructor technique advocated by Doug Crockford (of LSlint, JSON) in his recent Google tech talk.
var sevenUp = function () {
  // Define private vars here.
	var IELink = "http://www.microsoft.com/windows/downloads/ie/getitnow.mspx";
	var FFLink = "http://www.getfirefox.com";
	var ChromeLink = "http://www.google.com/chrome";
	var needUpgrade = /(MSIE 6|MSIE 5.(\d+))/i.test(navigator.userAgent); // is IE6??
	var overlayColor  = "#000000";  // Change these to fit your color scheme.
	var lightboxColor = "#ffffff";  // " "
	var borderColor   = "#6699ff";  // " "
  // Hate to define CSS this way, but trying to keep to one file.
  // I'll keep it as pretty as possible.
  var overlayCSS =
    "display: block; position: absolute; top: 0%; left: 0%;" +
    "width: 100%; height: 100%; background-color: " + overlayColor + "; " +
    "z-index:1001; -moz-opacity: 0.7; opacity:.70; filter: alpha(opacity=70);";
  var lightboxCSS = 
    "display: block; position: absolute; top: 25%; left: 25%; width: 50%; " +
    "height: 40%; padding: 16px; border: 8px solid " + borderColor + "; " +
    "background-color:" + lightboxColor + "; " +
    "z-index:1002; overflow: auto; -moz-opacity: 0.9; opacity:.90; filter: alpha(opacity=90);";
  var lightboxContents =
    "<div style='width: 100%;'>" +
      "<h2>Whoa there!</h2><p>You appear to be using an old web browser that is out of date and no longer supported by Microsoft.</p>" +
      "<p>" +
        "You can easily upgrade to the latest version of Internet Explorer by using Windows Update or by clicking " +
        "<a style='color: #0000EE' href='" + IELink + "'>here</a>.  Alternatively, you could switch to using " +
        "<a style='color: #0000EE' href='" + FFLink + "'>Firefox</a> or even Google's new browser, " +
		"<a style='color: #0000EE' href='" + ChromeLink + "'>Chrome</a>." +
      "</p>" +
      "<h3 style='margin-top: 40px'>Top 3 reasons to upgrade</h3>" +
      "<ul><li>Browse the Web <b>faster</b></li>" +
      "<li>Browse the Web more <b>safely</b></li>" +
      "<li>Many websites look <b>better</b>, including this one</li>" +
      "</ul>" +
    "<table width='100%'><tr><td style='text-align: left;'>" +
      "<a href='#' onclick='sevenUp.close();'" +
          "style='color: #0000EE'>" +
        "OK already" +
      "</a>" +
    "</td>" +
	"<td style='text-align: right;'>" +
      "<a href='#' onclick='sevenUp.quitBuggingMe();'" +
          "style='color: #0000EE'>" +
        "Please stop bugging me about my antiquated browser" +
      "</a>" +
    "</td></tr></table>" +
    "</div>";
  function isCookieSet() {
    if (document.cookie.length > 0) {
      var i = document.cookie.indexOf("sevenup=");
      return (i != -1);
    }
    return false;
  }
  
  return {  // Return object literal and public methods here.
  	test: function(allowSkip) {
  	  if (needUpgrade && !isCookieSet()) {
  	    // Write layer into the document.
  	    var layerHTML =
  	      "<div id='sevenUpOverlay' style='" + overlayCSS + "'>" +
  	        "<div style='" + lightboxCSS + "'>" +
              lightboxContents +
            "</div>" +
  		    "</div>";
        var layer = document.createElement('div');
        layer.innerHTML = layerHTML;
  	    document.body.appendChild(layer);
  	  }  
  	},
    setLightboxContents: function(newContents) {
      lightboxContents = newContents;
    },
    quitBuggingMe: function() {
      var exp = new Date();
      exp.setTime(exp.getTime()+(7*24*3600000));
      document.cookie = "sevenup=dontbugme; expires="+exp.toUTCString();
      this.close();
    },
    close: function() {
      var overlay = document.getElementById('sevenUpOverlay');
      if (overlay !== undefined) {
        overlay.style.display = 'none';
      }
    }
  };
}();


