/*
 * 
 * common/base.js
 * 
 */

//ブラウザ判別
var browser = '';
if(!jQuery.support.checkOn && jQuery.support.checkClone){
	//document.write('あなたがお使いのブラウザはchromeもしくはsafariっぽいです');
	browser = 'webkit';
}else if(jQuery.support.checkOn && jQuery.support.noCloneEvent && window.globalStorage){
	//document.write('あなたがお使いのブラウザはFirefoxっぽいです');
	browser = 'mozilla';
}else if(jQuery.support.checkOn && jQuery.support.noCloneEvente && !window.globalStorage){
	//document.write('あなたがお使いのブラウザはOperaっぽいです');
	browser = 'opera';
}else if(!jQuery.support.noCloneEvent && jQuery.support.opacity){
	//document.write('あなたがお使いのブラウザはIE9っぽいです');
	browser = 'ie9';
}else if(!jQuery.support.opacity){
    if(!jQuery.support.style){
        if (typeof document.documentElement.style.maxHeight != "undefined") {
        	//document.write('あなたがお使いのブラウザはIE7っぽいです');
			browser = 'ieOld';
        } else {
        	//document.write('あなたがお使いのブラウザはIE6っぽいです');
			browser = 'ieOld';
        }
    }else{
    	//document.write('あなたがお使いのブラウザはIE8っぽいです');
		browser = 'ieOld';
    }
}else{
	//document.write('ごめんなさい、あなたのブラウザを特定できませんでした');
	browser = false;
}


//ブラウザサイズ幅取得
function getBrowserWidth() {
        if ( window.innerWidth ) {
                return window.innerWidth;
        }
        else if ( document.documentElement && document.documentElement.clientWidth != 0 ) {
                return document.documentElement.clientWidth;
        }
        else if ( document.body ) {
                return document.body.clientWidth;
        }
        return 0;
}

//ブラウザサイズ高さ取得
function getBrowserHeight() {
        if ( window.innerHeight ) {
                return window.innerHeight;
        }
        else if ( document.documentElement && document.documentElement.clientHeight != 0 ) {
                return document.documentElement.clientHeight;
        }
        else if ( document.body ) {
                return document.body.clientHeight;
        }
        return 0;
}

// $function--------------------------------//
$(function(){

	//ブラウザ幅表示
	//alert(getBrowserWidth());

	//windowリサイズに更新
	$(window).resize(function(){
	  //  location.href='http://spiraledge.jp/';
	});

	//slCont初期位置
	$('#slCont').css('top',getBrowserHeight()+1000);

	//menuホバー処理(li)
	$("ul#menu li").hover(
		function(){
			$(this).animate({backgroundColor:'#292929',opacity:0.5},0);
		},
		function(){
			$(this).animate({backgroundColor:'#fff',opacity:1},0,function(){
				$(this).css('background-color','transparent');
			});		
		}
	);

	//menuクリック処理
	var rotated = false;
	$("ul#menu a, a[rel='pa']").click(function(){
		$(this).blur();
		
		var tgtPage = $(this).attr('href');
		
		if(!rotated) {
			$('canvas#bgMotion').hide();
			$('div#bgMotion').hide();
			$('div#subLayer').css('visibility','visible');
			
			//ブラウザサイズによるレイアウト調整
			var pWidth = getBrowserWidth();
			if (pWidth<=1024) {
				
				//alert('1024');
				
				$('ul#menu').animate({left: '-280px'}, 'fast');
				$('ul#menu').css('width',getBrowserWidth() + 280);
				$('div#subLayer').css('left','270px');
				
			} else if(pWidth>1024 && pWidth<=1280) {
				
				//alert('1280');
				
				if (browser != 'ieOld') {
					$('ul#menu').animate({top:'280px',left: '-150px'}, 'fast');
					$('ul#menu').rotate({angle: 359,animateTo: 45});
					$('div#subLayer').css('left','530px');
				} else {
					$('ul#menu').animate({left: '-150px'}, 'fast');
					$('div#subLayer').css('left','350px');
				}
				
				$('ul#menu').css('width',getBrowserWidth() + 200);
				
							
			} else if(pWidth>1280 && pWidth<=1400) {
				
				//alert('1400');
				
				if (browser != 'ieOld') {
					$('ul#menu').animate({top:'330px',left: '-150px'}, 'fast');
					$('ul#menu').rotate({angle: 359,animateTo: 45});
					$('div#subLayer').css('left','600px');	
				} else {
					$('ul#menu').animate({left: '-150px'}, 'fast');
					$('div#subLayer').css('left','410px');
				}
				
				$('ul#menu').css('width',getBrowserWidth() + 200);
				
			} else if(pWidth>1400 && pWidth<=1600) {
				
				//alert('1600');
				
				if (browser != 'ieOld') {
					$('ul#menu').animate({top:'420px',left: '-170px'}, 'fast');
					$('ul#menu').rotate({angle: 359,animateTo: 45});
					$('ul#menu').css('width',getBrowserWidth() + 200);
				} else {
					$('ul#menu').rotate({angle: 359,animateTo: 45});
				}
				
			} else if(pWidth>1600 && pWidth<=1680) {
				
				//alert('1680');
				
				if (browser != 'ieOld') {
					$('ul#menu').animate({top: '440px',left: '-190px'}, 'fast');
					$('ul#menu').rotate({angle:359, animateTo:45});
					$('ul#menu').css('width',getBrowserWidth() + 200);
				} else {
					$('ul#menu').rotate({angle: 359,animateTo: 45});
				}
				
			} else if(pWidth>1680 && pWidth<=1920) {
				
				//alert('1920');
							
				if (browser != 'ieOld') {
					$('ul#menu').animate({top:'520px',left: '-230px'}, 'fast');
					$('ul#menu').rotate({angle: 359,animateTo: 45});
					$('ul#menu').css('width',getBrowserWidth() + 200);
				} else {
					$('ul#menu').rotate({angle: 359,animateTo: 45});
				}
								
			} else {
				
				//alert('other');
				
				if (browser != 'ieOld') {
					$('ul#menu').animate({top: '380px',left: '-150px'}, 'fast');
					$('ul#menu').rotate({angle: 359,animateTo: 45});
				} else {
					$('ul#menu').rotate({angle: 359,animateTo: 45});
				}
				
			}
			
			rotated = true;
		}
		
		//コンテンツ表示
		var tpPos = $(tgtPage).offset().top - 20;
		$($.browser.opera ? document.compatMode == 'BackCompat' ? 'body' : 'html' :'html,body').animate({scrollTop:tpPos});

		
		return false;
	});
		
	
	//メールフォーム
	
	//メール書式チェック
	function chkRegEmail(str){
		var Seiki=/[!#-9A-~]+@+[a-z0-9]+.+[^.]$/i;
		if(str!=""){
			if(str.match(Seiki)){
				//alert(str.match(Seiki)+"\n\nメールアドレスの形式は正しいです");
				return true;
			}else{
				//alert("メールアドレスの形式が不正です");
				return false;
			}
		}else{
			/* 何も入力されていない場合はアラート表示 */
			alert("メールアドレスを入力してください");
			return false;
		}
	}
	
	$('#sendBtn').click(function(){
		$(this).blur();
		var name = $('input[name="お名前"]').val();
		var mail = $('input[name="email"]').val();
		var ask = $('textarea[name="お問合せ内容"]').val();
		
		if(!name || !mail || !ask) {
			$('dd#error').text('【入力エラー】　必須項目が未入力です。（※）欄は入力必須項目となります。');
			return false;
		} else if (name && mail && ask) {
			if(!chkRegEmail(mail)) {
				$('dd#error').text('【入力エラー】　メールアドレスの書式に誤りがございます。');
				return false;
			}
		}
		
	});
	


// $function-------------------------------- end //
});


















