/*
 * 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;}


(function(g){function f(c){try{return eval("typeof "+c)!="undefined"}catch(b){}return false}function h(c){var b=document.createElement("script");b.type="text/javascript";b.src=c;(document.getElementsByTagName("head").item(0)||document.body).appendChild(b)}var d;(function c(){var b=g.shift();if(!b)return d&&d();if(typeof b=="string"||b instanceof String)b={window:b};for(var e in b)if(e=="window"||!f(e))h(b[e]);var j=setInterval(function(){for(var i in b)if(!f(i))return;clearInterval(j);c()},99)})();
return function(c){return function(){var b=arguments;d=function(){c.apply(c,b)}}}})
([
	{'jQuery.easing.easeInQuad':absPath+'/shared/js/jquery.easing.js'} 
	 //'jQuery.fn.lightpop':absPath+'/shared/js/lightpop.js',
])

//ロールオーバー
$.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})}


//Slider
$.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]);
				}
			});
		}
	}
	if (settings.movement == 'peel') {
		$cont.find('li').append('<img class="peeler" src="'+absPath+'/shared/img/slider/fig_pager.png">');
		$cont.find('img.peeler').css({
			zIndex:99,position:'absolute',left:$cont.width(),top:$cont.height(),width:0,height:0
		})
	}
	$root.bind('moveContent'+eventName,function(e,c){
		if(settings.movement=='peel'){
			//peel
			var cr = $cont.find('li.current').index();
			
			if (c < 0 ) c=len-1 ;
			else if(c >= len) c=0 ;
			
			if (c != cr) {
				//CR IMAGE CHANGE
				crImage(c);
				//
				$cont.find('li')
					.css({zIndex:0})
				.filter('.current').removeClass('current')
					.css({zIndex:len})
						.find('span')
						.css({
							margin:0,width:$cont.width(),height:$cont.height()
						});
				$cont.find('li:eq('+c+')').queue('fx',[]).addClass('current')
					.css({zIndex:len+1})
				.find('span').queue('fx',[])
					.css({
						width:0,height:0
					})
					.animate({margin:0,width:$cont.width(),height:$cont.height()},{duration:settings.time, easing:'easeOut'+settings.easeStrength})
				.end()
					.find('img.peeler').queue('fx',[])
					.css({
						zIndex:len,left:0,top:0,width:0,height:0
					})
					.animate({left:2,top:2,width:$cont.width(),height:$cont.height()},{duration:settings.time*.8, easing:'easeOut'+settings.easeStrength})
					.animate({left:$cont.width(),top:$cont.height(),width:0,height:0},{duration:settings.time*.5, easing:'easeIn'+settings.easeStrength});
			}
		}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;
			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]);
	},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').add('#globalNav li a img').add('#itemNav li a img').add('#subNav li a img').add('.yoto li a img').addRollOver('_on');

	//現在のページへのリンク
	$('#globalNav li a').add('#subNav li a').add('#localNav dd a').addCurrentImages('_cr');	

	//外部リンクは別ウインドウを設定
	$('a[href^="http://"]:not([href^="http://www.aircarry.com/"])').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;
	})
	
	//#itemNameに?以降の文字列を入力しておく
	$('a[href*="?"]').each(function(){
		$(this).attr('href',encodeURI($(this).attr('href')));//URLエンコード
	});
	$('input#itemName').each(function(){
		$(this).val(decodeURI(location.search.slice(1)));//URLデコード
	});
	

	//するするアニメーション ※要scrollTo.js
	$('a[href^="#"]').each(function(){
		this.target = $(this).attr('href');
	}).click(function(){
		$.scrollTo( this.target, {speed:800} );
		return false;
	});
	
	//ulのliにoddとevenを追加
	$('div#rightCon ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	

	//:first-child, :last-childをクラスとして追加
	$(':first-child').addClass('firstChild');
	$(':last-child').addClass('lastChild');



	//マウスーバー時、画像を半透明にする
	$('a img.alpha').hover(function(){
		$(this).fadeTo(100,0.7);
	},function(){
		$(this).fadeTo(100,1.0);
	});
	
	
	//dd要素の非表示 ver1.0
	$('dl.faqList').each(function(){
		$(this).children('dd').hide();
		$(this).before('<p class="faqall alignR"><a href="#faq001">回答をすべて表示</a></p>');
	});
	
	$('p.faqall a').click(function(){
		$(this).removeAttr("href");
		if($(this).html() == '回答をすべて非表示'){
			$(this).parent().next().children('dd').hide();
			$(this).text('回答をすべて表示');
		}else{
			$(this).parent().next().children('dd').show();
			$(this).text('回答をすべて非表示');
		}
		return false;
	});
	
	$('dl.faqList dt a').click(function(){
		if($(this).parent().next().is(':visible')){
			$(this).parent().next().hide();
			if(!$(this).parent().nextAll('dd').is(':visible')&&!$(this).prevAll('dd').is(':visible'))$(this).parent().prev().children().text('回答をすべて表示');
		}else{
			$(this).parent().next().show();
			$(this).parents('dl').prev().children().text('回答をすべて非表示');
		}
		return false;
	});
	
	 	/*------------------------------------------
	 *	ホーム
	 */ if($('#home').length){
		
			$('#example').slider({separate:6,backClass:'.prev'});
		};// End if	
		

	
});
