function MyThoughts(asGlobals)
{
	self = this;
	this.consts = asGlobals.consts;
	this.consts.hash_sep = '-';
	this.consts.default_page = 'home';
	this.consts.title = 'My Thoughts';
	
	this.init = function()
	{
		//Variables & constants from php
		self.vars('tmp', 'object');
		self.vars('page', 'string');
		self.vars('template', 'boolean');
		self.updateVars(asGlobals.vars);
		
		//page elem
		self.elem = {};
		self.elem.container = $('#container');
		
		//on window resize
		$(window).resize(self.onResize).resize();
		
		//Setup menu
		//self.initMenu();
		
		//Hash management
		self.resetTmpFunctions();
		$(window)
			.bind('hashchange', self.onHashChange)
			.trigger('hashchange');
	};
	
	this.updateVars = function(asVars)
	{
		$.each(asVars, function(sKey, oValue){self.vars(sKey, oValue)});
	};
	
	/* Scrollbar */
	
	/*this.scrollbar = function(sPos)
	{
		var $Cv = $('#main');
		if(!self.vars('mobile'))
		{
			if(typeof self.vars('scrollbar') === 'undefined')
			{
				$Cv.tinyscrollbar({axis:'y', thumbSizeMin:'20', thumbSize:'20'});
				self.vars('scrollbar', $Cv.data("plugin_tinyscrollbar"));
			}
			else self.vars('scrollbar').update(sPos);
		}
		else $Cv.unbind("tinyscrollbar");
	}*/
	
	/* Menu */
	
	this.initMenu = function()
	{
		
	};
	
	/* Events */
	
	this.onResize = function()
	{
		self.vars('mobile', $('body').css('min-width')=='120px');
		//self.scrollbar();
	};
	
	this.onHashChange = function()
	{
		var asHash = self.getHash();
		var sDefaultPage = self.vars('log_in')?'write':'logon';
		if(asHash.hash !='' && asHash.page != '') self.switchPage(asHash); //page switching
		else if(self.vars('page')=='') self.setHash(sDefaultPage); //first page
	};
	
	this.resetTmpFunctions = function()
	{
		self.pageInit = function(asHash){console.log('no init for the page: '+asHash.page)};
		self.onSamePageMove = function(asHash){return false};
		self.onQuitPage = function(){return true};
		self.onFeedback = function(sType, sMsg){feedback(sType, sMsg, self.elem.container);};
	};

	/* Hash Handling */
	
	this.getHash = function()
	{
		var sHash = self.hash();
		var asHash = sHash.split(self.consts.hash_sep);
		var sPage = asHash.shift() || '';
		return {hash:sHash, page:sPage, items:asHash};
	};
	
	this.setHash = function(sPage, asItems, bReboot)
	{
		bReboot = bReboot || false;
		sPage = sPage || '';
		asItems = asItems || [];
		if(typeof asItems == 'string') asItems = [asItems];
		if(sPage != '')
		{
			var sItems = (asItems.length > 0)?self.consts.hash_sep+asItems.join(self.consts.hash_sep):'';
			self.hash(sPage+sItems, bReboot);
		}
	};
	
	this.hash = function(hash, bReboot)
	{
		bReboot = bReboot || false;
		if(!hash) return window.location.hash.slice(1);
		else window.location.hash = '#'+hash;
		
		if(bReboot) location.reload();
	};
	
	this.getVars = function(fOnSuccess)
	{
		fOnSuccess = fOnSuccess || function(){};
		getInfo
		(
			'vars', 
			function(asData)
			{
				self.updateVars(asData.vars);
				fOnSuccess();
			},
			{}
		);
	};
	
	/* Page Switching */
	
	this.getActionLink = function(sAction, oVars)
	{
		if(!oVars) oVars = {};
		sVars = '';
		for(i in oVars)
		{
			sVars += '&'+i+'='+oVars[i];
		}
		return self.consts.process_page+'?a='+sAction+sVars;
	};
	
	this.switchPage = function(asHash)
	{
		var sPageName = asHash.page;
		var bSamePage = self.vars('page')==sPageName;
		if(self.onQuitPage(bSamePage) && !bSamePage || self.onSamePageMove(asHash))
		{
			//Preload template if not already loaded
			
			
			//Delete tmp variables
			self.vars('tmp', {});
			
			//disable tmp functions
			self.resetTmpFunctions();
			
			//Officially a new page
			var bFirstPage = self.vars('page')=='';
			self.vars('page', sPageName);
			
			//Update Page Title
			var sDetail = asHash.items[0] || '';
			document.title = self.consts.title+' - '+sPageName+' '+sDetail;
			
			//Replacing DOM
			var $Dom = $(self.consts.pages[sPageName]);
			if(bFirstPage)
			{
				self.elem.container.html($(self.consts.pages['template']));
				self.elem.main = self.elem.container.find('#main');
				self.splash(self.elem.main, $Dom, asHash, bFirstPage); //first page
			}
			else
			{
				self.elem.main.stop().fadeTo('fast', 0, function(){self.splash(self.elem.main, $Dom, asHash, bFirstPage);}); //Switching page
			}
		}
	};
	
	this.splash = function($FadeInElem, $Dom, asHash, bFirstPage)
	{
		//Switch main content
		$FadeInElem.empty();
		$FadeInElem.html($Dom);

		//Page Bootstrap
		self.pageInit(asHash, bFirstPage);
		
		//Show main
		$FadeInElem.fadeTo('fast', 1, function(){});
	};
	
	/* Variables Handling */
	
	this.vars = function(sVarName, oValue)
	{
		var asTypes = {boolean:false, string:'', integer:0, array:[], object:{}};
		var asVarName = (typeof sVarName == 'object')?sVarName:[sVarName];
		var sFirstVarName = asVarName[0];
		
		//Get, only name parameter
		if(typeof oValue == 'undefined')
		{
			return getElem(self.vars, asVarName);
		}
		//Init, name & type / default value
		else if(typeof oValue !== 'undefined' && typeof self.vars[sFirstVarName] === 'undefined')
		{
			self.vars[sFirstVarName] = (typeof asTypes[oValue] !== 'undefined')?asTypes[oValue]:oValue;
			return self.vars[sFirstVarName];
		}
		//Set, name & value
		else if(typeof oValue !== 'undefined' && typeof self.vars[sFirstVarName] !== 'undefined')
		{
			setElem(self.vars, asVarName, oValue);
			return getElem(self.vars, asVarName);
		}
		return null;
	};
	
	this.tmp = function(sVarName, oValue)
	{
		var asVarName = (typeof sVarName == 'object')?sVarName:[sVarName];
		asVarName.unshift('tmp');
		return self.vars(asVarName, oValue);
	};
}