//get or create the "nuskin" namespace
var nuskin = nuskin || {};
//require nuskin.util namespace
if(!nuskin.util) {
	alert("error: missing nuskin.util namespace");
}
var redirect = true;
var hashString = window.location.hash.substring(1);
if (hashString && hashString == "choose") {
	redirect = false;
}
var savedLocation = dojo.cookie('nuskin.hello.savedLocation');
if(redirect && savedLocation) {
	//console.log('savedLocation: '+savedLocation);
	var locationValid = false;
	dojo.query('#globalLanding .links a').forEach(function(node, index, nodeList){
		var href = dojo.attr(node, 'href');
		//console.log('   link: '+href);
		if(href == savedLocation || savedLocation.match(href+"$") == href) {
			locationValid = true;
		}
	});
	if(locationValid) {
		window.location = savedLocation;
	} else {
		//invalidate the cookie
		dojo.cookie('nuskin.hello.savedLocation', null, {path:'/', expires: -1});
	}
}