$(function(){

	//外部リンクの場合、自動的に別ウィンドウで表示
	var domain = "[@href^=\"http://"+location.hostname+"/\"]";
	$('a[@href^="http"]').not(domain).click(function() {
		$(this).attr('target','_blank');
	});

	//画像へ直リンクの場合、lightbox風に表示
	//jquery.lightbox-0.5.js利用
	try {
		$('a[@href$=".jpg"], a[@href$=".gif"], a[@href$=".png"]').lightBox({fixedNavigation:true});
	} catch(e) {
	}

	//class="over"でロールオーバーを設定
	//img要素が含まれていたらsrc属性を_on付きのものに差し替える
	$('.over img').each(function(){
		this.originalSrc = $(this).attr('src');
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
	});
	$('.over').hover(function(){
		$(this).find('img').each(function(){
			$(this).attr('src',this.rolloverSrc);
		});
	},function(){
		$(this).find('img').each(function(){
			$(this).attr('src',this.originalSrc);
		});
	});

	//奇数、偶数を自動追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('ol').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('thead').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	$('tbody').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	$('tfoot').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});	

	//:first-child、:last-childをクラスとして追加
	$('ul').each(function(){
		$(this).find('li:first-child').addClass('firstChild');
		$(this).find('li:last-child').addClass('lastChild');
	});
	$('ol').each(function(){
		$(this).find('li:first-child').addClass('firstChild');
		$(this).find('li:last-child').addClass('lastChild');
	});
	$('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');
	});

});

