
$(function() {
	
	pageID = $('body').attr('id')
	
	//ページTOPにスクロールして戻るリンク
	$('p.pagetop a').click(function() {
		if ($('html').scrollTop() != 0 || $('body').scrollTop() != 0)
			$('html,body').animate({scrollTop:0},1000,'easeOutQuart')
		return false
	})
	
	//外部サイトへのリンクにtarget="_blank"を
	$('#post a').each(function() {
		var href = $(this).attr('href')
		if (href.indexOf('http') == 0 && href.indexOf(location.host) == -1)
			$(this).attr('target','_blank')
	})
	
	//画像上の右クリック禁止
	$('img,map').bind("contextmenu",function() {
		return false
	})
	
	//グローバルナビゲーション
	var $nav_a = $('#nav a[class!="this"]')
	$('#nav').mouseout(function() {
		$nav_a.removeClass()
	})
	$nav_a.hover(function() {
		$(this).addClass('this')
	},function() {
		$(this).removeClass()
	})
	
	//以下、ページ毎の処理
	if (pageID == 'home') {
		$(window).load(function() {
			if (location.href.indexOf('/#/') > 0) {
				$('#contents,#main').bind("contextmenu",function() { return false })
				$('#topics').prepend(music)
				$('div,h2,p,address').css({visibility:'visible',display:'block'})
			} else {
				$('<img src="img/home100726.jpg">').load(function() {
					$('<div id="logo" class="overlay"></div>').appendTo('body').height($(document).height()).fadeIn(1500,function() {
						$('#top').fadeIn(function() {
							$('#logo').fadeOut(1000)
							$(this).animate({opacity:0},1500,'easeInQuint',function() {
								$(this).fadeTo(0,1)
								$('#contents,#main').bind("contextmenu",function(){return false}).css({visibility:'visible',display:'block'})
								$('#banner,#copyright,#release,#hotnews').show()
								$('<div id="white" class="overlay"></div>').appendTo('body').height($(document).height()).fadeOut(1000,function() {
									$('#topics').prepend(music).show()
								})
							})
						})
					})
				})
			}
		})
	}
	
	else if (pageID == 'live' && $('#archive').length == 1) {
		var $archive_h3 = $('#archive h3')
		var year = $archive_h3.eq(0).text().slice(0,4)
		
		$('#archive h2').after('<p class="year first">' + year + '年</p>')
		var n = $('#archive h3').length
		for(var i = 1; i < n; i++) {
			var $this = $archive_h3.eq(i)
			if ($this.text().slice(0,4) != year) {
				year = $this.text().slice(0,4)
				$this.before('<p class="year">' + year + '年</p>')
			}
		}
	}

	else if (pageID == 'mail_mobile') {
		$('#m1335 div a').text('weaver@mailmag.amuse.co.jp')
		$('#m1337 strong').text('http://www.weavermusic.jp/')
	}
	
	else if (pageID == 'discography') {
		function youtube_open(id) {
			$('#youtube_me').html('<p><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/' + id + '&hl=ja_JP&fs=0&autoplay=1&egm=1&border=0&rel=0&showinfo=0&ap=%2526fmt%3D22&showsearch=0"></param><param name="wmode" value="transparent" /><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + id + '&hl=ja_JP&fs=0&autoplay=1&egm=1&border=0&rel=0&showinfo=0&ap=%2526fmt%3D22&showsearch=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent allowfullscreen="true" width="640" height="385"></embed></object></p>')
			$('#youtube').show().css('top',$(document).scrollTop()).height($(window).height())
			$('#overlay').show().css({opacity:0.7}).height(Math.min($(document).height(),2000))
			if ($('#overlay').height() == 2000)
				$('#overlay2').show().css({opacity:0.7}).height($(document).height()-2000).css('top',2000)
			$('#youtube_me p').fadeIn(1000)
		}
		function youtube_close() {
			$('#youtube_me').html('')
			$('#youtube,#overlay,#overlay2').hide()
		}
		$('body').append('<div id="sound"></div><div id="overlay" class="overlay"></div><div id="overlay2" class="overlay"></div><table id="youtube"><tr><td><table><tr><td id="youtube_me"></td></tr></table><img src="img/lightbox_close.png" class="close" width="100" height="20" /></td></tr></table>')
		$('td.youtube a').click(function() {
			youtube_open($(this).attr('href'))
			$('#sound').html('')
			$('img',this).attr('src','img/movie.png')
			$sound_img.filter('[src$="sound.gif"]').attr('src','img/sound.png')
			return false
		}).hover(function() {
			$('img',this).attr('src','img/movie_o.png')
		},function() {
			$('img',this).attr('src','img/movie.png')
		})
		$('#youtube img').css({opacity:0.5}).hover(function() {
			$(this).css({opacity:0.7})
		},function() {
			$(this).css({opacity:0.5})
		}).click(function() {
			youtube_close()
			return false
		})
		$sound_img = $('td.sound img')
		$('td.sound a').click(function() {
			if ($('img',this).attr('src').indexOf('sound.gif') >= 0) {
				$('#sound').html('')
				$('img',this).attr('src','img/sound.png')
			} else {
				$('#sound').html('<i><object data="swf/sound_discography.swf?1&file=' + $(this).attr('href') + '" width="1" height="1" type="application/x-shockwave-flash"><param name="movie" value="swf/sound_discography.swf?1&file=' + $(this).attr('href') + '" /></i>')
				$sound_img.filter('[src$="sound.gif"]').attr('src','img/sound.png')
				$('img',this).attr('src','img/sound.gif')
			}
			return false
		}).hover(function() {
			if ($('img',this).attr('src').indexOf('sound.gif') == -1)
				$('img',this).attr('src','img/sound_o.png')
		},function() {
			if ($('img',this).attr('src').indexOf('sound.gif') == -1)
				$('img',this).attr('src','img/sound.png')
		})
	}
})

//Flash MP3プレイヤーからの合図を受けとる関数
function on_sound_complete() {
	$sound_img.filter('[src$="sound.gif"]').attr('src','img/sound.png')
	$('#sound').html('')
}
