jQuery(function($){
	$.ajax({
		type: "GET", url : rootPath + "assets/scripts/src/shift.js", dataType: "script",
		success: function() {
			var path = shift.getURL();
			var dir,page,n;
			if(path['file'].indexOf('.html')>0) {
				n = path['file'].indexOf('.html');
			} else if(path['file'].indexOf('.php')>0) {
				n = path['file'].indexOf('.php');
			}
			
			// ページにディレクトリ名・ファイル名のクラスを付与
			(rootPath==''||!rootPath) ? dir = 'top' : dir = path['dir'];
			(path['file']=='') ? page = "index" : page = path['file'].substring(0,n);
			$('body').addClass(dir).addClass(page);
			
			// グローバルナビゲーション
			$('#gNavi li[id*='+dir+'] a').addClass('active');
			
			// セミナーお問い合わせ
			if(dir=='inquiry'){
				$('#gNavi li#seminars a').addClass('active');
				$('#gNavi li#inquiry a').removeClass('active');
			}
			$('#gNavi li').hover(function(){
				var t = $(this);
				clearTimeout(this._tim2);
				this._tim1 = setTimeout(function(){ t.find('ul:first').fadeIn(); }, 150);
			},function(){
				var t = $(this);
				clearTimeout(this._tim1);
				this._tim2 = setTimeout(function(){ t.find('ul').hide(); }, 300);
			});
			if(dir=='top') {
				shift.include(rootPath+'assets/scripts/jquery.cycle.min.js');
				shift.include(rootPath+'assets/scripts/top.js');
			} else  {
				$('#subHeader').hoverAlpha({opacity:0.2});
				$('.pageTop').hoverAlpha({opacity:0.2});
				var curPage;
				(page=='index') ? curPage = false : curPage = path["file"];
				if(!curPage) { 
					$('#subHeader a:first').addClass('active');
				} else {
					$('#subHeader a[href*='+curPage+']').addClass('active');
				}
			}
			// ページ別js
			if(dir=='system') {
				shift.include(rootPath+'assets/scripts/system.js');
			}
			if(dir=='website') {
				shift.include(rootPath+'assets/scripts/website.js');
			}
			shift.importCSS(rootPath + 'assets/styles/' + dir + '.css');
			shift.include(rootPath + 'assets/scripts/jquery-ui-1.8.2.custom.min.js');
			/*shift.externalLink({absolute: true});*/
			shift.smoothScroll();
			$('#gNavi').hoverAlpha({opacity:0.3});
			$('body').hoverAlpha({opacity:0.3});
			$('#footer ul').hoverAlpha({opacity:0.3});
			$('#footer ul').addCaption();
			$('#header').addCaption({img:true});
			$('#header').addCaption();
			$('#contentBody').addCaption({img:true});
			$('#contentBody').addCaption({img:false});
			$('.buttons button').button();
			$('.buttons a').button();
		},
		error: function(a,b,c) {
			console.log("XMLHttpRequest : " + a );
			console.log("textStatus : " + b);
			console.log("errorThrown : " + c);
		}
	});
});
function dateParse(str){
	var objDate = new Date(str);
//	str = objDate.toLocaleDateString();
	return str;
}
function replaceLink(str) {
	var urlReg = new RegExp(/(https?:\/\/[\x21-\x7e]+)/gi);
	if(str.match(urlReg)){
		var uri = str.match(urlReg);
		str = str.replace(uri,'<a href="'+uri+'" rel="external">'+uri+'</a>');
	}
	return str;
}

