

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}
 

addLoadEvent(urlRewrite);
 
 
function urlRewrite(){
	//console.log('urlRewrite()');
	var currenturl = location.href;  // http://localhost:8888/mindtransplant_v02/
	var currenthost = "http://"+location.host;
	var currenthostendslash = "http://"+location.host+"/";
	var path = location.pathname;  // entspricht dem pfad nach www.mindtransplant.com also z.B. -> /de/fotos
		
		if(currenturl.indexOf('#') < 0) {
			//Injects # in the url.
			//Check if path is larger then 1
			if(1 < path.length){
				location.href = currenthost+"#/"+path.substring(1,location.pathname.length);
			}
			
		} else {
		     // location.href = currenthostendslash;
			// Checks if # is in the right place
			if(currenthostendslash.length != currenturl.indexOf('#')){
				//Removes the # form the string an injects i at the right place.
				location.href = currenthostendslash+"#/"+path.substring(1,location.pathname.length);		
			}
		
		}
			
}


