
$(function(){
	
	if (jQuery.support.opacity && jQuery.support.style)
		$('#head a').css('opacity',0.65).addClass('rollover')
	
	$('#main a, #topics a').hover(function(){
		if (! $(this).parent('h2').length)
			$('img',this).css('opacity',0.65)
	},function(){
		$('img',this).css('opacity',1)
	})
	
	//ページTOPにスクロールして戻るリンク
	$('p.pagetop a').click(function() {
		if ($('html').scrollTop() != 0 || $('body').scrollTop() != 0)
			$('html,body').animate({scrollTop:0},1000,'easeOutQuart')
		return false
	})
	
	
	//home
	if ($('body').attr('id') == 'home') {
		
		$('<ul id="left">').appendTo('#news').html($('#topics li:even'))
		$('#main li > img').each(function(){
			$(this).data('src',$(this).attr('src')).attr('src','common/img/home/index.png').show()
		})
		
		var slide_num = $('#slide > p').length
		var slide_array = []

		var i = slide_num
		while (i--) {
			slide_array[i] = i
		}
		
		var n = Number($('#slide').attr('class'))
		i = 50
		while (i--) {
			if (n > 0) {
				var num1 = Math.floor(Math.random() * (slide_num - n)) + n
				var num2 = Math.floor(Math.random() * (slide_num - n)) + n
			} else {
				var num1 = Math.floor(Math.random() * slide_num)
				var num2 = Math.floor(Math.random() * slide_num)
			}
			var data1 = slide_array[num1]
			var data2 = slide_array[num2]
			slide_array[num1] = data2
			slide_array[num2] = data1
		}

		function slideshow(id){
			$('#main li > img').removeClass('this')
			$('#slide p').hide()
			$('#' + id).each(function(){
				$(this).fadeIn(1500)
				$('#main li.' + $(this).attr('id') + ' img').each(function(){
					$(this).fadeTo(0,0).attr('src',$(this).data('src')).addClass('this').fadeTo(0,1)
				})
			})
		}
		
		function auto(){
			i++
			if (i == slide_num)
				i = 0
			slideshow($('#slide p:eq(' + slide_array[i] + ')').attr('id'))
		}
		auto()
		var timer = setInterval(auto,6000)
		var timer_move = true
		
		$('#main li img').click(function(){
			slideshow($(this).parent().attr('class'))
			if (timer_move) {
				clearInterval(timer)
				timer_move = false
			}
		}).hover(function(){
			$(this).css('opacity',0.65)
		},function(){
			$(this).css('opacity',1)
		})
	}
	
	//members
	else if ($('body').attr('id') == 'members') {
		var cat_flag = false
		$.fn.cat = function(flag){
			return $(this).each(function(){
				$(this).attr('src',$(this).attr('src').replace(flag ? '_gray.' : '_color.', flag ? '_color.' : '_gray.'))
			})
		}
		$('h3 img').click(function(){
			if (cat_flag)
				$('h2 a').show()
			else
				$('<a href="">絞り込みを解除する</a>').appendTo('h2').click(function(){
					$(this).hide()
					$('h3 img').cat(true)
					$('#list ul').show().removeClass()
				})
			cat_flag = true
			$('#list ul').hide()
			$(this).cat(true).siblings().cat(false)
			$('#' + $(this).attr('src').split('/title_').pop().replace('_color.png','')).show().addClass('this')
		})
	}
	
	//artists
	else if ($('body').attr('id') == 'artists') {
		$('div.box > table').each(function(){
			$('tr:nth-child(even)',this).addClass('color')
		})
		$('#tab a').click(function(){
			$('div.box > table','#list').hide()
			$($(this).attr('href')).show()
			$('#tab a').removeClass('this')
			$(this).addClass('this')
			return false
		})
	}
	
	//stage
	else if ($('body').attr('id') == 'stage') {
		$('dl').each(function(){
			$('dt:first',this).css('border',0)
		})
		$('#past li').filter(function(){
			return $(this).index() % 4 == 0
		}).before('<br class="clear">')
		$('h3 img').click(function(){
			$(this).attr('src',$(this).attr('src').replace('_gray.','_color.')).siblings().each(function(){
				$(this).attr('src',$(this).attr('src').replace('_color.','_gray.'))
			})
			$('#' + $(this).attr('src').split('/title_').pop().replace('_color.png','')).show().siblings('div').hide()
		})
	}
	
	//picture
	else if ($('body').attr('id') == 'picture') {
		$('table').each(function(){
			$('tr:last > td',this).addClass('last')
		})
		$('#package div.box').each(function(){
			$('div',this).filter(function(){
				return $(this).index() % 3 == 0
			}).before('<br class="clear">')
		})
		$('h3 img').click(function(){
			$(this).attr('src',$(this).attr('src').replace('_gray.','_color.')).siblings().each(function(){
				$(this).attr('src',$(this).attr('src').replace('_color.','_gray.'))
			})
			$('#' + $(this).attr('src').split('/title_').pop().replace('_color.png','')).show().siblings('div').hide()
		})
		$('#main a').click(function(){
			if (this.href.indexOf('www.e-fanclub.com/cube/webshop') > 0) {
				window.open(this.href, 'webshop','toolbar=0,location=no,status=no,menubar=no,scrollbars=yes,width=480,height=600')
				return false
			}
		})
	}
	
})

