
$(function(){
	
	$('#nav a, #shop a, h1 a, #main a').hover(function(){
		$('img',this).css('opacity',0.65)
	},function(){
		$('img',this).css('opacity',1)
	})

	//top
	if ($('body').attr('id') == 'top') {
		var months = {Jan:'01', Feb:'02', Mar:'03', Apr:'04', May:'05', Jun:'06', Jul:'07', Aug:'08', Sep:'09', Oct:'10', Nov:'11', Dec:'12'}
		$('#topics').html(topics).find('span').each(function(){
			$(this).text($(this).text().substr(0, 10))
		}).end().find('a').each(function(){
			if ($(this).text().length > 17)
				$(this).text($(this).text().substr(0, 17) + '..')
		}).end().show()
	}
	
	//vision
	if ($('body').attr('id') == 'vision') {
		$('#main a').click(function(){
			$('#main p').hide().filter($(this).attr('href')).show()
			return false
		})
	}
	
	//shoplist
	if ($('body').attr('id') == 'shoplist')	{
		$('table').hide().first().show()
		$('#subnav a').click(function(){
			var href = $(this).attr('href')
			$('#subnav img').removeClass('this').css('opacity',0.5)
			$('img',this).addClass('this').css('opacity',1)
			$('table').hide().filter(href).show()
			if (href == '#osaka' || href == '#okayama' || href == '#tokyo') {
				$('#subnav ul').hide()
			} else {
				$('#subnav ul').show()
				$('#subnav img').first().addClass('this').css('opacity',1)
				if ($(this).parent().parent().attr('id') == 'subnav') {
					$('#subnav img').eq(1).addClass('this').css('opacity',1)
				}
			}
			return false
		}).find('img').hover(function(){
			$(this).css('opacity',1)
		},function(){
			if (! $(this).hasClass('this'))
				$(this).css('opacity',0.5)
		}).filter(':gt(1)').css('opacity',0.5)
	}
	
	//product
	if ($('body').attr('id') == 'product') {
		$('#season dd').hide()
		$('#always dd:gt(0)').css('opacity',0.5)
		$('#main dl').hide().first().show()
		$('#menu dl a').click(function(){
			$($(this).attr('href')).show().siblings().hide()
			if ($(this).parent('dt').length)
				$(this).parent().siblings().show().removeClass('this').css('opacity',0.5).first().addClass('this').css('opacity',1).parent().siblings().find('dd').hide()
			else
				$(this).parent().addClass('this').siblings('dd').removeClass('this').css('opacity',0.5)
			return false
		})
		
		$('#menu dd').hover(function(){
			$(this).css('opacity',1)
		},function(){
			if (! $(this).hasClass('this'))
				$(this).css('opacity',0.5)
		})

		function overlay(target){
			$('#connected > dt').hide()
			$('#connected > dd').remove()
			$('#overlay').show().css('opacity',0.8).height($(document).height())
			$('html,body').scrollTop(0)
			$('#box').show()
			$('#detail').attr('src',$(target).attr('href'))
			
			if ($(target).attr('rel') != '') {
				$('#box_inner').addClass('connected')
				var target_array = $(target).attr('rel').split(',')
				var i = target_array.length
				while (i--) {
					var cat = $(target_array[i]).parent().parent().attr('id')
					if (cat == 'winter' || cat == 'spring' || cat == 'summer' || cat == 'autumn')
						cat = '#connected_' + cat
					else
						cat = '#connected_all'
					
					$(target_array[i]).clone(true).html('<img src="' + $(target_array[i]).prev().attr('src').replace('.jpg','_s.jpg').replace('syouhin-','') + '">').insertAfter(cat).wrap('<dd></dd>')
					$(cat).show()
				}
			}
			if ($(target).attr('class') == 'season')
				$('#connected').attr('class','season')
			else
				$('#connected').removeClass()

			$(target).parent().parent().show(0,function(){
				var id = '#' + $(this).attr('id')
				if ($(this).attr('id') == 'winter' || $(this).attr('id') == 'spring' || $(this).attr('id') == 'summer' || $(this).attr('id') == 'autumn') {
					$('#always dd').hide()
					$('#season dd').show().removeClass('this').css('opacity',0.5).each(function(){
						if ($('a',this).attr('href') == id)		
							$(this).addClass('this').css('opacity',1)					
					})
				} else {
					$('#season dd').hide()
					$('#always dd').show().removeClass('this').css('opacity',0.5).each(function(){
						if ($('a',this).attr('href') == id)		
							$(this).addClass('this').css('opacity',1)					
					})
				}
			}).siblings().hide()
		}
		
		$('#close').click(function(){
			$('#overlay,#box,#connected > dt').hide()
			$('#connected > dd').remove()
			$('#box_inner').removeClass('connected')
		}).hover(function(){
			$(this).css('opacity',0.7)
		},function(){
			$(this).css('opacity',1)
		})
		
		$('#main a').click(function(){
			overlay('#' + $(this).attr('id'))
			return false
		}).each(function(){
			$('<img>').attr('src',$(this).attr('href'))
		})
		
		$('#connected > dd > img').live('mouseover',function(){
			$(this).css('opacity',0.7)
		}).live('mouseout',function(){
			$(this).css('opacity',1)
		})

	}
	
})

