/*--------------------------------------------------------------------------*
*
*	common js
*
*	(C) Remixpoint, Inc. All Rights Reserved.
*	
*	2009 Remixpoint, Inc.
*	http://www.remixpoint.co.jp
*
*	Last Modified: 2010-07-29
*	Last Editor: Toshiyuki Hara
*
*	jQuery 1.4.2
/*--------------------------------------------------------------------------*/
(function($){

	$(function(){


		var ua = window.navigator.userAgent.toLowerCase();
		var av = window.navigator.appVersion.toLowerCase();
		var ie6fix = ua.indexOf("msie") > -1 && av.indexOf("msie 6.0") > -1;
		var ie7fix = ua.indexOf("msie") > -1 && av.indexOf("msie 6.0") > -1 || av.indexOf("msie 7.0") > -1;

		//headerMenu
		var nav = $("li:has(ul)" , "#nav-global");

		if(ie6fix){
		
			nav.hover(function(){
			
				$("ul.mousePoint" , nav)
					.css({"display":"none"})
					.removeClass("mousePoint");
					
				$("ul:first",this).css({"display":"block"});
				
			}, function(){
			
				$("ul:first",this).addClass("mousePoint");
				setTimeout(function(){
					$("ul.mousePoint" , nav).css({"display":"none"});
					$(this).removeClass("mousePoint");
				},1000);

			});
		
		} else {
		
			nav.hover(function(){
				$("ul.mousePoint" , nav).slideUp("fast", function(){
					$(this).removeClass("mousePoint");
				});
				$("ul:first",this).slideDown("fast");

			}, function(){
			
				$("ul:first",this).addClass("mousePoint");
				setTimeout(function(){
					$("ul.mousePoint" , nav).slideUp("fast", function(){
						$("ul.mousePoint" , nav).css({"display":"none"});
						$(this).removeClass("mousePoint");
					});
				},1000);

			});
		
		}


		//cssHelper（ie6、ie7で適用させる）
		if(ie7fix){
		
			$(".inner-section > div:last-child").addClass("lastChild");
			$(".corptable p:last-child").addClass("lastChild");
		
		}

		//pageScroller
		$.fn.pageScroller = function(options) {
		
			var c = $.extend({
				sclpos: 0
			},options);
		
			$(this).click(function() {
					if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
						var target = $(this.hash);
						target = target.length && target;
						if (target.length) {
							var sclpos = c.sclpos;
							var scldurat = 600;
							var targetOffset = $(this.hash).offset().top - sclpos;
							$('html,body')
								.animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
							return false;
						}
					}
				});
		}

		$("a[href*=#]",".anchor").pageScroller({
			sclpos: 0
		});



		//別ウィンドウで開く
		$("a[rel='blank']").click(function(){
			this.target = "_blank";
		});

		//印刷設定ダイアログを表示
		$("#btn-prt a").click(function(){
			/* print() が使えるブラウザかどうかを判断 */
			if (navigator.userAgent.match(/msie (\d)/i))
				v = (eval(RegExp.$1) >= 5) ? 1 : 0;
			else if (self.innerWidth)
				v = (eval(navigator.appVersion.charAt(0)) >= 4) ? 1 : 0;
			else v = 0;
			
			/* print() が使えるブラウザなら印刷を実行 */
			if (v) self.print();
			else alert("お使いのブラウザではこの機能は利用できません");
		});

		//タブメニュー
		$("#box-results , #btn-model")
			.css({
				"display":"none"
			});

		$(".tabBox > h4 > a , #tab-subMenu > li > a").click(function(){
		
			var tab = $(this)
						.parent()
						.attr("id")
						.replace(/^.*-(.*)$/,"$1");

			$("#tab-"+ tab +" > a")
				.addClass("active");
			
			$(".tabBox > h4:not([id$='"+ tab +"']) > a")
				.removeClass("active");

			if(ie6fix){
			
				$("#box-"+ tab +" , #tab-subMenu > li:not([id$='"+ tab +"'])")
					.css({
						"display":"block"
					});
				
				$(".tabBox > div:not([id$='"+ tab +"']) , #btn-"+ tab +"")
					.css({
						"display":"none"
					});

			} else {
			
				$("#box-"+ tab +" , #tab-subMenu > li:not([id$='"+ tab +"'])")
					.fadeIn(function(){
					
						$(".tabBox > div:not([id$='"+ tab +"']) , #btn-"+ tab +"")
						.fadeOut();
					
					});
				
				
			
			}

		});


		if(ie6fix){
		} else {
			//マウスオーバーアニメーション
			$.fn.fadeHover = function(options) {
		
				var c = $.extend({
					speed: 400,
					opa: 0.5
				},options);
				

				$(this).live("mouseover",function(){
				
					$(this).stop().animate({
						"opacity": c.opa
						}, c.speed);
				
				}).live("mouseout",function(){
				
					$(this).stop().animate({
						"opacity": 1
						}, c.speed , function(){
							$(this).removeAttr("style");
						});
				
				}).live("mousedown",function(){
				
					$(this).css({
							"opacity":"1"
						});
				
				});
			
			}

/*
			$("#nav-local > li > a[class!='active']").fadeHover({
				speed: 400,
				opa: 0
			});

			$("#nav-global a[class!='active']").fadeHover({
				speed: 400,
				opa: 0
			});
*/

			$(".fadeHover").fadeHover({
				speed: 400,
				opa: 0
			});
	
			$(".fadeHoverSet a[class!='active']").fadeHover({
				speed: 400,
				opa: 0
			});

		}


		//fontSize
		var target = $("#header");
		var fontStyle = $("#fontStyle");

		if(target.find("#fontChanger").length == 0) {

			var smlBtn = $('<a />')
							.attr("id","btn-smallFont")
							.append('<span>標準</span>');
			var lrgBtn = $('<a />')
							.attr("id","btn-largeFont")
							.append('<span>大</span>');
			$("<dl />")
				.appendTo(target)
				.attr("id","fontChanger")
				.append("<dt />","<dd />")
				.find("dd")
				.append(smlBtn,lrgBtn);
		}

		var fSize = $.cookie("fSize");
		var cssPath = fontStyle.attr("href").replace(/^(.*\/).*Font.css$/, "$1");

		if(fSize != null){
		
			$("#btn-"+fSize+"").css({
				"display":"none"
			});
			fontStyle.attr("href", cssPath+fSize+".css");

		} else if(fSize == null) {
			$("#btn-smallFont").css({
				"display":"none"
			});
			fontStyle.attr("href", cssPath+"smallFont.css");
		}

		$("dd > a","#fontChanger").click(function(){
			var chgId = $(this).attr("id").replace(/^btn-(.*Font)$/, "$1");
			$(this)
				.css({
					"display":"none"
				});
			$("dd > a[id!=btn-"+chgId+"]","dl#fontChanger")
				.css({
					"display":"block"
				});

			$("#container")
				.css({
					"transition":"all 0.3s ease-in-out",
					"-moz-transition":"all 0.3s ease-in-out",
					"-webkit-transition":"all 0.3s ease-in-out"
				});
			fontStyle.attr("href", cssPath+chgId+".css");
			$.cookie("fSize",chgId, { expires: 30,path:'/' });
		});


		//IRのページ専用
		if($("#section-ir").length){
		
			//「採用に関するお問い合わせ」へのリンクを追加する
			var a = $("dd > ul > li" , "#btn-footRecruit").length;
			
			if(a == 3){
				$("dd > ul" , "#btn-footRecruit").append("<li><a href='https://www.remixpoint.co.jp/contact/recruit-info.html'>採用に関するお問い合わせ</a></li>");
			}
			
			// フッタのIR用リンクを修正
			$("a" , "#btn-footIr").each(
				function(){
					var path = $(this).attr("href").replace(/^(\.\.\/ir|\.\.\/\.\.\/ir)(.*html)$/, "http://ir.remixpoint.co.jp$2");
					$(this).attr("href",path);
				}
			);
		
		}


	});

})(jQuery);
