
var add = {
	
	noSelfLink:function(){
		$('a img[class*=noself]').each(function(){
			$(this).attr('src',$(this).attr('src').replace(/_f2/,""));
		});
	},
	
	searchNav:function(){
		//検索
		var flag = false;
		$('#search select :selected').each(function(){
			if ($(this).val() != ''){
				flag = true;
			}
		});
		if(flag){
			$('.morebtn a').toggle(function(){
				$('.morekeyword').slideUp('fast');
			},function(){
				$('.morekeyword').slideDown('fast');
			});
		}else{
			$('.morekeyword').hide();
			$('.morebtn a').toggle(function(){
				$('.morekeyword').slideDown('fast');
			},function(){
				$('.morekeyword').slideUp('fast');
			});
		}
	},
	
	//ラインナップナビゲーション
	lineupNav:function(){
		
		$('#lineup.nav > ul > li').addClass('dep1');
		$('#lineup > ul .dep1 ul').hide();
		$('#lineup .current').parents().show();
		$('#lineup .current').parent().children().show();
		$('#lineup .parentsLink').parent().children().show();
		$('#lineup > ul .dep1 > a').toggle(function(){
			if($(this).hasClass('parentsLink') || $(this).hasClass('current')){
				$(' > ul:not(:animated)',$(this).parent()).slideUp('fast');
			}else{
				$(' > ul:not(:animated)',$(this).parent()).slideDown('fast');
			}
		},function(){
			if($(this).hasClass('parentsLink') || $(this).hasClass('current')){
				$(' > ul:not(:animated)',$(this).parent()).slideDown('fast');
			}else{
				$(' > ul:not(:animated)',$(this).parent()).slideUp('fast');
			}
		});
		
	},
	
	//パンくずリスト変更
	topicPath:function(){	
		
		var parentCat = [];
		var childCat = [];
		var target = $('#bread-crumb li:eq(1) a');
		
		$('#lineup > ul > li').each(function(){
			parentCat.push($(' > a',this).attr('href'));
			childCat.push($(' > ul li:first a',this).attr('href'));
		});
		
		$.each(parentCat,function(i,url){
			if(target.attr('href') == url){ 
				target.attr('href',childCat[i]);
			}
		});
		
		var lastTxt = $('#bread-crumb li:last a').text();
		$('#bread-crumb li:last').empty();
		$('#bread-crumb li:last').text(lastTxt);
	},
	
	//詳細ページの商品イメージ制御
	detailImage:function(){
		
		$("#details-pattern .pattern1-1-1 a").click(function(){
			var altTxt = $('img',this).attr('alt');
			var captionTxt = altTxt.split('：');
			$(".details-photo-main img").before("<img src='"+$(this).attr("href")+"' alt='"+altTxt+"' />");
			$(".details-photo-main img:last").fadeOut("fast",function(){
				$(this).remove()
			});
			$('#details-photo p.caption').text(captionTxt.pop());
			return false;
		});
	},
	
	//商品詳細ページの画像が１枚の場合、サムネールを消す
	detailImageHide:function(){
		var thmbSize = $('.pattern1-1-1 div.col').size();

		if(thmbSize == 1){
			$('.pattern1-1-1 div.col').hide();
		}
	},
	
	//カラーサンプルにL画像が登録されていない場合、aを取る
	colorLinkHide:function(){
		$('#color-pattern .col').each(function(){
			var imgTag = '';
			var urlLast = $('a',this).attr('href').split('/').pop();
			if(urlLast == ''){
				imgTag = $('a',this).html();
				$('a',this).empty();
				$('.photo_line_link',this).html(imgTag).css('border','solid 1px #ccc');
			}
		});
	},
	
	//カレンダーにtodayを挿入
	calendarOpe:function(){
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		var ym = String(year)+'年'+String(month)+'月';
		var ym2 = String(year)+String(month);
		var curMonth = $('#calendar ul li:last').text();
		var curMonth2 = $('#calendar ul li:last').text().replace(/(年|月|\s)/g,'');
		$('#calendar ul li:last').empty();
		$('#calendar ul li:eq(0)').after('<li>'+curMonth+'</li>');
		if(ym2 == curMonth2){
			//alert(ym);
			$('#calendar td').each(function(){
				if($(this).text() == String(day)){

					$(this).addClass('today');
				}
				
			});
		}
	},
	
	//エントリー投稿時のパターン画像表示
	changeIcon:function(){
		$('.changeIcon').each(function(){
			var self = $(this);
			var showClass = '.pt'+$('select :selected',this).val();
			$('.pt ul',self).hide();
			$(showClass,self).show();
			$('select',self).change(function(){
				$('.pt ul',self).hide();
				showClass = '.pt'+$(this).val();
				$(showClass,self).show();
			});
		});
		
	},
	
	//pdfの閲覧をgoogleアナリティクスに反映
	pdfAnalysis:function(){
		$('a[href$=pdf]').click(function(){
			var pdfName = $(this).attr('href');
			pageTracker._trackPageview(pdfName);
		});
	},
	
	//サブカテのselected
	subCatVal:function(){
		var subCat = $('#subCat').val();
		$('#subCat').next().val(subCat);
	}
	
}

$(function(){
	add.noSelfLink();
	add.searchNav();
	add.lineupNav();
	add.topicPath();
	add.detailImage();
	add.detailImageHide();
	add.colorLinkHide();
	add.calendarOpe();
	add.changeIcon();
	add.pdfAnalysis();
	add.subCatVal();
	try{
		$('#itemlist-pattern div.col,#related-item-pattern div.col').flatHeights();
	}catch(e){}
});


