var Halssmycket = {
	screenWidth: 0,
	isStarted: false,
	domReady: function() {
		//$('content').setStyle('opacity', '0');
		$('rightside').setStyle('width', (Halssmycket.screenWidth - 304) + 'px');
		
		$('door').setStyles({
			'background-image': 'url(/images/background-' + Halssmycket.screenWidth + '.jpg)',
			'width': (Halssmycket.screenWidth + 'px')
		});
		
		$('come-in').addEvent('click', function(e) {
			new Event(e).stop();
			
			Halssmycket.isStarted = true;
			
			this.getElement('img').set('morph', {duration: 3000});
			this.getElement('img').morph({
				'height': '1500px'
			});
			
			$('leftside').set('morph', {duration: 3000});
			$('leftside').morph({
				'left': '-355px',
				'border-right-color': '#333',
				'border-right-style': 'solid',
				'border-right-width': '50px'
			});
			$('rightside').set('morph', {
				duration: 3000, onComplete: function() {
					Halssmycket.showContent();
					$('leftside').dispose();
					$('rightside').dispose();
					$(document.body).setStyle('overflow-y', 'auto');
				}
			});
			$('rightside').morph({
				'left': (Halssmycket.screenWidth + 200) + 'px',
				'border-left-color': '#121212',
				'border-left-style': 'solid',
				'border-left-width': '175px'
			});
		});
		
		(function() {
			if (!Halssmycket.isStarted)
				$('come-in').fireEvent('click', $('come-in'), 10);
		}).delay(4000);
	},
	showContent: function() {
		/*$('content').morph({
			'opacity': '1'
		});*/
	},
	readScreen: function() {
		var screenWidths = [800, 1024, 1152, 1280, 1440, 1680, 1920];
		var screenWidth  = window.getSize().x;
		
		Halssmycket.screenWidth = 800;
		for (var i = screenWidths.length - 1; i >= 0; i--) {
			if (screenWidth <= screenWidths[i])
				Halssmycket.screenWidth = screenWidths[i];
		}
	}
};

window.addEvent('domready', Halssmycket.readScreen);
window.addEvent('domready', Halssmycket.domReady);