var latestRelease = '1.6.7';
var latestPreRelease = '2.0b2';
var latestPreReleaseText = '2.0 Beta 2';
var latestPreReleaseType = 'beta';
var oldRelease = new Array('1.6.6','1.6.5','1.6.4','1.6.3','1.6.2','1.6.1', '1.6','1.5.5','1.5.4','1.5.3','1.5.2','1.5.1','1.5');
var oldPreRelease = new Array('2.0b1','2.0a1','1.6b4','1.6b3','1.6b2','1.6b1','1.6a1');
var one06Release = '1.0.6';
var one0xReleases = new Array('1.0.5','1.0.4','1.0.3','1.0.2','1.0.1','1.0');
var recentBuildAge = 14;

var messageLatestRelease = '<h2>You’re using Camino!</h2><p>Thanks for using Camino ' + latestRelease + '. You’re using the latest version of Camino, which means you have the latest security updates.</p><p>For an overview of features in Camino ' + latestRelease + ', check out our <a href="/features/">Features section</a>. To keep up-to-date with the latest Camino news and information, subscribe to our <a href="/blog/">blog</a>. If you’re having problems or want to learn how to use specific features, try our <a href="/help/">Help section</a>.</p><p>Thanks again for using Camino. We hope you like it as much as we do!</p>';
var messageLatestPreRelease = '<h2>Thanks for testing!</h2>Thank you for testing Camino ' + latestPreReleaseText +'. Please <a href="https://bugzilla.mozilla.org/enter_bug.cgi?format=guided&amp;product=Camino">report any bugs</a> you find while you browse. If you find the ' + latestPreReleaseType + ' version unstable, you may be happier using our latest stable release, <a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>).</p>';
var messageOldRelease = '<h2>Time to Update!</h2><p>You appear to be running Camino ' + navigator.vendorSub + '. This release is old and has many known security vulnerabilities and stability issues. We strongly recommend you upgrade to <a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>).</p>';
// messageOldPreRelease to be used when after a new version release
// var messageOldPreRelease = '<h2>Time to Update!</h2><p>You appear to be running Camino ' + navigator.vendorSub + '. Camino ' + latestRelease + ' has been released. Please <a href="/download/releases/' + latestRelease + '/">upgrade to Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>) today.</p>';
// messageOldPreRelease to be used when during the preview phase
var messageOldPreRelease = '<h2>Time to Update!</h2><p>You appear to be running Camino ' + navigator.vendorSub + '. Camino ' + latestPreReleaseText + ' is the newest version available for testing. Please <a href="http://preview.caminobrowser.org/">upgrade</a> to Camino ' + latestPreReleaseText + ' today.</p>';
var messageOne06Release = '<h2>Try Camino ' + latestRelease + '!</h2><p>You appear to be running Camino 1.0.6. Camino ' + latestRelease + ' is now available. It has numerous new features and bug fixes. If you’re running Mac OS X 10.3.9 or later, we recommend you upgrade to <a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>). Check out our <a href="/features/">Features page</a> for just some of the reasons why you should upgrade. If you’re still running Mac OS X 10.2, please note that Camino 1.0.6 is the last release for your platform and is no longer supported.</p>';
var messageOne0xReleases = '<h2>Time to Update!</h2><p>You appear to be running Camino ' + navigator.vendorSub + '. This release is old and has many known security vulnerabilities as well as stability issues. If you’re running Mac OS X 10.3.9 or later, we recommend you upgrade to <a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>). If you’re still running Mac OS X 10.2, please <a href="/download/releases/1.0.6/">download Camino 1.0.6</a>, the latest stable version of Camino for your platform.</p>';
var messageFirefox = '<h2>Migrating from Firefox?</h2><img src="/img/firefox.png" height="64" alt="" class="fr" /><p>Thinking about switching to Camino from Firefox? Switching browsers can be a disruptive, sometimes even painful experience. We’ve <a href="/documentation/firefox/">created a page</a> which points out some of the common differences between Camino and Firefox and helps make Camino feel right at home on your desktop and in your Dock.</p><p>On that page you can learn how to migrate your Firefox data, how to extend Camino in similar ways, and differences in keyboard shortcuts.</p>';
var messageDefault = '<h2>Camino ' + latestRelease + ' Released!</h2><p><a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> is now available. This version contains brand new features as well as important stability and security fixes. All users of Mac OS X 10.3.9 or later are recommended to upgrade. Camino ' + latestRelease + ' is also available in a <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>. For more information, checkout our <a href="/blog/">blog</a>, <a href="/features/">features page</a>, or <a href="/releases/' + latestRelease + '/">release notes</a>.</p>';
var messageSafari = '<h2>Migrating from Safari?</h2><img src="/img/safari.jpg" alt="" class="fr" /><p>Thinking about switching to Camino from Safari? Switching browsers can be a disruptive, sometimes even painful experience. We’ve <a href="/documentation/safari/">created a page</a> which points out some of the common differences between Camino and Safari and helps make Camino feel right at home on your desktop and in your Dock.</p><p>On that page you can learn how to migrate your Safari data, how to extend Camino in similar ways, and differences in keyboard shortcuts.</p>';
var messageMacIE = '<h2>Looking for a new browser?</h2><p>You appear to be running Internet Explorer for Mac, a browser that hasn’t been updated since 2001. Download <a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>) and discover the advantages of using a modern browser designed especially for your Mac.</p>';

var messageNewNightly = '<h2>Thanks for testing!</h2><p>You appear to be running a recent nightly build of Camino. Testing recent nightlies of Camino is a great way to <a href="/contribute/">contribute</a> to the project. Please <a href="https://bugzilla.mozilla.org/enter_bug.cgi?format=guided&amp;product=Camino">report any bugs</a> you find while you browse. Isn’t life on the bleeding edge great?!</p>';
var messageOldNightly = '<h2>Update Your Nightly!</h2><p>You appear to be running a nightly build of Camino that is several weeks old. Please <a href="/download/releases/nightly/">download the latest nightly</a> before reporting bugs, etc. If you find the nightly version unstable, you may be happier using our latest stable release, <a href="/download/releases/' + latestRelease + '/">Camino ' + latestRelease + '</a> (or the <a href="/download/releases/' + latestRelease + '-MultiLang/">multilingual version</a>).</p>';

function displayProperMessage() {
if(BrowserDetect.browser == "Camino") {
  var now = Date.now();

  // 'now' is parsed in milliseconds since the epoch so we must convert our build ID to the same.
  var buildIDDate = new Date(navigator.buildID.substr(0,4), navigator.buildID.substr(4,2) - 1, navigator.buildID.substr(6,2));
  var epochBuildID = Date.parse(buildIDDate);
  var buildAge = (now - epochBuildID) / 86400000;

  if(navigator.vendorSub == latestPreRelease) {
    document.write(messageLatestPreRelease)
  }
  // This needs to be before the check for the old releases.
  else if (navigator.vendorSub == latestRelease) {
    document.write(messageLatestRelease)
  }
  else if (navigator.vendorSub == one06Release) {
    document.write(messageOne06Release)
  }
  else if (oldPreRelease.indexOf(navigator.vendorSub) != -1) {
    document.write(messageOldPreRelease)
  }
  else if (oldRelease.indexOf(navigator.vendorSub) != -1) {
    document.write(messageOldRelease)
  }
  else if (one0xReleases.indexOf(navigator.vendorSub) != -1) {
    document.write(messageOne0xReleases)
  }
  else if (buildAge < recentBuildAge) {
    document.write(messageNewNightly)
  }
  else if (buildAge > recentBuildAge) {
    document.write(messageOldNightly)
  }
  else {
    document.write(messageDefault)
  }
}
else if(BrowserDetect.browser == "Firefox") {
  document.write(messageFirefox)
}
else if(BrowserDetect.browser == "Safari") {
  document.write(messageSafari)
}
else if(BrowserDetect.browser == "Explorer" && BrowserDetect.OS == "Mac") {
  document.write(messageMacIE)
}
else {
  document.write(messageDefault)
}

}

