var lightbox_flag = false

$(function(){
	var body_id = $('body').attr('id')
	
	$('a').click(function() {
		var my_class = $(this).attr('class')
		if (my_class == 'youtube' || my_class == 'load') {
			lightbox($(this).attr('href'),my_class)
			return false
		}
	}).find('img').hover(function(){
		$(this).css('opacity',0.7)
	},function(){
		$(this).css('opacity',1)
	})
	
	$('#nav li.' + body_id + ' img').each(function(){
		$(this).attr('src',$(this).attr('src').replace('nav_','nav_this_'))
	})

	$('body').append('<div id="overlay_bg" class="overlay"></div><table id="lightbox"><tr><td><table><tr><td id="lightbox_me"></td></tr></table><img src="common/img/btn_close.png" id="close_btn" width="80" height="16" /></td></tr></table><p id="close"><img src="common/img/btn_close2.png" alt="CLOSE" width="50" height="50"></p>')
	$('#close_btn,#close > img').click(close_lightbox)

	//top
	if (body_id == 'top') {
		$('#wrap').bind("contextmenu",function(){
			return false
		})
	}

	//discography
	else if (body_id == 'discography') {
		$('#contents a.buy').click(function(){
			if ($(this).attr('href') == '') {
				$('+span',$(this)).toggleClass('show')
				return false
			}
		})
	}
	$(window).resize(resize_lightbox)
	$('img').bind("contextmenu",function(){
		return false
	})
})

function lightbox(href,type){
	lightbox_flag = true
	$('#contents').data('scrollTop',$(document).scrollTop())
	if (type == 'youtube')
		$('#lightbox_me').html('<p id="youtube"><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/' + href + '&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/' + href + '&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>')
	else (type == 'load')
		$('#lightbox_me').load(href,function(){
			$(($.browser.msie && $.browser.version == 6) ? '#close_btn' : '#close').show()
		})
	resize_lightbox()
	if (type == 'youtube')
		$('#youtube,#close_btn').fadeIn(1000)
}
function close_lightbox(){
	lightbox_flag = false
	$(document).scrollTop($('#contents').data('scrollTop'))
	$('#lightbox_me').text('')
	$('#lightbox,#overlay_bg,#close,#close_btn').hide()
}
function resize_lightbox(){
	if (lightbox_flag) {
		$('#lightbox').show().css('top',$(document).scrollTop()).height($(window).height())
		$('#overlay_bg').show().css({opacity:0.85}).width($(window).width() < 960 ? $(document).width() : '100%').height($(document).height())
	}
}

