
/* *********************************************************
script.js
サイト全体で共有するJS
********************************************************* */

$(function(){

	/* ==================================================
	 * 外部リンクを別ウィンドウで開く
	 * Copyright (c) 2009 Kyosuke Nakamura (kyosuke.jp)
	 * Licensed under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 ================================================== */
	var siteUri = 'http://axanael.jp/';
	var windowOpen = true;
	var externalClass = 'externalLink';
	
	var externalLinks = $('a[href^="http"]').not('a[href^="' + siteUri + '"]');
	if (windowOpen) {
		externalLinks.click(function(){
			window.open($(this).attr('href'), '_blank');
			return false;
		});
	}
	externalLinks.addClass(externalClass);

	/* ==================================================
	 * 画像ロールオーバー
	 * @author AkiraNISHIJIMA(http://nishiaki.probo.jp/)
	 * Licensed under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 ================================================== */
	var img_cache = new Object();
	$('img.over').not('[src*="_on"]').each(function(){
		var imgsrc = this.src;
		var imgsrc_non_filetype = this.src.lastIndexOf('.');
		var imgsrc_over = this.src.substr(0,imgsrc_non_filetype)+'_on'+this.src.substr(imgsrc_non_filetype,4);
		img_cache[this.src] = new Image();
		img_cache[this.src].src = imgsrc_over;
		$(this).hover(
			function(){ this.src = imgsrc_over; },
			function(){ this.src = imgsrc; }
		);
	});

	/* ==================================================
	/* CSS3を擬似実装
	 * Copyright (c) 2007 Kyosuke Nakamura (kyosuke.jp)
	 * Licensed under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 ================================================== */
	/* :nth-child,:first-child,:last-childを実装
	--------------------------------------------------- */
	$('li:nth-child(odd)').addClass('odd');
	$('li:nth-child(even)').addClass('even');
	$('li:first-child').addClass('firstChild');
	$('li:last-child').addClass('lastChild');
	$('tr:nth-child(odd)').addClass('odd');
	$('tr:nth-child(even)').addClass('even');
	$('tr:first-child').addClass('firstChild');
	$('tr:last-child').addClass('lastChild');

	/* display:box;を実装
	--------------------------------------------------- */
	/* 2段組 */
	$('.column2 li').each(function(i){
		$(this).addClass('nth'+(i+1));
	});
	$('column2 li:nth-child(2n)').addClass('lastCol');
	$('column2 li:nth-child(2n+1)').addClass('firstCol');
	var columnBox2 = $('.column2 li');
	var a = [];
	var max = 0;
	var col = 2;
	var lastIndex = columnBox2.length;
	columnBox2.each(function(i){
		var li = $(this);
		var index = i + 1;
		a.push(li);
		if (li.height() > max){
			max = li.height();
		}
		if (index % col === 0 || index === lastIndex){
			$.each(a, function(i, li){
				li.height(max);
			});
			a = [];
			max = 0;
		}
	});
	
	/* 3段組 */
	$('.column3 li').each(function(i){
		$(this).addClass('nth'+(i+1));
	});
	$('column3 li:nth-child(3n)').addClass('lastCol');
	$('column3 li:nth-child(3n+1)').addClass('firstCol');
	var columnBox3 = $('.column3 li');
	var a = [];
	var max = 0;
	var col = 3;
	var lastIndex = columnBox3.length;
	columnBox3.each(function(i){
		var li = $(this);
		var index = i + 1;
		a.push(li);
		if (li.height() > max){
			max = li.height();
		}
		if (index % col === 0 || index === lastIndex){
			$.each(a, function(i, li){
				li.height(max);
			});
			a = [];
			max = 0;
		}
	});

});

