/*
 * jcommon.js 1.2
 * Copyright (c) 2010 C.M.A. Co.,Ltd.
 *
 * Last Added: 2010-07-09
 *
 */

//GoogleAnalytics
var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-*******-*']); 
_gaq.push(['_setDomainName', 'none']); 
_gaq.push(['_setAllowLinker', true]); 
_gaq.push(['_trackPageview']);
(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();

//Utility
var absPath,sharePath = '/shared',isIE='\v'=='v',isIE6=(navigator.userAgent.indexOf("MSIE 6")>=0)?true:false,isWebKit = navigator.userAgent.match(/WebKit/),isLinkAry = location.pathname.split('/').slice(1),jcommon={preloader:{loadedImages:[],load:function(a){var b=this.loadedImages,c=b.length;b[c]=new Image;b[c].src=a}},URIExp:new RegExp("^[https]*[^a-z]*"+document.domain),URI:function(a){this.absolutePath=a.replace(jcommon.URIExp,"").replace(/^[^a-z]*/,"").replace(/index.*$/,"").replace(/\/$/,"");this.len=isLinkAry.length;for(this.isSelfLink=false;this.len--&&!this.isSelfLink;)this.isSelfLink=this.isSelfLink||this.absolutePath==isLinkAry[this.len]},addLinkAry:function(){for(var a=0,b=isLinkAry.length;a<
b;)isLinkAry.push(isLinkAry.slice(0,++a).join("/").replace(/^\//,"").replace(/index.*$/,""))}};jcommon.addLinkAry();switch(true){case location.host.split('.')[1]===('apkisndov'+40*50).replace(/[p-z]/g,''):absPath = '/'+(location.pathname.split('/')[1]);var isBeta = true;break;case location.protocol==='file:':absPath = (isIE?'':'/')+('IYK:M/HOtMdoNcRs/X').replace(/[I-X]/g,'')+(location.pathname.split('/')[3])+'/www/\u4f5c\u696d\u7528';var isBeta = true;break; default:absPath = '';break;}

//ロールオーバー
$.fn.addRollOver=function(add){$(this).filter('img').each(function(){$(this).runRollOver(add,$(this));}).end().not('img').each(function(){$(this).runRollOver(add,$(this).find('img'));});};
$.fn.runRollOver=function(add,target){$(this).each(function(num){this.originalSrc=String(target.attr('src'));this.rolloverSrc=this.originalSrc.replace(/(\.gif|\.jpg|\.png)/,add+"$1");}).hover(function(){target.attr('src',this.rolloverSrc);},function(){target.attr('src',this.originalSrc);});};
//現在のページへのリンク
$.fn.addCurrentImages=function(add){$(this).each(function(){var href=new jcommon.URI($(this).attr('href'));if(href.isSelfLink){$(this).addClass('current');$(this).unbind('mouseenter');$(this).unbind('mouseleave');$(this).find('img').each(function(){$(this).unbind('mouseenter');$(this).unbind('mouseleave');this.currentSrc=this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/,add+"$1");$(this).attr('src',this.currentSrc)});}});};	
//ページ全体にリンク
$.fn.groupLink=function(){$(this).css({cursor:'pointer'}).hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){location.href=$(this).find('a:last').attr('href');return false})}
//ページpopUp ※href="[表示するURL]?width=000&amp;height=000"
	$.fn.pagePoper=function(){$(this).each(function(){this.param=$(this).attr("href");this.param=this.param.split('?');if(this.param[1]){this.param[1]=this.param[1].split('&');this.param[1]=this.param[1].join(',');$(this).attr("href","").click(function(){window.open(this.param[0],'popup',"menubar=1,location=1,resizable=1,status=1,scrollbars=1,"+this.param[1]);return false});}});};
	
	
$.fn.slider=function(settings){
			settings = jQuery.extend({
				movement:'slide',
				isCurrentImage:false,
				currentImage:'_on',
				currentClass:'current',
				contClass:'.contents',
				nextClass:'.next',
				backClass:'.back',
				naviClass:'.navigation',
				separate:1,
				overshoot:10,
				time:500,
				loop:false,
				auto:false,
				easeStrength:'Expo'
			},settings);
			// Init
			var	$root	= $(this), 
				$cont	= $(this).find(settings.contClass+':first'),
				$next	= $(this).find(settings.nextClass+':first'),
				$back	= $(this).find(settings.backClass+':first'),
				$navi	= $(this).find(settings.naviClass+':first');
			var	len		= $cont.find('ul:first>li').length,
				count	= 0,
				eventName = $root.attr('id')||$root.attr('class').split(' ',1);
			var crImage = function(c){
				$cr = $navi.find('li:eq('+count/settings.separate+')');
				$cr.trigger('changeImage'+eventName,false);
				count = c;
				$cr = $navi.find('li:eq('+count/settings.separate+')');
				$cr.trigger('changeImage'+eventName,true);
			}
			var autoTrigger = function(){
				if(settings.auto){
					//$root.stop().clearQueue();
					$root.animate({width:$root.width()},{
						duration: settings.auto,
						easing: 'linear',
						complete: function(){
							$root.trigger('moveContent'+eventName,[count+settings.separate]);
						}
					});
				}
			}
			$root.bind('moveContent'+eventName,function(e,c){
				if(settings.movement=='fade'){
					//fade
					var isEnd	= false, $cr;
					if(settings.auto||settings.loop){
						if (c < 0 ) c=len-1 ;
						else if(c >= len) c=0 ;
					}
					if(c<0||c>=len){
						count = (c<0?0:len-settings.separate);
						isEnd = true;
					}else{
						//CR IMAGE CHANGE
						crImage(c);
					};
					var moveX	= $cont.find('ul:first>li:eq('+count+')').position().left;
					var moveY	= $cont.find('ul:first>li:eq('+count+')').position().top;
					$cont.find('ul:first>li').removeClass('current');
					$cont.find('ul:first>li:eq('+count+')').addClass('current');
					if(!isEnd){
						$cont.find('ul:first').queue('fx',[])
							.fadeTo(settings.time,0,function(){
								$(this).css({left:-moveX,top:-moveY}).fadeTo(settings.time,1);
							});
					};
				}else{
					//slide||updown
					var isEnd	= false, overshoot = 0, $cr;
					if(settings.auto||settings.loop){
						if (c < 0 ) c=len-1 ;
						else if(c >= len) c=0 ;
					}
					if(c<0||c>=len){
						count = (c<0?0:len-settings.separate);
						overshoot = settings.overshoot*(c<0?1:-1);
						isEnd = true;
					}else{
						//CR IMAGE CHANGE
						crImage(c);
					};
					var moveX	= $cont.find('ul:first>li:eq('+count+')').position().left;
					var moveY	= $cont.find('ul:first>li:eq('+count+')').position().top;
					$cont.find('ul:first>li').removeClass('current');
					$cont.find('ul:first>li:eq('+count+')').addClass('current');
					if(isEnd){
						var	overshootX = settings.movement=='slide'?overshoot:0,
							overshootY = settings.movement=='updown'?overshoot:0;
						$cont.find('ul:first').queue('fx',[])
							.animate({left:-moveX+overshootX,top:-moveY+overshootY},{duration:settings.time/2, easing:'easeOut'+settings.easeStrength})
							.animate({left:-moveX,top:-moveY},{duration:settings.time/2, easing:'easeInOut'+settings.easeStrength});
					}else{
						$cont.find('ul:first').queue('fx',[])
							.animate({left:-moveX,top:-moveY},{duration:settings.time, easing:'easeOut'+settings.easeStrength});
					};
				}
				autoTrigger();
			});
			$back.click(function(){
				$root.trigger('moveContent'+eventName,[count-settings.separate]);
				return false;
			});
			$next.click(function(){
				$root.trigger('moveContent'+eventName,[count+settings.separate]);
				return false;
			});
			$navi.find('li').css({cursor:'pointer'}).click(function(){
				$root.trigger('moveContent'+eventName,[$(this).index()*settings.separate]);
				return false;
			})
			.bind('changeImage'+eventName,function(e,cr,noClass){
				if(settings.isCurrentImage){
					var	src = $(this).find('img').attr('src'),
						regexp = new RegExp(settings.currentImage+'(\.[a-z]+)$');
					if(cr&&!src.match(regexp)){
						$(this).find('img').attr('src',src.replace(/(\.[a-z]+)$/,settings.currentImage+'$1')); 
					}else if(!cr){
						$(this).find('img').attr('src',src.replace(regexp,'$1'));
					}
				}
				if(!noClass){
					cr ?
						$(this).addClass(settings.currentClass):
						$(this).removeClass(settings.currentClass);
				}
			}).hover(function(){
				$(this).addClass('hover');
				//if(!$(this).hasClass(settings.currentClass))$(this).trigger('changeImage'+eventName,[true,true]);
				$root.trigger('moveContent'+eventName,[$(this).index()*settings.separate]);
			},function(){
				$(this).removeClass('hover');
				if(!$(this).hasClass(settings.currentClass))$(this).trigger('changeImage'+eventName,[false,true]);
			});
			autoTrigger();
			return this;
		};


	
$(function(){

	//beta
	if(isBeta){
		$('a[href^="/"]').each(function(){var url = $(this).attr('href');$(this).attr('href',absPath+url);});
		$('img[src^="/"]').each(function(){var url = $(this).attr('src');$(this).attr('src',absPath+url);});
	}

	//ロールオーバー
	$('a img.btn,a.btn,#globalNav li a').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a').addCurrentImages('_on');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="除外したいURL"])').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');

	//別ウィンドウを設定
	$('a[href$=".pdf"],a[href$=".asx"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	})
	//:first-child, :last-childをクラスとして追加
	$('tr,th').filter(':first-child').addClass('firstChild');
	$('dd,li,tr,th').filter(':last-child').addClass('lastChild');
	
		//oddとevenを追加
	$('li').filter(':odd').addClass('even').end().filter(':even').addClass('odd');

	//連番nxxxをクラスとして追加
	$('#flowNum li').each(function(num){
		$(this).addClass('n'+(++num));
	});
	
		//ポップアップ
	$('#Home a.popup').pagePoper();


	if($('body#Home').length){
		//slider
		$('#mainVisual').slider({movement:'fade',loop:true,auto:7000});
	}

});
