
$(function(){
	// Go Top
	$('a.move').click(function() {
		var targetY = $($(this).attr('href')).offset().top;
		if (targetY < 0) {
			targetY = 0;
		}
		$('html,body').animate({scrollTop: targetY}, 1000, 'swing');
		return false;
	});
	
	$('nav.ep_navi').find('li a').hover(function() {
		naviPopUp(this, '#' + $('nav.ep_navi').attr('id'));
	} , function() {
		naviPopUpHide();
	});
	
	$('p[id^=res] a[href^=#res]').hover(function() {
		popUp(this, $(this).attr('href'));
	}, function() {
		hidePop('#res_popup');
	});
	
	$('a[rel*=lightbox]').lightBox();
	
});

function naviPopUp(obj, id) {
	var title = $(obj).attr('title');
	var top = $(obj).offset().top - $(id).offset().top - 35;
	$(id).append('<div id="navi_popup"></div>');
	$('#navi_popup').append(title).css('top', top).hide().fadeIn();
}
function naviPopUpHide() {
	$('#navi_popup').remove();
}

/* レスポップアップ
===========================*/

function popUp(obj, resId) {
	
	x = $(obj).offset().left;
	y = $(obj).offset().top;
		
	var res = $(resId);
	var popup = $('#res_popup');
	
	if (res.html() == null) {
		return;
	}
	
	// レスの高さ取得
	var height = res.outerHeight();

	// レス追加
	popup.append('<p id="res_child">' + res.html() + '</p>');
	
	var thread_left = $('#thread').offset().left;
	var thread_top = $('#thread').offset().top;
	
	popup.css('left', x - thread_left + "px");
	popup.css('top', y - thread_top  - (height + 30) + "px");
	
	popup.show();
	
}

function popUpComment(obj, resId) {

	x = $(obj).offset().left;
	y = $(obj).offset().top;
	
	var res = $(resId);
	var popup = $('#comment_popup');
	
	if (res.html() == null) {
		return;
	}
	
	// レスの高さ取得
	var height = res.outerHeight();

	// レス追加
	popup.append('<div id="res_child">' + res.html() + '</div>');
	
	var com_left = $('#comments').offset().left;
	var com_top = $('#comments').offset().top;
	
	popup.css('left', x - com_left + "px");
	popup.css('top', y - com_top  - (height + 30) + "px");
	
	popup.show();
	
}

function hidePop(id) {

	$('#res_child').remove();
	$(id).hide();
	
}

function execMessage(flag, html) {

	var obj = $('#exec_message');
	if (flag == 1) {
		obj.html(html);
		obj.slideDown(300);
	} else {
		obj.slideUp(300);
	}
}

