/* ===================================================================
JS information

 script info :デフォルト
 
 *Last Modified: 2011-10-06
=================================================================== */


// ----------------------------------------------------
// スムーススクロール
// ----------------------------------------------------
jQuery.fn.extend({
	scrollTo : function(speed, easing) {
		if(!$(this)[0].hash || $(this)[0].hash == "#") {
			return false;
		}
		return this.each(function() {
			if( $(this)[0].hash == "#wrapper" ) {
				var targetOffset = $($(this)[0].hash).offset().top;
				$('html,body').animate({scrollTop: targetOffset}, speed, easing);
			} else {
				var targetOffset = $($(this)[0].hash).offset().top - 70;
				$('html,body').animate({scrollTop: targetOffset}, speed, easing);
			}
		});
	}
});


// ----------------------------------------------------
// facebookボタン
// ----------------------------------------------------
function fbl(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
	if (d.getElementById(id)) {return;}
	js = d.createElement(s); js.id = id;
	js.src = "//connect.facebook.net/ja_JP/all.js#xfbml=1";
	fjs.parentNode.insertBefore(js, fjs);
}


$(function() {


	// ----------------------------------------------------
	// 特徴 スライダー
	// ----------------------------------------------------
	$("#slider").wslide({
		width: 610,
		height: 401,
		horiz: false
	});


	// ----------------------------------------------------
	// スムーススクロール 実行
	// ----------------------------------------------------
	$('a[href*=#]').not("#feature a").click(function() {
		$(this).scrollTo(800, "easeOutQuad");
		return false;
	});
	$("#feature a, #previousBtn, #nextBtn").click(function() {
		var featureOffset = $("#feature").offset().top - 70;
		$('html,body').animate({scrollTop: featureOffset}, 300, "easeOutQuad");
		return false;
	});


	// ----------------------------------------------------
	// トップアニメ
	// ----------------------------------------------------
	if ($.browser.msie && $.browser.version < 7) {
		$("#indexMain hgroup h2 img").css({display:"block"});
		$("#indexMain .cir img").css({display:"block", left:0, top:0});
		$("#indexMain ul li").css({display:"block"});
		$("#indexMain .txt").css({left:"11px"});
		$("#indexMain hgroup h1").css({display:"block"});
						// ソーシャルボタンの追加
						fbl(document, 'script', 'facebook-jssdk');
	} else {
		$("#indexMain .txt").css({opacity:0});
		$("#indexMain .cir img").css({display:"block", opacity:0, width:"80px", height:"80px"});
		$("#indexMain ul li").css({display:"block"});
		$(window).bind("load", function() {
			var winWidth = $(window).width();
			$("#indexMain hgroup h2 img").delay(300).fadeIn(400);
			$("#indexMain hgroup h1").delay(700).animate({opacity:"1", width:"show"}, 300, function() {
				$("#indexMain .point01 .cir img").animate({opacity:1, width:"100px", height:"100px", left:0, top:0}, 300, "easeOutBack", function() {
					$("#indexMain .point01 .txt").animate({opacity:1, left:"11px"}, 500, "easeOutBack");
				});
				$("#indexMain .point02 .cir img").animate({opacity:1, width:"100px", height:"100px", left:0, top:0}, 300, "easeOutBack", function() {
					$("#indexMain .point02 .txt").animate({opacity:1, left:"11px"}, 500, "easeOutBack");
				});
				$("#indexMain .point03 .cir img").animate({opacity:1, width:"100px", height:"100px", left:0, top:0}, 300, "easeOutBack", function() {
					$("#indexMain .point03 .txt").animate({opacity:1, left:"11px"}, 500, "easeOutBack", function() {
						// ソーシャルボタンの追加
						fbl(document, 'script', 'facebook-jssdk');
						var plusOneScript = document.createElement("script");
						plusOneScript.setAttribute("src", "https://apis.google.com/js/plusone.js");
						$("head").append(plusOneScript);				
					});
				});
			});
		});
	};


	// ----------------------------------------------------
	// トップヘのリンク
	// ----------------------------------------------------
	function btnTop() {
		$(".btnPageTop").each(function() {
			var el = $(this),
			scrollTop = $(window).scrollTop(),
			winWidth = $(window).width();
			if ((scrollTop > 100) ) {
				if(1065 < winWidth) {
					$(this).show();
				};
			} else {
				$(this).hide();
			};
		});
	};
	$(window).scroll(btnTop).trigger("scroll");

	$(window).bind('resize', function() {
		if (resizeTimer) clearTimeout(resizeTimer);
			resizeTimer = setTimeout(doSomething, 10);
	});
	var resizeTimer = null;
	function doSomething() {
		winWidth = $(window).width();
		scrollTop = $(window).scrollTop()
		if (1065 > winWidth) {
			$(".btnPageTop").hide();
		} else {
			if(scrollTop>100) {
				$(".btnPageTop").show();
			}
		};
	};


	// ----------------------------------------------------
	// グローバルナビ
	// ----------------------------------------------------
	
	if(!($.os.name == 'iphone'||$.os.name == 'ipod'||$.os.name == 'ipad')) {
		// 固定
		var nav = $('nav#global ul');
		function gnvFixed() {
			if($(window).scrollTop() > 60) {
				nav.addClass('fixed');
			} else {
				nav.removeClass('fixed');
			};
		};
		$(window).scroll(function () {
			gnvFixed();
		});
		gnvFixed();
	};


	// ----------------------------------------------------
	// サービスバナー
	// ----------------------------------------------------
	$("#service li").hover( function() {
		$(this).find("img").css({opacity:"0.6"});
	}, function() {
		$(this).find("img").css({opacity:"1"});
	}).click( function() {
		var linkUrl = $(this).find("a").attr("href");
		window.open(linkUrl);
		return false;
	});


	// ----------------------------------------------------
	// ポップアップ
	// ----------------------------------------------------
	$(".external").click( function() {
		var linkUrl = $(this).attr("href");
		window.open(linkUrl, "tool","width=800,height=650,resizable=yes,scrollbars=yes");
		return false;
	});


	// ----------------------------------------------------
	// ロールオーバー
	// ----------------------------------------------------
	var imgClass = ".roll" // ロールオーバー画像切替の対象セレクター
	var hovername = "_on" // オーバー画像のファイル名末尾
	$(imgClass).not('[src*="'+ hovername +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + hovername + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
			img.hover(function() {
			img.attr('src', src_on);
		},
		function() {
			img.attr('src', src);
		});
	});


	// ----------------------------------------------------
	// お問い合わせの表示
	// ----------------------------------------------------
	$("#contact").hover( function() {
		$(this).find(".inner").show();
	}, function() {
		$(this).find(".inner").hide();
	});


	// ----------------------------------------------------
	// フォーム リデザイン（use ./jqtransform.js）
	// ----------------------------------------------------
	$("form").jqTransform();
	$("form p.btn").click( function() {
		$(this).parent().submit();
	});
	

	// ----------------------------------------------------
	// ie6向け処理
	// ----------------------------------------------------
	if ($.browser.msie && $.browser.version < 7) {

        $('#bg01, #bg02, .btnPageTop').remove();

		// 透過PNG
		DD_belatedPNG.fix('img, #contact .inner');

	};

	
	// ----------------------------------------------------
	// 角丸処理
	// ----------------------------------------------------
	if (!($.support.borderRadius)) {
		$("#download h3 span").corner();
	}


	// ----------------------------------------------------
	// ios向け処理
	// ----------------------------------------------------
	if($.os.name == 'iphone'||$.os.name == 'ipod'||$.os.name == 'ipad') {
		$("#bg01, #bg02").css({position:"absolute"});
		$(window).bind('load', function() {
			var wrapperH = $("footer").offset().top;
			$("#bg02").css({top:wrapperH-240, bottom:""});
		});
	};


});



