function Application()
{
	this.rootPath = 'http://www.dutchmadmen.nl/';
	this.mapObject = false;
	this.eventsObject = false;
	this.toplistsObject = false;
	this.controller = false;
	this.action = false;
	this.pageId = false;
	this.viewportWidth = $(window).width();
	this.viewportHeight = $(window).height();
	this.model2Selected = false;

	this.initialize = function()
	{
		// Preloading....
		this.preLoading();
	}
	
	this.run = function(controller, action, pageId, hasMap)
	{
		this.controller = controller;
		this.action = action;
		this.pageId = pageId;

		// Events
		this.eventsObject = new Events();

		// Google maps
		if(hasMap) { this.mapObject = new Map(); this.mapObject.initialize(action); }

		// i.e. png fix
		if(jQuery.browser.msie && jQuery.browser.version < 7) { DD_belatedPNG.fix('.png_bg'); }

		switch(controller)
		{
			case 'Content' :
				if(action == 'home')
				{
					// Load model 1 small
					this.mapObject.markerManagerObject.loadModel1Small();
				}
				if(action == 'connected')
				{
					// Load model 1
					this.mapObject.markerManagerObject.loadModel1();

					if(!this.readCookie ('model1'))
					{
						this.createCookie('model1', 1);
						$('#help').get(0).style.display = 'block';
					}
					
				}
				if(action == 'influence')
				{				
					if(!this.readCookie ('model2'))
					{
						this.createCookie('model2', 1);
						$('#help').get(0).style.display = 'block';
					}
				}
				if(action == 'toplists')
				{				
					this.toplistsObject = new Toplists();
				}
				break;
		}

		if(hasMap) { 
			GEvent.addListener(applicationObject.mapObject.map, "mousemove", function(latlng)
			{
				// debug
				var pixelLocation = applicationObject.mapObject.map.fromLatLngToDivPixel(latlng);
				//GLog.write('Mousemove'+latlng);
			});
		}
	}

	this.destroy = function()
	{
		// clean up
		//GUnload();
	}

	this.require = function(src)
	{
		// add the required script
		var scriptElem = document.createElement('script');
		scriptElem.setAttribute('src',src);
		scriptElem.setAttribute('type', 'text/javascript');
		document.getElementsByTagName('head')[0].appendChild(scriptElem);
	}

	this.getQueryVariable = function(variable)
	{
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i=0;i<vars.length;i++)
		{
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
		return false;
	}
	
	this.preLoading = function()
	{
		try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {}
		if (!$('#preload')) return
	    
		var preload = $('#preload');
		var preloadImages = new Array();
		var sHtml = '';

		for(i=0; i<preloadImages.length; i++)
		{
			sHtml += '<img src="images/' + preloadImages[i] + '" />'
		}
		
		preload.html(sHtml);
		preload.hide();
	}
	
	this.createCookie = 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=/";
	}

	this.readCookie = 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;
	}
}