app.navi = {
	
	attachEvents : function(){ 
		app.appnavlist.event('click', this.newPage);
	},

	onLoad : null,
	
	page : '',
	
	visit : function(sDest, func){
		
		//defaults to home
		sDest = sDest || "login-";		
		var sUser = (sDest.indexOf('-') > 0)?'&usr=1':'';
		this.page  =  sDest.replace('-', '');
		var sData  = "c=nav&goingto=" + this.page + sUser;			
		
		this.ajax = new sb.ajax({
			data : sData,
			format : 'json',
			handler : function(data){
				app.navi.load(data);	
				if(typeof(func) == 'function'){
					func();
				}
			}
		});		
		this.ajax.fetch();
		this.ajax = null;
		
		document.cookie = 'page=' + this.page;
	},
	
	indicate : function(href){
		
		
		//REFACTOR: using app.navii				
		this.tabs = app.navii.$('a');
		
		this.tabs.forEach(function(v){
			v.removeClassName("selected");		
		});
		
		//risque	
		var tab = $('#navii a[href*="' + href + '"]');		
		
		
		if(tab[0]){
			tab[0].addClassName("selected");
		}
		
		
	},
	
	init : function(){ 
			this.attachEvents();
			this.updateTimer();
	}, 
	
	load : function(data){ 
		
		
		var good = 0;
		var what = '';
			
			for(var i in data){	 							
				if(app[i]){ 						
					app[i].innerHTML = data[i];	
					good = 1;
				}
			}
			
			if(sb.typeOf(app.navi.onLoad) == 'function'){app.navi.onLoad();}		
			//app.refresh();
			app.startMod(app.navi.page);
			return good;
	},
	
		
	timer : null,
	
	timersettings : { 
		seconds : 	900,
		handler : function(){ 	
			//touch the server		
			new sb.ajax({ 
				url : '../data/touch.php'
			}).fetch();
		}
	},
	
	updateTimer : function(){ 		
				
		if(app.username.innerHTML.trim() != 'Anonymous'){ 	
			
			if(this.timer){
				this.timer.restart();
			}else{ 
				this.timer = new sb.utils.timer(this.timersettings);
				this.timer.begin();
				var time = new sb.date;
			}
			
		}else{					
			if(this.timer){
				this.timer.end();
				this.timer = null;
			}
		}
		
			
	},
	

	newPage : function(e){
		var targ = sb.events.target(e);
			
		if(targ.nodeName == 'A' && targ.className != 'offsite'){	
			sb.events.stopAndPrevent(e);					
			app.navi.visit(targ.href.replace(/.*#/, ''));			
		}
	}, 
	
	fade : function(targ){  
	
	}
	
};