﻿/**
* CompatibilityBar
*/

var CompatibilityBar = new Class({

    Implements: [Options, Events],
     
 options: {
 className: 'compatibilitybar',
 message: 'We\'re sorry, but this web site contains enhanced features not supported by the browser version you are currently using. Please update to a recent Version. <a href="http://browser-update.org/en/update.html" target="_blank">Learn how to update your browser</a>',
 browsers: [
 {alias: 'IE6', name: 'trident', version: 4}
 ]
 },

 initialize: function (options) {
 var showBar = this.options.browsers.some(function (browser) {
 return (Browser.Engine.name == browser.name && Browser.Engine.version <= browser.version);
 }, this);
 if (!showBar) return false;
 if (Cookie.read('compatibilitybar') != 'closed') {
 this.setOptions(options);
 this.build();
 this.show();
 }
 },

 build: function () {
 this.container = new Element('div', {
 'class': this.options.className
 }).set('tween', {transition: 'sine:out'});

 this.message = new Element('div', {
 'class': this.options.className + '-message',
 'html': this.options.message
 }).inject(this.container);

 this.closeButton = new Element('a', {
 'class': this.options.className + '-close',
 'events': {
 'click': this.close.bind(this)
 }
 }).inject(this.container);

 this.container.inject(document.body, 'top');
 },

 show: function () {
 this.container.tween('height', this.message.getSize().y);
 },

 hide: function () {
 this.container.tween('height', 0);
 },

 close: function () {
 Cookie.write('compatibilitybar', 'closed', {path: '/'});
 this.hide();
 }

});
