 // <![CDATA[ 
 
	soundManager.debugMode = false;
	soundManager._createSound = soundManager.createSound;
	
	soundManager._queue = new Array();
	soundManager.createSound = function (options) {
		if (arguments.length == 2) {
			options = {'id':arguments[0],'url':arguments[1]}
		}

		if (soundManager.loaded) {
			soundManager.createSound(options);
		} else {
			soundManager._queue[soundManager._queue.length] = options;
		}
	}
	soundManager.onload = function() {
		soundManager._queue.each(function (options) {
			soundManager._createSound(options);
		});
	}	
	
 	soundManager.createMovie('/includes/soundmanager2.swf');
	
	document.setCookie = function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}	
	document.getCookie = function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}	
	document.removeCookie = function(name) {
		document.setCookie(name,"",-1);
	}
	
	var Joke = new Class.create({
		initialize: function() {
			this.close = this.close.bind(this);
			this.display = this.display.bind(this);
			this.enable = this.enable.bind(this);
			this.disable = this.disable.bind(this);
			this.reset = this.reset.bind(this);

			this._onLoad = this._onLoad.bind(this);
			this._onClick = this._onClick.bindAsEventListener(this);	
			
			this.loaded = new Hash();
			
			soundManager.createSound({
			  id: 'laugh',
			  url: 'monster.mp3',
			  stream: true,
			  autoLoad: true,
			  autoPlay: false,
			  onload: this._onLoad.curry('sound')
			});
			
			img = new Element('img', {'src':'../images/joke.gif'}).observe('load', this._onLoad.curry('img'));
			img.style.height = '600px';
			
			height = Math.max($$('html').first().getHeight(), document.viewport.getHeight(), document.body.offsetHeight) + 'px';
			
			this.overlay = new Element('div', {'class': 'overlay', style: 'height:' + height +'; width:100%; top:0px; left:0px; position:absolute; display:none;'});
			this.overlay.observe('click', this.close);
			
			this.container = new Element('div', {style: 'top:' + (document.viewport.getScrollOffsets().top + 100) + 'px; left:0px; position:absolute; width:100%; display:none; text-align:center;'});
			this.container.observe('click', this.close);
			this.container.insert(img);
			
			this.redbutton = new Element('img', {src:'../images/redbutton.gif', style:'top:3px; right:3px; position:absolute; display:none; cursor:pointer;'});
			this.redbutton.observe('click', this.reset);
			
			$(document.body).insert(this.overlay);
			$(document.body).insert(this.container);
			$(document.body).insert(this.redbutton);
		},
		display: function() {
			height = Math.max($$('html').first().getHeight(), document.viewport.getHeight(), document.body.offsetHeight, (this.container.offsetTop + this.container.getHeight() + 100)) + 'px';
			
			this.overlay.setStyle({'height': height});
			this.container.setStyle({'top': (document.viewport.getScrollOffsets().top + 50) + 'px'});

			soundManager.play('laugh');

			this.overlay.show();
			this.container.show();
			
			document.setCookie('joke', true);
		},
		close: function() {
			this.overlay.hide();
			this.container.hide();
			this.disable();
			this.redbutton.show();
		},
		enable: function() {
			$$('a, button, input[type="button"], input[type="submit"]').invoke('observe', 'click', this._onClick);
		},
		disable: function() {
			$$('a, button, input[type="button"], input[type="submit"]').invoke('stopObserving', 'click', this._onClick);
		},
		reset: function() {
			this.redbutton.hide();
			this.enable();

			document.removeCookie('joke');
		},
		_onClick: function(event) {
			this.display();
			Event.stop(event);
		},
		_onLoad: function(loadeditem) {
			this.loaded.set(loadeditem, true);
			
			if (this.loaded.get('img') && this.loaded.get('sound')) {
				if (!document.getCookie('joke')) {
					this.enable();
				} else {
					this.redbutton.show();
				}
			}
		}
	});
	
	//Event.observe(document, 'dom:loaded', function () { new Joke(); });
 
 // ]]>