var underconstruction = new Class({
	
	bg : null,
	imageWidth : 1920,
	imageHeight : 1132,
	currentWindowWidth : null,
	currentWindowHeight : null,
	currentProject : null,
	
	/**
	 * Constructor
	 */
	initialize : function() {
		// set tween functions for background element
		var temp = this;
		this.bg = new Fx.Tween('background',{duration : 1500});
		
		this.fixBackground();
		this.preloadBgImages();
		
		this.hideContent();
		this.activateMenu();
		this.activateTopMenu();
		this.activateLogos();
		
		
	},
	
	
	/**
	 * 
	 */
	preloadBgImages : function() {
		var images = new Array(
			'gfx/bg2.jpg',
			'gfx/bg.jpg',
			'gfx/UClogo.png',
			'gfx/STlogo.png',
			'gfx/topbuttons/en.about.png',
			'gfx/topbuttons/en.forpress.png',
			'gfx/topbuttons/en.png',
			'gfx/topbuttons/no.om.png',
			'gfx/topbuttons/no.forpresse.png',
			'gfx/topbuttons/no.png',
			'gfx/buttons/drops.png',
			'gfx/buttons/dusk.png',
			'gfx/buttons/72.png',
			'gfx/buttons/aperto.png',
			'gfx/buttons/backup1.png',
			'gfx/buttons/beehive.png',
			'gfx/buttons/falsetto.png',
			'gfx/buttons/hiatus.png',
			'gfx/buttons/plasticdandy.png',
			'gfx/buttons/samo.png',
			'gfx/buttons/softscape.png',
			'gfx/buttons/stagholm.png',
			'gfx/buttons/stavesidechair.png',
			'gfx/buttons/swell.png',
			'gfx/buttons/unitone.png',
			'gfx/buttons/zipp.png');
		new Asset.images(images,{
			onComplete : function() {
			}
		});
	},
	
	
	/**
	 * Hide content
	 */
	hideContent : function() {
		$$('.content').each(function(item,index) {
			item.setStyle('display','none');
			item.setStyle('visibility','visible');
			item.set('tween',{ duration : 500 });
		});
	},
	
	
	/**
	 * Activate top menu
	 */
	activateTopMenu : function() {
		var temp = this;
		$('topmenu').getElements('a').each(function(item,index) {
			if(item.get('rel') != null) {
				item.addEvent('click',function(e) {
					e.stop();
					e.preventDefault();
					
					if(temp.currentProject == null) {
						temp.dimBackground();
					}
					
					temp.hideProject(temp.currentProject);
					$('topmenu').getElements('a').each(function(oitem,oindex) {
						if(oitem.get('rel') == temp.currentProject) {
							oitem.removeClass('marked');
						}
					});
					$('menu').getElements('a').each(function(oitem,oindex) {
						oitem.removeClass('marked');
					});
					temp.currentProject = item.get('rel');
					temp.showProject(item.get('rel'));
					item.addClass('marked');
				});
			}
		});
	},
	
	
	/**
	 * Add menu events
	 */
	activateMenu : function() {
		var temp = this;
		$('menu').getElements('a').each(function(item,index) {
			item.addEvent('click',function(e) {
				e.preventDefault();
				e.stop();
				
				if(temp.currentProject == null) {
					temp.dimBackground();
				}
				
				temp.hideProject(temp.currentProject);
				$('menu').getElements('a').each(function(oitem,oindex) {
					if(oitem.get('rel') == temp.currentProject) {
						oitem.removeClass('marked');
					}
				});
				$('topmenu').getElements('a').each(function(oitem,oindex) {
					oitem.removeClass('marked');
				});
				temp.currentProject = item.get('rel');
				temp.showProject(item.get('rel'));
				item.addClass('marked');
			});
		});
	},
	
	/**
	 * Make the logos "exit" buttons
	 */
	activateLogos : function() {
		var temp = this;
		$$('.logo').each(function(item,index) {
			item.addEvent('click',function(e) {
				e.stop();
				e.preventDefault();
				
				temp.hideProject(temp.currentProject);
				$('menu').getElements('a').each(function(oitem,oindex) {
					if(oitem.get('rel') == temp.currentProject) {
						oitem.removeClass('marked');
					}
				});
				$('topmenu').getElements('a').each(function(oitem,oindex) {
					oitem.removeClass('marked');
				});
				temp.currentProject = null;
				temp.lightenBackground();
			});
		});
		$('dimbackground').addEvent('click',function(e) {
			e.stop();
			e.preventDefault();
			
			temp.hideProject(temp.currentProject);
			$('menu').getElements('a').each(function(oitem,oindex) {
				if(oitem.get('rel') == temp.currentProject) {
					oitem.removeClass('marked');
				}
			});
			$('topmenu').getElements('a').each(function(oitem,oindex) {
				oitem.removeClass('marked');
			});
			temp.currentProject = null;
			temp.lightenBackground();
		});
	},
	
	
	/**
	 * Hide a project.
	 */
	hideProject : function(project) {
		// hide the active project
		var p = $(project);
		if(p != null) {
			p.tween('opacity',0);
			(function() { p.setStyle('display','none') }).delay(500);
		}
	},
	
	
	/**
	 * Show project
	 */
	showProject : function(project) {
		
		(function() {
			$(project).setStyle('opacity',0);
			$(project).setStyle('display','block');
			$(project).tween('opacity',1);
		}).delay(500);
		
	},
	
	/**
	 * Fade down the background
	 */
	dimBackground : function() {
		var temp = this;
		(function() {
			temp.bg.start('opacity',0);
		}).delay(500);
		
	},
	
	/**
	 * Fade up the background
	 */
	lightenBackground : function() {
		this.bg.start('opacity',1);
	},
	
	
	/**
	 * Fix scaling background
	 */
	fixBackground : function() {
		var temp = this;
		
		var f = function() {
			if(this.currentWindowWidth != document.getElement('body').getSize().x
			|| this.currentWindowHeight != document.getElement('body').getSize().y) {
				var bodyHeight = document.getElement('body').getSize().y;
				var bodyWidth = document.getElement('body').getSize().x;
				var actualHeight = (this.imageHeight * bodyWidth) / this.imageWidth;
				var neededWidth = (this.imageWidth * bodyHeight) / this.imageHeight;
				// center the background images
				$$('.bgimage').each(function(item,index) {
					if(actualHeight <= bodyHeight) {
						item.setStyle('height','100%');
						item.setStyle('width',(neededWidth + 'px'));
		// 				item.removeStyle('width');
						item.setStyle('left',(((neededWidth - bodyWidth) / 2) * -1) + 'px');
					}
					else {
						item.setStyle('height',actualHeight + 'px');
						item.setStyle('width','100%');
						item.setStyle('left',0);
					}
				});
				this.currentWindowWidth = document.getElement('body').getSize().x;
				this.currentWindowHeight = document.getElement('body').getSize().y;
			}
		};
		f.periodical(1000,this);
	}
});
