window.addEvent('domready', function() {
	new BlakistonAlert();
});

var BlakistonAlert = new Class({
	alertEl: null,
	maskEl: null,
	
	initialize: function() {
		if ($('blakistonDummy')) {
			this.setupAlert();
		} else {
			var cookie = Cookie.read('showBlakistonAlert');
			if (cookie == null || cookie != 'hide') {
				this.setupAlert();
			}
		}
	},
	
	setupAlert: function() {
		this.alertEl = new Element('div', {
			'id': 'blakistonAlert',
			'class': (($('blakistonDummy')) ? 'bcBlakistonAlert' : 'gtBlakistonAlert')
		}).inject(document.body);
		
		new Element('a', {
			'id': 'close',
			'href': '#',
			'events': {
				'click': function(e) {
					e.preventDefault();
					Cookie.write('showBlakistonAlert', 'hide');
					
					if ($('blakistonDummy')) {
						window.location = 'http://www.gtlaw.com.au';
					} else {
						this.alertEl.destroy();
						this.maskEl.hide();
					}
				}.bind(this)
			}
		}).inject(this.alertEl);
		
		// Position to center
		var docSize = window.document.getSize();
		var elSize = this.alertEl.getSize();
		
		this.alertEl.setStyle('left', ((docSize.x / 2) - (elSize.x / 2)) + 'px');
		
		// Reposition on resize
		window.addEvent('resize', function(e) {
			var docSize = window.document.getSize();
			var elSize = this.alertEl.getSize();
			this.alertEl.setStyle('left', ((docSize.x / 2) - (elSize.x / 2)) + 'px');
		}.bind(this));
		
		this.maskEl = new Mask();
		this.maskEl.show();
	}
});
