/* 共通テンプレート
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
$(function(){

	/* ブロックレベル要素の高さをそろえる
	 * http://www.akatsukinishisu.net/itazuragaki/js/i20070801.html
	 */
	$('#newsListTopics ul.linklist li').flatHeights();
	$('.list2column li').flatHeights();
	$('#cat_works li').flatHeights();
	$('#staffblog li').flatHeights();

	/* 外部リンクを別ウィンドウで開く
	 * Copyright (c) 2009 Kyosuke Nakamura (kyosuke.jp)
	 * Licensed under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 */
	var siteUri = 'http://www.nitroplus.co.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);

	/* 画像ロールオーバー
	 * Licensed:MIT License
	 * @author AkiraNISHIJIMA(http://nishiaki.probo.jp/)
	 */
	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; }
		);
	});

	/* yuga.js 0.4.2 - 優雅なWeb制作のためのJS
	 * Copyright (c) 2007 Kyosuke Nakamura (kyosuke.jp)
	 * Licensed under the MIT License:
	 * http://www.opensource.org/licenses/mit-license.php
	 */

	//奇数・偶数、:first-child、:last-childをクラスとして追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
		$(this).find('li:first-child').addClass('firstChild');
		$(this).find('li:last-child').addClass('lastChild');
	});
	$('ol').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
		$(this).find('li:first-child').addClass('firstChild');
		$(this).find('li:last-child').addClass('lastChild');
	});
	$('table').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	$('thead').each(function(){
		$(this).find('tr:first-child').addClass('firstChild');
		$(this).find('tr:last-child').addClass('lastChild');
	});
	$('tbody').each(function(){
		$(this).find('tr:first-child').addClass('firstChild');
		$(this).find('tr:last-child').addClass('lastChild');
	});
	$('tfoot').each(function(){
		$(this).find('tr:first-child').addClass('firstChild');
		$(this).find('tr:last-child').addClass('lastChild');
	});

	/* 検索フォーム */
	$('#search_text').focus(function() {
		$(this).parent().addClass('jFocus');
	});
	$('#search_text').blur(function() {
		if ($(this).parent().find('.jFocus')) {
			$(this).parent().removeClass('jFocus');
		}
	});

});
