(function(){

	var admin = {}
	admin.readCookie = function (name){
		var cookieValue = null;
	    if (document.cookie && document.cookie != '') {
	        var cookies = document.cookie.split(';');
	        for (var i = 0; i < cookies.length; i++) {
	            var cookie = admin.trim(cookies[i]);
	            // Does this cookie string begin with the name we want?
	            if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                cookieValue = decodeURIComponent(cookie.substring(name.length + 1).replace(/\+/g, '%20'));
	                break;
	            }
	        }
	    }
	    return cookieValue;
	}
	admin.isAuthenticated=function(){
		var info = admin.readCookie('_au'); // authentication information
		if (info && info.length)return true; else return false;
	}
	
	admin.addJS = function (url){
		var js=document.createElement('script');
		js.setAttribute('type','text/javascript');
		js.setAttribute('src',''+url);
		document.getElementsByTagName("head")[0].appendChild(js);
	}
	admin.addCSS = function (url){
		var js=document.createElement('link');
		js.setAttribute('rel', 'stylesheet');
		js.setAttribute('type', 'text/css');
		js.setAttribute('media', 'screen');
		js.setAttribute('href', ''+url);
		
		document.getElementsByTagName("head")[0].appendChild(js);
	}
	admin.trim = function (text){
		return (text || "").replace( /^(\s|\u00A0)+|(\s|\u00A0)+$/g, "" );
	}
	if (admin.isAuthenticated()){
		document.getElementsByTagName('html')[0].className+= ' with-app-nav';
			var session = (function(){
				 try {
		             if( !! window.sessionStorage ) return window.sessionStorage;
		         } catch(e) {
		             return undefined;
		         }
			})();

		if (session && session.getItem('app-nav-collapsed')) document.getElementsByTagName('html')[0].className+=' app-nav-collapsed';
		
		var js = document.getElementById('app-load-script').getAttribute('data-load-js').split(' ');
		var css = document.getElementById('app-load-script').getAttribute('data-load-css').split(' ');
		
		for(var i=0;i<js.length;i++){
			admin.addJS(js[i])
		}
		for(var i=0;i<css.length;i++){
			admin.addCSS(css[i])
		}
	}
})()
