var app = {	
	
	debug : 0,	

	jsbase : '..',
	
	hasSB_Includes : 0,
	
	hasTC_Includes : 0,	
	
	
	init : function(){		
		
		//get custom
		if(!app.custom){app.include('app.custom.js');}
		
		//configure surebert
		if(!this.hasSB_Includes){
			this.hasSB_Includes = 1;
			this.custom.sb_includes();
		}
		
		//configure tony framework
		if(!this.hasTC_Includes){
			this.hasTC_Includes = 1;
			this.custom.tc_includes();
		}
		
		this.custom.sb_config();
				
		this.startMod('navi');
		
		
		//page reloads
		var reload = (sb.cookies.get('page'))?sb.cookies.get('page'):app.custom.default_page;	
		reload = (sb.browser.$_GET['goingto'])?sb.browser.$_GET['goingto']:reload;		
		this.startMod(reload);		
	},
	
	startMod : function(module, refOnly){
			
		var block = this.custom.refs[module];
		var m = '';
		refOnly = refOnly || 0;
		
		//add refs for that module
		if(block){
			for(var i=0;i<block.length;i++){	
				if(sb.$("#" + block[i])){				
					this[block[i]] = $("#" + block[i]);
					 m += block[i] + "\n";			
				}
			}	  
		}
		
		
		//logout exeption
		module = (module == 'logout')?'login':module;
		module = (module == 'pending')?'update':module;
		module = (module == 'thanks')?'update':module;
		
		//start the module for that module
		if((this[module]) && !refOnly && (typeof(this[module].init) == 'function')){
			this[module].init();this.navi.updateTimer();
		}else{
			if(this.debug){
				this.warn(module + " is not a valid module name for this application");
			}
		}
		
		if(this.debug){this.report(m);}
	},
	
	refresh : function() {
		sb.events.removeAll();
		this.init();
	},
	
	include : function(str){
		//alert("loaded " + str);
		sb.load(this.jsbase + str);
	},
	
	events : {},
	
	error : function(str){
		sb.consol.write(str, 'red', 'black');
	},
	
	report : function(str){
		sb.consol.write(str, 'pink', 'brown');
	},
	

	
	warn : function(str){
		alert('Warning: ' + str);
	}
};
