/* redirect if iPhone */

if(navigator.userAgent.indexOf('iPhone') > -1){
	location.href = '/sp/';
}

// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
	log.history = log.history || [];   // store logs to an array for reference
	log.history.push(arguments);
	if(this.console){
		console.log( Array.prototype.slice.call(arguments) );
	}
};

// avoid http://foo.com/#
if(location.href.match(/#$/)){
	location.href = location.href.replace(/#$/,'');
}
if(location.href.match(/#\!\/top$/)){
	location.href = location.href.replace(/#\!\/top$/,'');
}

// add html class
(function(){

	var html = document.getElementsByTagName('html')[0];
	
	function addClass(condition, classIfTrue, classIfFalse){
		var str = html.className;
		var classToAdd = condition ?
			classIfTrue :
			(classIfFalse !== undefined) ? classIfFalse : null;
		if(classToAdd === null){
			return;
		}
		html.className = str ?  (str + ' ' + classToAdd) : classToAdd;
	}

	addClass(navigator.appVersion.indexOf("Win") !== -1, 'os-win');
	addClass(navigator.userAgent.indexOf("MSIE 6") !== -1, 'browser-ie6');

})();


// loaders
window.loadCss = function(src){
	var link = document.createElement("link");
	link.type = "text/css";
	link.rel = "stylesheet";
	link.href = src;
	document.getElementsByTagName("head")[0].appendChild(link);
}
window.loadJs = function(src){
	var script = document.createElement('script');
	script.src = src;
	document.getElementsByTagName('head')[0].appendChild(script);
}

loadJs('/common/js/modernizr-1.6.min.js');


/* namespacing */
var jwt = {};

jwt.isEn = function(){
	var path = location.pathname;
	return (/^\/en\/.+$/.test(path) || /^\/en.+$/.test(path));
};
jwt.getMapPath = function(){
	return jwt.isEn() ? 'map-en' : 'map-ja';
};


