/*

Last UpDate 2010-01-06

jquery-extension.js =
function.js(2010-01-06) + いつもの（ウィンクのみ,ゼブラ,fancybox,slimbox,flatHeightsの説明追加分)

*/

$(function(){
	//現在居るファイル名	   
	var currentFile = location.href.split('/').pop();
	
	//ua取得
	var ua = navigator.userAgent;

	/* ウィンク効果のみ */
	$("#sidecolumn a img").hover(function(){
		$(this).css("opacity", "0.2");
		$(this).css("filter", "alpha(opacity=20)");
		$(this).fadeTo("slow", 1.0);
	});
	
	/* ddの奇数にoddクラスをつける */
	$('#ind04 dd').filter(function(i){
		alert(i);
		if(i % 2 == 0) return this;
	}).addClass('odd');

	//fancybox
	try{
		$("#blog div.item ul a,#blog div.item div.mainv a").fancybox({
			'zoomOpacity' : true,'overlayShow' : false,'zoomSpeedIn' : 500,'zoomSpeedOut' : 500});
	}catch(e){}
		
	/* slimbox */
	try{
	$("div a").slimbox({/* Put custom options here */}, null, function(el) {
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));});
	}catch(e){}

	//classが、'nav'で終わるulの、最後のliに、'last'クラスを付ける
	$('ul[class$="nav"]').each(function(){
		$('li:last',this).addClass('last');
	});
	
	//classが、'list'で終わるulの、偶数の要素に、'even'クラスを付ける
	$('ul[class$="list"] li:nth-child(even)').addClass('even');

	//classが、'list'で終わるulの、偶数の要素に、'even'クラスを付ける
	$('div#news dl:nth-child(even)').addClass('even');

	//classが、'table'で終わるテーブルの、偶数trに、'even'クラスを付ける
	$('table[class$="table"] tr:nth-child(even)').addClass('even');
	
	//rollover
	$('a img').each(function(){
		var imgSrc = $(this).attr('src');
		//smartRollover
		if(imgSrc.match(/(.*)_off(\..*)/)){
			var repSrc = RegExp.$1+'_on'+RegExp.$2;
			$('<img />').attr('src',repSrc);
			$(this).hover(function(){
				$(this).attr('src',repSrc);
				$(this).css({opacity: '1',filter: 'alpha(opacity=100)'});
			},function(){
				$(this).attr('src',imgSrc);
			});
		//ロールオーバーが無い場合は、透明度80%
		}else if(!$(this).hasClass('not')){
			$(this).hover(function(){
					$(this).css({
						opacity: '0.8',
						filter: 'alpha(opacity=80)'
					});
			},function(){
					$(this).css({
						opacity: '1',
						filter: 'alpha(opacity=100)'
					});
			}
			
			);
		}
	});
	
	//透過条件設定 pngfixクラスを持つ要素に透過を適用する
	/*if(ua.indexOf('IE 6') > -1){
		DD_belatedPNG.fix('.pngfix');
	}*/
	
	/*flatHeights設定 http://www.akatsukinishisu.net/itazuragaki/js/i20070801.html
		1.dl自体をtemp配列に入れる（dlの個数分）
		2.i%3(3つごとに）temp配列をsets配列に入れる。
		3.tempを空にする
		4.sets配列を左から順に見ていき、sets[0][0]～sets[0][2]までの高さを揃える
		
		*iは0からスタート
	    *setsは二次元配列なので、一つの枠に、temp配列が入る　
	*/
	if($('div').is('#teaknow04')){
		var sets = [], temp = [];
		$('#teaknow04 dl').each(function(i) {
			temp.push(this);
			if (i % 2 == 1) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);

		/* 各組ごとに高さ揃え */
		$.each(sets, function() {
			$(this).flatHeights();
		});
	}

	if($('div').is('#subcatitem')){
		var sets = [], temp = [];
		$('#subcatitem dl').each(function(i) {
			temp.push(this);
			if (i % 3 == 2) {
				sets.push(temp);
				temp = [];
			}
		});
		if (temp.length) sets.push(temp);

		/* 各組ごとに高さ揃え */
		$.each(sets, function() {
			$(this).flatHeights();
		});
	}

	try{
		$('div.cart object').append('<param name="wmode" value="transparent" />');
		$('div.cart object embed').attr("wmode","transparent");
		$('div.cart object').css("z-index", "1");
		$('div.cart object embed').css("z-index", "1");
	}catch(e){
	}
		
	//submit押した感 & ウィンクorsmartrollover
	$('form p.submit input').mousedown(function(){
		$(this).css({position:'relative',top:'1px',left:'1px'});
	}).mouseup(function(){
		$(this).css({position:'static'});
	}).mouseout(function(){
		$(this).css({position:'static'});
	})
	  .hover(function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.*)_off.(.*)$/,'$1_on.$2'));
	},function(){
		$(this).attr('src',$(this).attr('src').replace(/^(.*)_on.(.*)$/,'$1_off.$2'));
	});

	if($('div').is('#ranking')){
	$("#ranking dl dd.title").autoHeight({column:5});
	}

});