/* ////////////////////////////////////////////////////////////////////////////////////////////////////
 *
 * Title  : Setting JavaScript
 * Author : Daisuke Zamoto
 * UpDate : 2011/02/01
 *
 * ///////////////////////////////////////////////////////////////////////////////////////////////// */

// ====================================================================================================
//  jQueryを必要とするスクリプト
// ====================================================================================================

// OS判別によるHTML要素クラス付加
jQuery(document).ready(function($) {
	if (navigator.platform.indexOf("Win") != -1) {
		$("body").addClass("win");
	}
});

// 外部リンクを別ウィンドウで表示（ローカル動作不可）
jQuery (document).ready( function ($) {
	$("a[href^=http]").not("[href*="+location.hostname+"]").attr("target","_blank");
})

// 印刷ダイアログを表示
jQuery(document).ready(function($) {
	$('a.ico-print').click(function(){
		window.print();
		return false;
	});
	$("a.ico-print").hover(function(){
		$(this).css("cursor","pointer");
	},function(){
		$(this).css("cursor","default");
	});
});

// イージングスクロール	
jQuery(document).ready(function($) {
	$('a[href*=#][class$=scroll]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target	|| $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 300);
				return false;
			}
		}
	});
});

// リンク領域の拡張
jQuery(document).ready(function($) {
	$(".biglink").click(function(){
      window.location=$(this).find("a").attr("href");
       return false;
    });
	$(".biglink").hover(function(){
		$(this).css("cursor","pointer");
	},function(){
		$(this).css("cursor","default");
	});
});

// アコーディオンパネル
jQuery(document).ready(function($) {
	$(".panel").not(".current").hide();
	$(".accordion .openbtn").click(function() {
		$(".accordion .panel").not($(this).next()).slideUp();
		$(this).next().slideToggle();
	});
	$(".toggle .openbtn").click(function() {
		$(this).next().slideToggle();
	});
	$(".openbtn").hover(function() {
		$(this).css("cursor","pointer");
	},function(){
		$(this).css("cursor","default");
	});
});

// タブパネル
jQuery(document).ready(function($) {
	var tabArea = $('.tabArea');
	var tabPanel = $('.tabPanel',tabArea);
	var tab = $('.tabMenu li',tabArea);
	tabPanel.not(':first').hide();
	tab.eq(0).addClass('active');
	tab.click(function(){
		var targetTabId = $('a',this).attr('hash');
		tab.removeClass('active');
		tabPanel.hide();
		$(this).addClass('active');
		$(targetTabId).show();
		return false;
	});
});


// テーブルの行に偶数・奇数クラスの挿入
jQuery(document).ready(function($){
  $("table").each(function(){
    $(this).find("tr:even").addClass("odd");
  });
});

// IE6でDD_belatedPNG.jsのロールオーバー処理
jQuery(document).ready(function($) {
	if ($.browser.msie && $.browser.version <= 6 ) {
		var oldFixPng = DD_belatedPNG.fixPng;
		DD_belatedPNG.fixPng = function (el) {
			oldFixPng(el);
			if (el.vml && el.vml.image.fill.getAttribute("src").match(/_off\./)) {
				el.vml.image.shape.attachEvent('onmouseenter', function() {
					var image = el.vml.image.fill;
					image.setAttribute("src", image.getAttribute("src").replace("_off.", "_on."));
			});
				el.vml.image.shape.attachEvent('onmouseleave', function() {
					var image = el.vml.image.fill;
					image.setAttribute("src", image.getAttribute("src").replace("_on.", "_off."));
				});
			}
		};
		DD_belatedPNG.fix('img, .png_bg');
	}
});

// ====================================================================================================
//  jQueryを必要としないスクリプト
// ====================================================================================================

// JavaScriptエラーを非表示化
window.onerror = function () {
	return true;
}

// 画像のロールオーバー
function smartRollover() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")) {
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}
if(window.addEventListener) {
	window.addEventListener("load", smartRollover, false);
}else if(window.attachEvent) {
	window.attachEvent("onload", smartRollover);
}

// フィード購読用URLのアラート表示
var linkURIs = new Array();
function getRSSurl(idName) {
	var linkURI = "";
	if(linkURIs[idName] != undefined) {
		linkURI = linkURIs[idName];
	}else {
		if(document.all) {
			linkURI = document.all(idName).href;
		} else if(document.getElementById) {
			linkURI = document.getElementById(idName).href;
		}
	}
	prompt("当サイトではRSS配信を行っています。\n配信希望の方は、下記URLをご使用のRSSリーダーにご登録ください。",linkURI);
	linkURIs[idName] = linkURI;
	if(document.all) {
		document.all(idName).href = 'javascript:void(0);';
	}else if(document.getElementById) {
		document.getElementById(idName).href = 'javascript:void(0);';
	}
	return false;
}

// 検索フォームの値チェック
function inputCheck(obj){
    if(obj.s.value == ''){
        alert("検索キーワードを入力して下さい"); return false;
    } else {
        return true;
    }
}

// フッターを最下部に固定（MIT-style license. Kazuma Nishihata [to-R] http://blog.webcreativepark.net）
new function(){
	var footerId = "FooterWrap";
	function footerFixed(){
	var dh = document.getElementsByTagName("body")[0].clientHeight;
	document.getElementById(footerId).style.top = "0px";
	var ft = document.getElementById(footerId).offsetTop;
	var fh = document.getElementById(footerId).offsetHeight;
	if (window.innerHeight){
		var wh = window.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight != 0){
		var wh = document.documentElement.clientHeight;
	}
	if(ft+fh<wh){
		document.getElementById(footerId).style.position = "relative";
		document.getElementById(footerId).style.top = (wh-fh-ft-1)+"px";
	}
}
function checkFontSize(func){
	var e = document.createElement("div");
	var s = document.createTextNode("S");
	e.appendChild(s);
	e.style.visibility="hidden"
	e.style.position="absolute"
	e.style.top="0"
	document.body.appendChild(e);
	var defHeight = e.offsetHeight;
	function checkBoxSize(){
		if(defHeight != e.offsetHeight){
			func();
			defHeight= e.offsetHeight;
		}
	}
setInterval(checkBoxSize,1000)
}
function addEvent(elm,listener,fn){
	try{
		elm.addEventListener(listener,fn,false);
	}catch(e){
		elm.attachEvent("on"+listener,fn);
	}
}
addEvent(window,"load",footerFixed);
addEvent(window,"load",function(){
	checkFontSize(footerFixed);
});
addEvent(window,"resize",footerFixed);
}
