$(function(){
	$('.section').corner("10px");
	$('#main_navi a').mouseover(function(){
		$src = $('img', this).attr('src').replace('_n.gif','_o.gif');
		$('img', this).attr('src', $src);
	});
	$('#main_navi a').mouseout(function(){
		$src = $('img', this).attr('src').replace('_o.gif','_n.gif');
		$('img', this).attr('src', $src);
	});
	$('#main_navi a:last').css('border-right','0');
	
	if($('#seach-materials').length > 0)
	{
		search_materials();
		$('#seach-materials input:radio').change(function(){
			search_materials();
		});
	}
	
	if($('#seach-materials').length > 0)
	{
		$num = $('#page-midi #musiclist tbody tr').length;
		$('#page-midi #musiclist tbody tr').filter(function(i){
			if(i > $num - 23 || i === 14) return true;
			else return false;
		}).find('a').prepend('<img src="/wordpress/wp-content/themes/robin/images/checked.gif" /> ');
	}

});

function rewrite_materials_tr(){
	$('#musiclist tbody tr:visible:even').attr('class', 'even');
	$('#musiclist tbody tr:visible:odd').attr('class', 'odd');
}

function search_materials(){
	$s_genre = $('[name="genre"]:checked').val();
	$s_tempo = $('[name="tempo"]:checked').val();
	
	$('#musiclist tbody tr').each(function(){
		$t_genre = $(this).children('.genre').attr('rel');
		$t_tempo = $(this).children('.tempo').attr('rel');
		
		if(
			$s_genre == $t_genre && $s_tempo == $t_tempo ||
			$s_genre == 'off' && $s_tempo == $t_tempo ||
			$s_genre == 'off' && $s_tempo == 'off' ||
			$s_genre == $t_genre && $s_tempo == 'off'
		) $(this).show();
		else $(this).hide();
	});
	
	$('#no-materials-alert').remove();
	if($('#musiclist tbody tr:visible').length == 0) $('#musiclist').after('<p id="no-materials-alert" style="text-align:center; padding:25px 0; border-bottom:1px solid #E8E8E8;">該当する楽曲はありませんでした。</p>');
	
	rewrite_materials_tr();
}
