// ロールオーバー
$(function() {
	if(document.getElementsByTagName) {
		var images = document.getElementsByTagName("img");
		var images_pre = new Array();
		for(var i = 0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")) {
				images_pre[i] = new Image();
				images_pre[i].src = images[i].getAttribute("src").replace("_off.", "_on.")

				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."));
				}
			}
		}
	}
});

//ページトップ
$(function () {
	$("div.pagetop a").click(function () {
		$(this).blur();
		$("html,body").animate({scrollTop:0},"_default");//Safari：body指定
		return false;
	});
});

// _blank
$(function() {
	var anchors = document.getElementsByTagName("a");
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
});

// ストライプテーブル
$(function() {
	var tableList = document.getElementsByTagName("table");
	for(var i=0; i < tableList.length; i++) {
		if(tableList[i].className.match("stripe")){
			var trList = tableList[i].getElementsByTagName("tr")
			for(var j=0; j<trList.length; j++){
				if(j%2==1) {
					trList[j].className = trList[j].className + " odd";
				}else {
					trList[j].className = trList[j].className + " even";
				}
			}
		}
	}
});


/*$(function() {
	var ulList = document.getElementsByTagName("ul");
	for(var i=0; i < ulList.length; i++) {
		if(ulList[i].className.match("stripe")){
			var liList = ulList[i].getElementsByTagName("li")
			for(var j=0; j<liList.length; j++){
				if(j%2==1) {
					liList[j].className = liList[j].className + " odd";
				}else {
					liList[j].className = liList[j].className + " even";
				}
			}
		}
	}
});*/


//IE6
/*$(document).ready(function() {  
	$('div#header ul li:first-child').addClass('firstChild');
	$('div#footer ul li:first-child').addClass('firstChild');
});

*/



/*--------------------------------------------------------------------------*
 *  
 *  fixHeight JavaScript Library beta1
 *  
 *  jQuery required.
 *  
 *  MIT-style license. 
 *  
 *  May 18th , 2009 Written by Koji Kimura
 *  http://www.starryworks.co.jp/
 *  
 *--------------------------------------------------------------------------*/

$(document).ready(function(){
	var groups = [];
	var textHeight = 0;
	var $fontSizeDiv;
	
	function init() {
		$(".fixHeight, .fixHeightNAuto, *[class*=fixHeightN]").each(function(){
			var $this = $(this);
			var $children = $(".fixHeightChild",$this);
			if ( !$children.length ) $children = $this.children();
			if ( !$children.length ) return;
			var n = 0;
			if ( $(this).hasClass("fixHeightNAuto") ) n = -1;
			else if ( String($this.attr("class")).match(/fixHeightN([0-9]+)/) ) n = parseInt(String($this.attr("class")).match(/fixHeightN([0-9]+)/)[1]);
			else if ( !$(this).hasClass("fixHeight") ) return;
			groups.push({ parent:this, children:$children, n:n });
		});
		
		$fontSizeDiv = $(document).append('<div>s</div>');
		setInterval(check,1000);
		$(window).resize(check);
		check();
	}
	
	function check() {
		if ( $fontSizeDiv.height() == textHeight ) return;
		textHeight = $fontSizeDiv.height();
		$.each(groups,function(){
			var $children = this.children;
			var n = this.n;
			$children.css("height","auto");
			var maxHeight = 0;
			if ( n == 0 ) {
				$children.each(function(){
					if ( $(this).height() > maxHeight ) maxHeight = $(this).height();
				});
				$children.css("height",maxHeight+"px");
			} else if ( n == -1 ) {
				var top = 0, cnt = 0, st = 0, i = 0;
				$children.each(function(){
					if ( top != $(this).position().top ) {
						if ( cnt > st ) for ( i = st; i < cnt; i++ ) $children.eq(i).css("height",maxHeight+"px");
						top = $(this).position().top;
						maxHeight = 0;
						st = cnt;
					}
					if ( $(this).height() > maxHeight ) maxHeight = $(this).height();
					cnt++;
				});
				if ( cnt > st ) for ( i = st; i < cnt; i++ ) $children.eq(i).css("height",maxHeight+"px");
			} else {
				var maxHeights = [];
				$children.each(function(index){
					if ( index != 0 && index % n == 0 ) {
						maxHeights.push(maxHeight);
						maxHeight = 0;
					}
					if ( $(this).height() > maxHeight ) maxHeight = $(this).height();
				});
				maxHeights.push(maxHeight);
				$children.each(function(index){
					$(this).css("height",maxHeights[Math.floor(index/n)]+"px");
				});
			}
		});
	}
	
	init();
});