(function($)
{
	//blockLink
	$.fn.blockLink = function(){
		$(this).css({"cursor":"pointer"});
		$(this).mouseover(function(){
			//$(this).removeClass('ui_blockLink');
			$(this).addClass('ui_blockLinkOver');
		});
		
		$(this).mouseout(function(){
			$(this).removeClass('ui_blockLinkOver');
			//$(this).addClass('ui_blockLink');
		});
		
		$(this).click(function(){
			if($(this).find('a.ui_popup').size() > 0){
				var
				elem = $(this).find('a.ui_popup'),
				a = elem.attr("rel").split(",");
				var b;
				if (!a[0]) {a[0] = window.width;}
				if (!a[1]) {a[1] = window.height;}
				if (!a[2]) {a[2] = 1;}
				if (!a[3]) {a[3] = 1;}
				if (!a[4]) {a[4] = 1;}
				if (!a[5]) {a[5] = 1;}
				popup = window.open(elem.attr("href"), elem.attr("target"), "width=" + a[0] + ", height=" + a[1] + ", location=" + a[2] + ", menubar=" + a[3] + ", toolbar=" + a[4] + ", scrollbars=" + a[5]);
				popup.focus();
			}else{
				var _href = $(this).find('a').attr('href');
				var _target = $(this).find('a').attr('target');
				if(!_target) {
					location.href = _href;
				} else {
					_win = window.open(_href, _target, 'location=1, menubar=1, toolbar=1, scrollbars=1');
				}
			}
		});
	};

	//setPrintBtn
	$.fn.setPrint = function(settings){
		$(this).append(
			'<img src="/common/img/co_bt_03_off.gif" alt="印刷する" width="76" height="20" class="ui_rollOver" />'
		);
		$(".ui_print").click(function(){
			print();
		});
	}

	//setCloseBtn
	$.fn.setClose = function(settings){
		$(this).append(
			'<img src="/common/img/co_bt_06_off.gif" alt="閉じる" width="65" height="20" class="ui_rollOver" />'
		);
		$(".ui_close").click(function(){
			window.close();
		});
	}

	//rollOver
	$.fn.rollOver = function()
	{
		var imgsrc = '', path = '', file = '';
		$(this).hover( function(){
			imgsrc = $(this).attr("src").split("/");
			path = imgsrc.slice(0,-1).join("/") + "/";
			file = imgsrc[imgsrc.length - 1];
			$(this).attr({"src": path + file.replace("_off.","_over.") });
		},
		function(){
			$(this).attr({"src": path + file.replace("_over.","_off.") });
		});
	};

	//scrollAnchor
	$.fn.scrollAnchor = function(settings)
	{
		settings = jQuery.extend({
			timer:1000,
			easing:"easeOutExpo",
			topMargin:50
		}, settings);

		var curPos = 0;
		var ankPos = 0;
		var timer = settings.timer;
		this.click(function()
		{
			curPos = $(this).offset().top;
			ankPos = $($(this).attr("href")+":first").offset() ? $($(this).attr("href")+":first").offset().top - settings.topMargin : 0;
			if(curPos > ankPos){
				timer = settings.timer * (curPos - ankPos) / 7000;
			}else if(curPos < ankPos){
				timer = settings.timer * (ankPos - curPos) / 7000;
			}else{
				timer = 30;
			}
			$("html:not(:animated),body:not(:animated)").animate({scrollTop:ankPos}, timer, settings.easing);
			return false;
		});
	};

	//popup
	$.fn.popUp = function()
	{
		$(this).click(function (){
			var a = $(this).attr("rel").split(",");
			var b;
			if (!a[0]) {a[0] = window.width;}
			if (!a[1]) {a[1] = window.height;}
			if (!a[2]) {a[2] = 1;}
			if (!a[3]) {a[3] = 1;}
			if (!a[4]) {a[4] = 1;}
			if (!a[5]) {a[5] = 1;}
			if (!a[6]) {a[6] = 1;}
			popup = window.open($(this).attr("href"), $(this).attr("target"), "width=" + a[0] + ", height=" + a[1] + ", location=" + a[2] + ", menubar=" + a[3] + ", toolbar=" + a[4] + ", scrollbars=" + a[5] + ", resizable=" + a[6]);
			popup.focus();
			return false;
		});
	};

	//config cookie for smartPhone
	$.fn.smtConfig = function()
	{
		//cokkie init
		var ck = $.cookie("fSmt") ? $.cookie("fSmt") : false;
		if(!ck){
			$.cookie("fSmt","smt",{ expires: 7 });
		}

		$(this).click(function (){
			if($.cookie("fSmt")=="pc"){
				$.cookie("fSmt","smt",{ expires: 7 });
			}else{
				$.cookie("fSmt","pc",{ expires: 7 });
			}
		});
	};
})(jQuery);

jQuery(document).ready(function($) {

	//サイドナビ編集
	var	sNav = $("#siLnav");
	var crrUrl = document.location.pathname;
	if(sNav.length>0){
		//子要素非表示処理(親要素がリンクを持たない場合は常時表示)
		sNav.find("li ul li ul").each(function(){
			if($(this).closest("li").children("a").length > 0){
				$(this).hide();
			}
		});
		//カレント設定
		var crrElm = sNav.find("a[href=\""+crrUrl+"\"]");
		if(crrElm.length>0){
			crrElm.closest("li").addClass("g_siNavCurrent");
		}else{
			//カレントが見当たらないときは親ディレクトリをカレントにする
			var arElm = crrUrl.split("/"),subElm="";
			for($i=1;arElm.length-1>$i;$i++){
				subElm = subElm+"/"+arElm[$i];
			}
			crrElm = sNav.find("a[href=\""+subElm+"/\"]");
			if(crrElm.length>0){
				crrElm.closest("li").addClass("g_siNavCurrent");
			}
		}
		//カレントの親要素・子要素表示
		$("li.g_siNavCurrent").children("ul").show();
		$("li.g_siNavCurrent").parents("ul").show();
		//sNav.children("ul").children("li:last-child").children("a").css({"background":"none"});
		//sNav.find("li li:last-child a").css({"background-position":"bottom left"});
	}

	//blockLink
	if($(".ui_blockLink").length > 0){
		$(".ui_blockLink").blockLink();
	}
	//setPrintBtn
	if($(".ui_print").length > 0){
		$(".ui_print").setPrint();
	}
	//setCloseBtn
	if($(".ui_close").length > 0){
		$(".ui_close").setClose();
	}
	//rollOver"
	if($(".ui_rollOver").length > 0){
		$(".ui_rollOver").rollOver();
	}
	//scrollAnchor
	if($(".ui_scrollTop").length > 0){
		$(".ui_scrollTop").scrollAnchor({easing:"swing"});
	}
	//popup
	if($(".ui_popup").length > 0){
		$(".ui_popup").popUp();
	}
	//smartphone link
	if($(".switchSmart").length > 0){
		$(".switchSmart").smtConfig();
	}
	
//	var fSmt = navigator.userAgent.search(/iPhone|iPad|iPod|Android/);
//	if(fSmt>0){
//		setTimeout(scrollTo, 100, 0, 1);
//	}
	
	if(!$.support.style){
		window.onerror = function(){
			return true;
		};
	}

});

