/*  ================================================================================
 *
 *  jQuery Page Scroller -version 3.0.8
 *  http://coliss.com/articles/build-websites/operation/javascript/296.html
 *  (c)2011 coliss.com
 *
 *  この作品は、クリエイティブ・コモンズの表示 2.1 日本ライセンスの下で
 *  ライセンスされています。
 *  この使用許諾条件を見るには、http://creativecommons.org/licenses/by-sa/2.1/jp/を
 *  チェックするか、クリエイティブ･コモンズに郵便にてお問い合わせください。
 *  住所は：559 Nathan Abbott Way, Stanford, California 94305, USA です。
 *
================================================================================  */


/*  ================================================================================
TOC
============================================================
Ooption
Page Scroller
============================================================
this script requires jQuery 1.3-1.4.4(http://jquery.com/)
================================================================================  */


/*  ================================================================================
Ooption
================================================================================  */
var virtualTopId = "top",
    virtualTop,
    adjTraverser,
    adjPosition = 1,
    callExternal = "pSc",
    delayExternal= 50,
    adjSpeed = .5;

/* option example
======================================================================  */
//  virtualTop = 0;    // virtual top's left position = 0
//  virtualTop = 1;    // virtual top's left position = vertical movement
//  adjTraverser = 0;  // left position = 0
//  adjTraverser = 1;  // horizontal movement.
//  adjPosition = -26;

/*  ================================================================================
Page Scroller
================================================================================  */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('(c($){7 C=$.H.C,w=$.H.w,F=$.H.F,A=$.H.A;$.H.1P({w:c(){3(!6[0])1H();3(6[0]==h)b 1K.1O||$.1D&&5.z.1x||5.f.1x;3(6[0]==5)b((5.z&&5.1G=="1s")?5.z.1u:5.f.1u);b w.1e(6,1f)},C:c(){3(!6[0])1H();3(6[0]==h)b 1K.1N||$.1D&&5.z.1F||5.f.1F;3(6[0]==5)b((5.z&&5.1G=="1s")?5.z.1d:5.f.1d);b C.1e(6,1f)},F:c(){3(!6[0])b 17;7 j=5.M?5.M(6[0].u):5.1h(6[0].u);7 k=1o 1r();k.x=j.19;1q((j=j.1j)!=V){k.x+=j.19}3((k.x*0)==0)b(k.x);g b(6[0].u)},A:c(){3(!6[0])b 17;7 j=5.M?5.M(6[0].u):5.1h(6[0].u);7 k=1o 1r();k.y=j.1m;1q((j=j.1j)!=V){k.y+=j.1m}3((k.y*0)==0)b(k.y);g b(6[0].u)}})})(1Q);$(c(){$(\'a[q^="#"], 20[q^="#"]\').22(\'.1k a[q^="#"], a[q^="#"].1k\').1a(c(){7 i=Q.21+Q.1Z;7 I=((6.q).25(0,(((6.q).13)-((6.15).13)))).R((6.q).1C("//")+2);3(i.G("?")!=-1)Y=i.R(0,(i.G("?")));g Y=i;3(I.G("?")!=-1)X=I.R(0,(I.G("?")));g X=I;3(X==Y){d.12((6.15).23(1));b 1T}});$("f").1a(c(){d.L()})});6.r=V;7 d={14:c(B){3(B=="x")b(($(5).w())-($(h).w()));g 3(B=="y")b(($(5).C())-($(h).C()))},W:c(B){3(B=="x")b(h.18||5.f.v||5.f.N.v);g 3(B=="y")b(h.1S||5.f.1c||5.f.N.1c)},P:c(l,m,D,p,o){7 r;3(r)J(r);7 1A=16*1X;7 S=d.W(\'x\');7 O=d.W(\'y\');3(!l||l<0)l=0;3(!m||m<0)m=0;3(!D)D=$.1E.1Y?10:$.1E.1W?8:9;3(!p)p=0+S;3(!o)o=0+O;p+=(l-S)/D;3(p<0)p=0;o+=(m-O)/D;3(o<0)o=0;7 U=E.1J(p);7 T=E.1J(o);h.1U(U,T);3((E.1I(E.1v(S-l))<1)&&(E.1I(E.1v(O-m))<1)){J(6.r);h.1i(l,m)}g 3((U!=l)||(T!=m))6.r=1n("d.P("+l+","+m+","+D+","+p+","+o+")",1A);g J(6.r)},L:c(){J(6.r)},24:c(e){d.L()},12:c(n){d.L();7 s,t;3(!!n){3(n==1M){s=(K==0)?0:(K==1)?h.18||5.f.v||5.f.N.v:$(\'#\'+n).F();t=((K==0)||(K==1))?0:$(\'#\'+n).A()}g{s=(1y==0)?0:(1y==1)?($(\'#\'+n).F()):h.18||5.f.v||5.f.N.v;t=1B?($(\'#\'+n).A())+1B:($(\'#\'+n).A())}7 11=d.14(\'x\');7 Z=d.14(\'y\');3(((s*0)==0)||((t*0)==0)){7 1t=(s<1)?0:(s>11)?11:s;7 1w=(t<1)?0:(t>Z)?Z:t;d.P(1t,1w)}g Q.15=n}g d.P(0,0)},1z:c(){7 i=Q.q;7 1l=i.1C("#",0);7 1b=i.1V(1g);3(!!1b){1p=i.R(i.G("?"+1g)+4,i.13);1R=1n("d.12(1p)",1L)}3(!1l)h.1i(0,0);g b 17}};$(d.1z);',62,130,'|||if||document|this|var||||return|function|coliss||body|else|window|usrUrl|obj|tagCoords|toX|toY|idName|frY|frX|href|pageScrollTimer|anchorX|anchorY|id|scrollLeft|width|||documentElement|top|type|height|frms|Math|left|lastIndexOf|fn|anchorPath|clearTimeout|virtualTop|stopScroll|getElementById|parentNode|actY|pageScroll|location|slice|actX|posY|posX|null|getWindowOffset|anchorPathOmitQ|usrUrlOmitQ|dMaxY||dMaxX|toAnchor|length|getScrollRange|hash||true|TouchXOffset|offsetLeft|click|checkPageScroller|scrollTop|scrollHeight|apply|arguments|callExternal|all|scroll|offsetParent|nopscr|checkAnchor|offsetTop|setTimeout|new|anchorId|while|Object|CSS1Compat|setX|scrollWidth|abs|setY|clientWidth|adjTraverser|initPageScroller|spd|adjPosition|indexOf|boxModel|browser|clientHeight|compatMode|error|floor|ceil|self|delayExternal|virtualTopId|innerHeight|innerWidth|extend|jQuery|timerID|TouchYOffset|false|scrollTo|match|opera|adjSpeed|mozilla|pathname|area|hostname|not|substr|cancelScroll|substring'.split('|'),0,{}));



/**
 * Smartphone check Plugin
 * User: Tenderfeel
 * Date: 11/08/08
 * LastModified: 11/09/28
 * version:1.3.93
 *
 */

(function($) {
    /**
     * jQuery function 'checkSmartphone'
     * @param method {string|object|undefined}
     *
     * $(document.body).checkSmartphone({});
     */
    $.fn.checkSmartphone = function(method) {
        var ua = navigator.userAgent;

        var OS = null;
        var APPLE = false;
        var ANDROID = false;
        var WINDOWS = false;
        var BROWSER_NAME = null;
        var DEVICE_NAME = null;
        var OS_VERSION = 0;
        var BROWSER_VERSION = null;
        var TABLET = false;
        var SMARTPHONE = false;
        var TOUCH = false;
        var isOrientation = function() {
            return (typeof window.orientation != 'undefined');
        };

        var isTouch = function() {
            if (typeof TouchEvent != 'undefined') {
                return true;
            } else {
                return false;
            }
        };
        var _doAndroid = function() {
            var m;
            ANDROID = true;
            OS = 'android';
            TOUCH = isTouch();

            if ($.browser.webkit) {
                m = ua.match(/([\w]+)\s(\d\.\d(?:[^;]+)*); \w{2,3}\-\w{2,3};\s([^\/]+)\sBuild\/[^\)]*\).*Version\/([\d\.]+)\s([\w\s]*Safari)\/[\d\.]+/i);
                /**
                 * m[1] OS Name
                 * m[2] OS Version
                 * m[3] Device name
                 * m[4] Browser Version
                 * m[5] Browser name
                 */
                 
                if(m){
                	OS = m[1];
                	OS_VERSION = m[2];
                	DEVICE_NAME = m[3].replace(/\s/ig, '');
                	BROWSER_NAME = m[5].replace(/\s/ig, '');
                	BROWSER_VERSION = m[4];
				} else {
					
					if(ua.indexOf('Chrome') > -1){
						BROWSER_NAME = 'Chrome';
					} 
					
				}
				
            } else if ($.browser.opera) {
                m = ua.match(/Opera\/9\.80 \((?:Android )*([^;]+);(\sLinux;)*\s([^\/]+)\/([^\/]+)[^;]*;\s\w+;\s([^\)]*)\).*Version\/([\d\.]+)/i);
                /**
                 * m[1] OS Name
                 * m[2] OS Version
                 * m[3] Browser Name
                 * m[4] Browser Version(mini)
                 * m[5] lang
                 * m[6] Browser Version(mobi)
                 */
                OS = m[1];
                OS_VERSION = m[2];
                BROWSER_NAME = m[3].replace(/\s/ig, '');

                if (BROWSER_NAME === 'OperaMobi') {
                    BROWSER_VERSION = m[6];
                } else {
                    BROWSER_VERSION = m[4];
                }

            } else if ($.browser.mozilla) {
                m = ua.match(/Mozilla\/[\d\.]+\s\(([^;]+);\s[^;\/]*;{0,1}[^;]*\)[;\s]*[^\s]+\s[^\s]+\sFennec\/([\d\.\w]+)/i);
                var n = m[1].split('/');
                OS = m[1];
                BROWSER_NAME = 'Fennec';
                BROWSER_VERSION = n[2];
            }

            if (isOrientation()) {
                if((ua.indexOf('Mobile') >= 0) || (ua.match(/(?:Mobi(?:le)*|Fennec)/i)) ){
    	            	SMARTPHONE = true;
       	        	} else {
        	        	TABLET = true;
           	     }
            } else {
                TABLET = true;
            }
        };
        
        var _doTV = function(){
            var m;
            WINDOWS = false;
            OS = 'TV';
            
            BROWSER_NAME = 'InettvBrowser';
        };
        
        var _doWin = function(){
            var m;
            WINDOWS = true;
            OS = 'windows';
            TOUCH = isTouch();
            
            if ($.browser.ie) {
                m = ua.match(/Mozilla\/[\d\.]+\s\(\w+;\sMSIE\s[\d\.]+;\s([^\d]+)\sOS\s([\d\.]+);\s.+IEMobile\/([\d\.]+)/i);
                /**
                 * m[1] = os name
                 * m[2] = os version
                 * m[3] = browser version
                 */
                OS = m[1];
                OS_VERSION = m[2];
                BROWSER_NAME = 'IEMobile';
                BROWSER_VERSION = m[3];
            }
            
            if (isOrientation() || ua.indexOf('Mobile') > -1) {
                SMARTPHONE = true;
            } else {
                TABLET = true;
            }
        };

        var _doApple = function() {
            var m;
            APPLE = true;
            OS = 'apple';
            TOUCH = isTouch();

            if (isOrientation()) {
                SMARTPHONE = true;
            }
            if(("standalone" in window.navigator) && !window.navigator.standalone){

                 if ($.browser.webkit) {
                    m = ua.match(/\((\w+); U;[\w\s]+? OS (\d_\d(?:_\d)*).*(?:Version\/([\d\.]+))*/i);
                    if(m){
                    	DEVICE_NAME = m[1];
                	    OS_VERSION = m[2].replace(/_/g, '.');
                    
                    	if(m[3]){
                      	  BROWSER_VERSION = m[3];
                   		}else{
                        	BROWSER_VERSION = $.browser.version;
                    	}
                    }
                    BROWSER_NAME = 'MobileSafari';
    				
                } else if ($.browser.opera) {
                    m = ua.match(/Opera\/9\.80 \(([^;]+);\s([^\/]+)\/([^\/]+)[^;]*;\s\w+;\s([^\)]*)\).*/i);
                    DEVICE_NAME = m[1];
                    BROWSER_NAME = m[2].replace(/\s/ig, '');
                    BROWSER_VERSION = m[3];
    
                }
            }else{
                m = ua.match(/\((\w+); U;[\w\s]+? OS (\d_\d(?:_\d)*).*/i);
                DEVICE_NAME = m[1];
                OS_VERSION = m[2].replace(/_/g, '.');
                BROWSER_VERSION = $.browser.version;
                BROWSER_NAME = 'AppMode';
            }


        };

        var publics = {
            init: function(options) {
                this.checkSmartphone.settings = $.extend({}, this.checkSmartphone.defaults, options);
                var settings = this.checkSmartphone.settings;
                var cn = [];
                OS = 'pc';

                if (!$.browser.agent) {
                    if (ua.indexOf('InettvBrowser') !== -1) {
                        _doTV();
                    } else if (ua.indexOf('Android') !== -1) {
                        _doAndroid();
                    } else if (ua.indexOf('Windows Phone') !== -1) {
                        _doWin();
                    } else if (ua.indexOf('iPhone') !== -1 || ua.indexOf('iPad') !== -1 || ua.indexOf('iPod') !== -1) {
                        _doApple();
                    }

                    $.extend($.browser, {
                        'agent': {
                            'os': OS,
                            'apple': APPLE,
                            'android': ANDROID,
                            'device': DEVICE_NAME,
                            'browser_name': BROWSER_NAME,
                            'browser_version': BROWSER_VERSION,
                            'os_version': parseFloat(OS_VERSION),
                            'smartphone': SMARTPHONE,
                            'tablet': TABLET,
                            'touch': TOUCH
                        }
                    });

                    $.each(settings, function(key, val) {
                        if (val !== true) {
                            return;
                        }
                        switch (key) {
                        case 'smartphone':
                            if ($.browser.agent.smartphone) cn.push('smartphone');
                            break;
                        case 'tablet':
                            if ($.browser.agent.tablet) cn.push('tablet');
                            break;
                        case 'touch':
                            if ($.browser.agent.touch) cn.push('touch');
                            break;
                        case 'os_version':
                            if ($.browser.agent.os_version) {
                                if ($.browser.agent.device === 'iPhone' || $.browser.agent.device === 'iPad') {
                                    cn.push($.browser.agent.device + String($.browser.agent.os_version).slice(0, 1));
                                }

                                cn.push('ov' + String($.browser.agent.os_version).replace(/\./g, '_'));
                            }
                            break;
                        case 'browser_version':
                            cn.push('bv' + String($.browser.agent.browser_version).replace(/\./g, '_'));
                            break;
                        default:
                            cn.push($.browser.agent[key]);
                            break;
                        }
                    });
                }

                return this.each(function() {
                    var $element = $(this),
                        element = this;
                    $element.addClass($.trim(cn.join(' ')));
                });
            }
        };

        $.extend({
            getAgent: function(type) {
                if (!$.browser.agent) return null;
                if (type !== 'all' && typeof type === 'string') {
                    return $.browser.agent[type];
                } else if (!type || type === 'all') {
                    var str = '';
                    var s = arguments[1] || ':';
                    var n = arguments[2] || '\r\n';
                    $.each($.browser.agent, function(key, val) {
                        str += key + s + val + n;
                    });
                    return str;
                }
            }
        });

        if (publics[method]) {
            return publics[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return publics.init.apply(this, arguments);
        } else {
            $.error(method + ' はcheckAgentプラグインに定義されていません');
        }
    };

    $.fn.checkSmartphone.defaults = {
        'os': true,
        'device': true,
        'browser_name': false,
        'browser_version': false,
        'os_version': false,
        'smartphone': false,
        'tablet': false,
        'touch': true
    };

    $.fn.checkSmartphone.settings = {};

})(jQuery);


$.anchor = function (val, skip) {
	var fn = arguments.callee;
	switch (typeof val) {
		// getter
		case "undefined":
			var ret = location.hash;
			if (!ret) {
				return null;
			}
			ret = ret.replace(/^#/, "");
			return $.browser.fx ? ret : decodeURIComponent(ret);
		// callback
		case "function":
			if (!fn.tid) {
				fn.hash = location.hash;
				(function rec() {
					if (!fn.skip && fn.hash !== location.hash) {
						fn.hash = location.hash;
						$(window).trigger("changeAnchor", $.anchor());
					}
					fn.tid = setTimeout(rec, 300);
				})();
			}
			return $(window).bind("changeAnchor", val);
		// setter
		default:
			if (skip) {
				fn.skip = true;
				location.hash = encodeURIComponent(val);
				fn.hash = location.hash;
				fn.skip = false;
			}
			else {
				location.hash = encodeURIComponent(val);
			}
			return;
	}
};

function preLoadImages() {
  for (var i = 0, I = arguments.length; i < I; ++i) {
    new Image().src = arguments[i];
  }
}
	
var currentZoom = 1;

	
$(function(){
	
	/*---------------------------------初期化----------------------------------*/
	
	// 基準ブラウザ以外では、画面準備を待たず表示させる
	
	var ua = navigator.userAgent;
	var hideBeforeDOMReady = false;
	var isAppleDevice =  ( /iPhone|iPad|iPod/.test( navigator.platform ) && ua.indexOf( "AppleWebKit" ) > -1 );
	var isAndroid = ua.indexOf('Android') > -1
	var isSonyPhoneMain = false;
	var isChrome = false;
	var isWebKit = false;
	var isPC = ua.indexOf('Android') == -1 && !isAppleDevice
	
	if(ua){
		isSonyPhoneMain = ua.indexOf("SonyEricssonSO-02D") >= 0; //SonyPhoneかどうか
		isChrome = (ua.indexOf('Chrome') >= 0) || (ua.indexOf('CriOS') >= 0);
		isWebKit = ua.indexOf('AppleWebKit') >= 0;
		
		if( isWebKit){
			hideBeforeDOMReady = true;
		}
	}
	
	if(hideBeforeDOMReady){
		
	} else { //alert('対象外ブラウザ')
		$('body').css('display','block');
	}
	
	//bodyにクラスを自動付加（Android SonyTablet touch）など
	$(document.body).checkSmartphone();	


    // page scrollerの設定
    virtualTop  = 1;
 	adjTraverser = 0;
    adjSpeed = .5;
	
	var landscapeWidth = 1280, portraitWidth = 720;
	var firstLoad = true;
	var isInvertedDevice = false; // 角度0がヨコ位置のデバイスかどうか（保留）
	var aspectRatio = 1;
	var orientationString = 'portrait';
	var isAppleDevice =  ( /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1 );
	var realWidth = 0, realHeight = 0;;
	var $viewport = $('meta[name="viewport"]');

	
	/* プリロード */
	// 2012.11.30-ISE
	// ファイルの格納されているフォルダ名がcontents、cover、searchのどれかの場合はトップページ以外なので、相対パスを変更する
	var lastFolderName = location.href.substring(location.href.lastIndexOf("/", location.href.lastIndexOf("/")-1)+1, location.href.lastIndexOf("/"));
	if(lastFolderName.toLowerCase() == "contents" || lastFolderName.toLowerCase() == "cover" || lastFolderName.toLowerCase() == "search"){
		preLoadImages("../common/img/icon_menu_howtouse.png", "../common/img/icon_menu_faq.png", "../common/img/icon_menu_contentslist.png", "../common/img/icon_menu_top.png", "../common/img/nav_arrow.png", "../common/img/button_search.png", "../common/img/form_search.png", "../common/img/list_keyword.png");
	}else{
		preLoadImages("common/img/icon_menu_howtouse.png", "common/img/icon_menu_faq.png", "common/img/icon_menu_contentslist.png", "common/img/icon_menu_top.png", "common/img/nav_arrow.png", "common/img/button_search.png", "common/img/form_search.png", "common/img/list_keyword.png");
	}
	
	
	
	/*---------------------------------VIEWPORT----------------------------------*/
	
	function setViewport(o){
		
		var delay = 0, ww = 0, wh = 0;		
				
		/*
			alert(
				'devicePixelRatio:'+window.devicePixelRatio +
				'\n outerWidth:'+window.outerWidth+
				'\n outerHeight:'+window.outerHeight+
				'\n innerWidth:'+window.innerWidth+
				'\n innerHeight:'+window.innerHeight+
				'\n SCREEN Width:'+screen.width +
				'\n SCREEN Height:'+screen.height +
				'\n scrollWidth:'+document.body.scrollWidth + 
				'\n Window Width:'+$(window).width()
			);
			*/
			
			//ズームの設定
			
			if( isAndroid ){
				//Android
				ww = window.outerWidth; 
				wh = window.outerHeight;
				
			} else {
				//iOS
				ww = screen.width;
				wh = screen.height;
				delay = 1000;
			}

			if(firstLoad){
				
				if(wh > ww){
					
					aspectRatio = ww/wh;
					realWidth = ww;
					realHeight = wh;
					
				} else {
					
					isInvertedDevice = true;
					aspectRatio = wh/ww;
					realWidth = wh;
					realHeight = ww;
					
				}
				
			}	
		
		if(isAndroid){

			//Android
			
			if(o == 'portrait'){
				
				if(isChrome){
					// Chrome
					$viewport.attr('content', 'width=device-width, minimum-scale=1.0,maximum-scale=1.0,user-scalable=yes') ;
				
					setTimeout(function(){
						$viewport.attr('content', 'width=device-width, minimum-scale=1.0,maximum-scale=3.0,user-scalable=yes') ;
					},50)
				} else {
					// 標準ブラウザ 
					$viewport.attr('content', 'width=device-width, minimum-scale=1.0,maximum-scale=3.0,user-scalable=yes') ;
				}	
			
			} else if(o == 'landscape'){
				
				if(isChrome){
					// Chrome
					$viewport.attr('content', 'width=device-width, minimum-scale=1.0,maximum-scale=1.0,user-scalable=yes') ;
				
					setTimeout(function(){
						$viewport.attr('content', 'width=device-width, minimum-scale=1.0,maximum-scale=3.0,user-scalable=yes') ;
					},50)
				} else {
					// 標準ブラウザ (特になにもしない)
					
				}	
			
			}
		
		} else if( isAppleDevice ){
			
			//Apple
			
			//$viewport.attr('content', 'width=device-width, minimum-scale=1,maximum-scale=4,user-scalable=yes');
						
			if(o == 'portrait'){
				
				$viewport.attr('content', 'width=320, minimum-scale=1, maximum-scale=3,user-scalable=yes');
				
			} else if(o == 'landscape'){
				
				//横回転する直前でcheckTilt()のviewport設定になる（バグ回避）
				$viewport.attr('content', 'width=device-height, minimum-scale=1, maximum-scale=1,user-scalable=no');
				
				setTimeout(function(){
					$viewport.attr('content', 'width=device-height, minimum-scale=1, maximum-scale=3, user-scalable=yes');
				},50)
			}
			
		} else {
	
			$viewport.attr('content', 'width=device-width, height=device-height, minimum-scale=0.3, maximum-scale=3.0, user-scalable=yes');
		}
		

		
		setTimeout(function(){
			
			
			if(orientationString == 'portrait'){

					currentZoom = realWidth/720;
					
			} else if(orientationString == 'landscape'){
				
					currentZoom = ( realWidth/720 ); // * aspectRatio;
			
			}

			if(isAppleDevice){ // TODO : Android Chromeではここの計算いらない。iOSでは必要。古いAndroid機種で要検証
				
				$("body").css("zoom", currentZoom );
				
			} else {

				//$("body").css("zoom", currentZoom );
			
			}

			if(firstLoad){
				
				//ロード中のものを非表示にし、全て完了後に表示
				$('body').css('display','block');
				
				
				//ハッシュつきURLの場合、自動でページ内アンカーへ
				if(location.hash){
					
					var anchor = '#'+$.anchor();
					
					if($(anchor).length){
						if($.browser.safari) { 
							bodyelem = $("body") 
						} else {
							bodyelem = $("html,body")
						}
						setTimeout(function(){
							bodyelem.scrollTop( ($(anchor).offset().top )*currentZoom*.5 );
						},delay)
						
					}
					
				} else {
					if($(window).scrollTop() < 100 ){
						scrollTo(0,1);
					}
		
				}
				
				firstLoad = false;
			}	
		},100)
		
		
		$('.impact a').removeClass('touchover');
	}
	
	var enabled = true;
	
	function checkTilt( e ){
		
		if(isAppleDevice){
		// iOSでのズームのバグを回避 ( 縦から横のとき、拡大される )
		
		var aig = e.accelerationIncludingGravity;
		var x = Math.abs( aig.x );
		var y = Math.abs( aig.y );
		var z = Math.abs( aig.z );
		var o = window.orientation;
		
		var facingUp = -1;
		if (aig.z > 0) {
			facingUp = +1;
		}


		var tiltLR = Math.round(((aig.x) / 9.81) * -90);
		var tiltFB = Math.round(((aig.y + 9.81) / 9.81) * 90 * facingUp);
		
		
		// 表示が崩れるので先にフォームだけブラー
        if( (Math.abs(o) === 90) && (((-55 < tiltFB) && (tiltFB < 55)) || (tiltFB < -115)) ){
        	$('.search-form').blur();
        }
        if( (!o || o === 180) && ( (-30 > tiltLR)  || (tiltLR > 30)) ){
        	$('.search-form').blur();
        }
        
         if( (!o || o === 180) && ( (-30 > tiltLR)  || (tiltLR > 30)) ){
			if( enabled ){
				//alert('たて > よこ')
				
				$viewport.attr('content', 'width=device-width, minimum-scale=1, maximum-scale=1, user-scalable=no');
				
				enabled = false;
			}        	
        } else  if( (Math.abs(o) === 90) && (((-35 < tiltFB) && (tiltFB < 35)) || (tiltFB < -135)) ){
			if( enabled ){
				//alert('よこ > たて')
				
				//$viewport.attr('content', 'width=320, minimum-scale=1, maximum-scale=1, user-scalable=no');
				//$('body').css('width', screen.width );
				
				//enabled = false;	//ヨコ > タテ > ヨコ で拡大されてしまうのを防ぐ
			}        	
        } else if ( !enabled ){
			//$('body').css('width', '100%' );
			$viewport.attr('content', 'width=device-width, minimum-scale=1, maximum-scale=3, user-scalable=yes');
			enabled = true;
        }
        }
		

    }
    
	/*---------------------------------オリエンテーション----------------------------------*/
	
	
	var lastOrientation = 'undefined';//window.orientation;


	
	setTimeout(switchOrientation,100);	//オリエンテーションのクラスを付加（portrait or landscape）
		
	$(window).bind('orientationchange', switchOrientation);
	window.addEventListener('devicemotion', checkTilt, false);
	
	function switchOrientation(e){
		
		var suggestionStatus = $('#search-suggestions').css('display');
		$('#search-suggestions').css('display','none');
		
		var orientation = window.orientation;
		
		if(isInvertedDevice){
		
			//横位置がデフォルトのデバイス
			if(orientation == 0 || orientation == 180){
				//ヨコ
				orientationString = 'landscape';
				$("body").addClass("landscape");
				$("body").removeClass("portrait");
			} else {
				//タテ
				orientationString = 'portrait';
				$("body").addClass("portrait");
				$("body").removeClass("landscape");
			}
		
		} else {
			 
			//縦位置がデフォルトのデバイス
			if(Math.abs(orientation) == 0 || Math.abs(orientation) == 180){
				//タテ
				orientationString = 'portrait';
				$("body").addClass("portrait");
				$("body").removeClass("landscape");
				
			}else{
				//ヨコ
				orientationString = 'landscape';
				$("body").addClass("landscape");
				$("body").removeClass("portrait");
				
			}
			
		}
		
		setTimeout(setViewport(orientationString),500)
		
		
		
		
		if(orientation != lastOrientation){ 
			afterOrientationChanged();
		}
		
		lastOrientation = orientation;
		
		
	}
	//ワンテンポおくらせる
	function afterOrientationChanged(){
		setTimeout(function(){
			
			/*メニューエリアの位置設定*/
			$('.menu-area').css('top',$('header')[0].clientHeight + 'px')
			
		},500);
	}
	
	/*---------------------------------検索サジェスト----------------------------------*/
	
	var activeButton = '';
	
    var defaultSearchFormWord;
    
    if($('.search-form')){
    	if($('.search-form')[0]){
    		defaultSearchFormWord = $('.search-form')[0].value;
    	}
    }
    
    $('.menu-area .search-form').bind("focus", onFormFocus);
    $('.menu-area .search-form').bind("blur", onFormBlur );
    //$('.menu-area .search-form').bind("keydown", onFormChange );
    
    $('.foot .search-form').bind("focus", onFormFocus);
    $('.foot .search-form').bind("blur", onFormBlur );
   
	if(!isPC){ 	// モバイル＆タブレット
	
		$("#button-menu").bind("touchstart", touchStart_A);
    	$("#button-search").bind("touchstart", touchStart_B);
		$(".top .menu-area.category li a").bind("click", touchStart_anchor);
		$(".search-button").bind("touchstart", touchStart_Go);
		$(".search-button").bind("touchend", touchEnd_Go);
	
	} else {	// PC
	
		$("#button-menu").bind("click", touchStart_A);
    	$("#button-search").bind("click", touchStart_B);
		$(".top .menu-area.category li a").bind("click", touchStart_anchor);
		//$(".search-button").bind("click", touchStart_Go);
		$(".search-button").bind("click", touchEnd_Go);
	}

	
	var dropdown_A = $(".menu-area.category");
	var dropdown_B = $(".menu-area.search");
	
	
	function onFormFocus (e) {
		
		if($(this).attr('class').indexOf('foot') == -1){
			//ドロップダウンメニューのinput
			
			androidBugProvision();
		
		} else {
			//フッターのinput
			
			
		}
		$(this).addClass('active');
		
		if($(this).val() == defaultSearchFormWord){
			$(this).val('');
		}
		
		
	}
	
	function onFormBlur(){
	
		if($(this).attr('class').indexOf('foot') == -1){
			//ドロップダウンメニューのinput
			
			//androidBugProvisionOff();
			
		}
		
		//フォームの文字をデフォルトに
		if($(this).val() == ''){
			$(this).val(defaultSearchFormWord);
			$(this).removeClass('active');
		}
		
		
	}
	function onFormChange (e) {
		
	}
	
	function touchStart_A (e) {
		
		blurAllForms();
		touchCount = 0;
		
		if(activeButton != 'A'){
			
			if(activeButton == 'B'){	
				//右が出ている状態
				dropdown_B.slideUp("normal", function(){
					androidBugProvisionOff();
  					dropdown_A.slideDown("normal");
  				});
  			} else {
  				//どちらも出ていない状態
  				androidBugProvisionOff();
  				dropdown_A.slideDown("normal");	
  			}
  			activeButton = 'A';
  			setTimeout(function(){
  				$('.menu a#button-menu').addClass('active');
				$('.menu a#button-search').removeClass('active');
			},200);
			
		} else {
			//左が出ている状態
			activeButton = '';
			androidBugProvisionOff()
			blurAllForms();
			dropdown_A.slideUp("slow",checkBoth);
		}
		
  		return false;
  		
	}
	
	function touchStart_B (e) {

    	blurAllForms();
    	
    	if(activeButton != 'B'){
			
			if(activeButton == 'A'){	
				//左が出ている状態
				dropdown_A.slideUp("normal", function(){
  					androidBugProvision();
  					dropdown_B.slideDown("normal");
  				});
  			} else {
  				//どちらも出ていない状態
  				androidBugProvision();
  				dropdown_B.slideDown("normal");	
  			}
  			activeButton = 'B';
  			setTimeout(function(){
  				$('.menu a#button-menu').removeClass('active');
				$('.menu a#button-search').addClass('active');
			},200);
  			
		} else {
			//右が出ている状態
			activeButton = '';
			blurAllForms();
		
			dropdown_B.slideUp("slow",function(){
				androidBugProvisionOff();
				checkBoth();
			});
		}
		
		
  		return false;
  		
	}
	
	function touchStart_Go (e) {
		
		$(this).addClass('active');
  		
	}
	
	function touchEnd_Go (e) {
		
		$(this).removeClass('active');
  		
	}
	
	
	function touchStart_anchor (e) {
		
		
		dropdown_A.slideUp("slow",checkBoth);
		
		$('.menu a#button-menu').removeClass('active');
		$('.menu a#button-search').removeClass('active');
		activeButton = '';
  		
	}
	
	function androidBugProvisionOff(){
		
		if(isAndroid){
			
			$('a').css("-webkit-tap-highlight-color","rgba(0, 150, 255, .4)");
    		
			$('.impact a').css("-webkit-transform","translate3d(0, 0, 0)");
    		
		}
		
	}
	
	function androidBugProvision(){
		
		if(isAndroid){
			
			$('.impact a').css("-webkit-transform","none");
			
			$('a').css({
				"-webkit-tap-highlight-color":"rgba(0, 0, 0, 0)"
			});
			
			$('.keyword a').css("-webkit-tap-highlight-color","rgba(0, 150, 255, .4)");
		}
		
	}
	
	function showTransparentScreen(){
		
		if(!$('#ScreenOverlay').length){
			$(".container").prepend('<div id="ScreenOverlay"></div>');
			$("#ScreenOverlay").bind("touchstart click", touchStartScreenOverlay);
		}
	}
	
	function touchStartScreenOverlay (e) {
		if(dropdown_A.css('display') != 'none'){
			dropdown_A.slideToggle('fast');
		}
		if(dropdown_B.css('display') != 'none'){
			dropdown_B.slideToggle('fast');
		}
		
		$("#ScreenOverlay").remove()
		blurAllForms()
		onFormBlur()
	}
	
	function checkBoth(){
		
		if ( activeButton == '' ){
			
			//$("#ScreenOverlay").remove();

			$('.menu a#button-menu').removeClass('active');
			$('.menu a#button-search').removeClass('active');
			
		} 
	}
	
	function blurAllForms(){
		if($('.search-form')){
			
			var forms = $('.search-form');
			
			if(forms.length){
			
				for(var i =0 ;  i < forms.length ; i++){
				
					forms[i].blur();
					
				}
			}
		}	
	}
	
	
});
