/* [www.artfairtokyo.com]
 * Summary: common script
 * LastModified: 2009-12-15
 * This script requires jquery.js
 */


document.createElement("abbr");

(function () {
	var favicon = document.createElement("link");
	favicon.setAttribute("rel", "shortcut icon");
	favicon.setAttribute("href", "/favicon.ico");
	document.getElementsByTagName("head")[0].appendChild(favicon);
})();

/* Global Object */
var AFT;
if(!AFT) AFT = {};

/*----------------------------------------------------------------------------
 check UserAgent
----------------------------------------------------------------------------*/
AFT.UA = {
	os: function() {
		if(navigator.userAgent.indexOf('Mac') != -1) {return 'Mac';}
		else if(navigator.userAgent.indexOf('Windows') != -1) {return 'Win';}
		else return 'Other';
	},
	documentSet: function() {
		if(AFT.UA.os() == 'Mac') {
			$('body').addClass('mac');
			if(navigator.userAgent.indexOf('WebKit') != -1) {
				$('body').addClass('macwebkit');
			}
		} else if(AFT.UA.os() == 'Win') {
			$('body').addClass('win');
		} else {
			$('body').addClass('other');
		}
	}
}
/*----------------------------------------------------------------------------
 global navigation setting
----------------------------------------------------------------------------*/
AFT.nav = function(navEle) {
	var config = {
		className: 'cr'
	}
	return {
		setGlobal: function() {
			var splitedPath = location.pathname.split('/');
			if(splitedPath[1] === 'en') {
				var targetPath = splitedPath[2];
			} else {
				var targetPath = splitedPath[1];
			}
			$(navEle + ' a').each(function() {
				var crId = this.href.match(/[a-zA-Z_-]+\//g);
				crId = crId[crId.length - 1];
				crId = crId.slice(0, crId.length -1);
				if (crId === targetPath) {
					$(this).addClass(config.className);
				}
			});
		},
		setLocal: function(){
			function init(jQele) {
				jQele.each(function() {
					if (this.href === location.href) {
						$(this).addClass(config.className);
					} else {
						$(this).removeClass(config.className);
					}
				});
			}
			var ele = $(navEle + ' a');
			init(ele);
			ele.click(function() {
				setTimeout(function() {
					init(ele);
				}, 2000);
			});
		}
	}
}

/*----------------------------------------------------------------------------
 onload event function
----------------------------------------------------------------------------*/
$(document).ready(function() {
AFT.UA.documentSet();
var AFTglobalNav = AFT.nav('ul.nav_global');
AFTglobalNav.setGlobal();
var AFTwidgetNav = AFT.nav('div.widget');
AFTwidgetNav.setLocal();
})


