var BASE_PATH = '/' + 'allnewm';
var hash = window.location.hash.substring(1); // eg "/main/landing"
var path = window.location.pathname.substring(BASE_PATH.length); 

var captureString =hash.split('/');

var first = captureString[captureString.length-2];
var last = captureString[captureString.length-1];


if(hash != '' && hash.match(/^\//) == null) {
	hash = '/' + hash;
	window.location = '#' + hash;
} 

if(path.charAt(path.length-1) == '/') // strip trailing slash
	path = path.substring(0, path.length-1);

if(hash != '' && hash != path) {
	
	if (last =='share-email' && (first == '' || first ==null)){
		var newURL = BASE_PATH + '/index.html#/' + last;
		window.location = newURL;
	} else if (last =='share-email' && (first != '' || first !=null)){
		var newURL = BASE_PATH +'/' + first + '/index.html#/' + first + '/' + last;
		window.location = newURL;	
	}else if (first == '' || first ==null){
		var newURL = BASE_PATH +'/' + last + '/index.html#/' + last;
		window.location = newURL;	
	} else{
		var newURL = BASE_PATH +'/' + last + '/index.html#/' + first + '/' + last;
		window.location = newURL;	
	}


} else if(hash == '' && window.location.pathname.match(BASE_PATH)) {
	//Check to see if page loads with /index.html#. IE 6 & 7 bug - browsers crash
	var windowPath = window.location.href;
	var checkHash = windowPath.charAt(windowPath.length -1);
	
	if (checkHash == '#'){
		var deleteHashUrl = windowPath.replace('#', '');
		var newURL = deleteHashUrl;
		window.location = newURL;
	} else {
	var newURL = '#'+path.replace('/index.html','');
		try{
			window.location = newURL;
		}
			catch(e){}	
	};

};

//Express Install Cookie
function declinedExpressInstall() {
	document.cookie = "declinedExpressInstall = true; path=/allnewm/";
};

function getExpressInstallPath(){
		var searchCookie = document.cookie;
		var expressInstallFound = searchCookie.match("declinedExpressInstall");
		
		if (expressInstallFound){
			return "";
			//no express install path provided
		}else {
			return '/allnewm/swfobject/expressInstall.swf';
		}	
}
