/* マウスオーバー時の画像入れ替え */
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);
}

/* ページの先頭へ */
function backToTop() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop()", 25);
  }
}

/* トップページタブ切り替え */
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	$("ul.tabs li:first").click(); //Activate first tab

});


/* トップサイドメニュー展開 */
$(document).ready(function() {
	$("h3#sidenavi1").hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default"); 
		});
	$("h3#sidenavi1").click(function(){
		if($(this).next().css("display")=="none") {
			$("h3#sidenavi2").next().slideUp("fast");
		}
		$(this).next().slideToggle("fast");
		});
});

$(document).ready(function() {
	$("h3#sidenavi2").hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default"); 
		});
	$("h3#sidenavi2").next().css("display","none");
	$("h3#sidenavi2").click(function(){
		if($(this).next().css("display")=="none") {
			$("h3#sidenavi1").next().slideUp("fast");
		}
		$(this).next().slideToggle("fast");
		});
});


/* グローバルメニュー展開 */
$(document).ready(function() {
	$(".gnavi dt").hover(function(){
		$(this).css("cursor","pointer"); 
	},function(){
		$(this).css("cursor","default"); 
		});
	$(".gnavi dd").css("display","none");
	$(".gnavi dt").click(function(){
		if($(this).next().css("display")=="none") {
			$(".gnavi dd").slideUp();
		}
		$(this).next().slideToggle("fast");
		});
});

/*
 * RSS Reader
 * use Google feed api
 */
function rssreader(target, feedurl) {

	var $container = $(target);
	var feed = new google.feeds.Feed(feedurl);
	feed.setNumEntries(5);
	feed.load(function(result) {
		if (!result.error) {
			$container.html("");
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				var entrydate = new Date(entry.publishedDate);
				var printdate = entrydate.getMonth()+"月"+entrydate.getDate()+"日";
				$container.append('<li><a href="'+entry.link+'" target="_blank">'+entry.title+'</a>&nbsp;['+printdate+']</li>');
			}
		}
	});

}

function rssreader_nodate(target, feedurl) {

	var $container = $(target);
	var feed = new google.feeds.Feed(feedurl);
	feed.setNumEntries(5);
	feed.load(function(result) {
		if (!result.error) {
			$container.html("");
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				var entrydate = new Date(entry.publishedDate);
				$container.append('<li><a href="'+entry.link+'">'+entry.title+'</a></li>');
			}
		}
	});

}


/* 
 * GoogleAnalytics
 */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21867869-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/*
 * Googleカスタムサーチ
 */
var gaJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + gaJsHost + "www.google.com/cse/brand?form=cse-search-box&lang=ja' type='text/javascript'%3E%3C/script%3E"));

/*
 * Google AJAX Feed API
 */
var gaJsHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + gaJsHost + "www.google.com/jsapi' type='text/javascript'%3E%3C/script%3E"));

