/*===================================================================

@fileoverview

 Created:		2010-09-26 Yuji Hisamatsu
 Last update:	2011-03-24
 Style Info:	共通JS
 File name:		site.js

@description

 + page scroll
 + product series pulldown
 + table style
 + dialog box
 + window open

===================================================================*/
jQuery.easing.quart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

$(document).ready(function(){
/*-------------------------------------
	page scroll
-------------------------------------*/
	$('a[href*=#],area[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({ scrollTop: targetOffset }, 1200, 'quart');
				return false;
			}
		}
	});
/*-------------------------------------
	product series pulldown
-------------------------------------*/
	$('#globalNvArea li').hover(
		function(){
			$("> ul:not(:animated)", this).css({visibility: "visible",display: "none"}).show(300);
		},
		function() {
			$("> ul" , this).fadeOut("fast");
		}
	);

/*-------------------------------------
	table style
-------------------------------------*/
	$("table.tb-zebra").each(function(){
		$(this).find("tr:even").addClass("even");
	});

/*------------------------------------
	dialog box
------------------------------------*/
	$("a.eq-window").click(function(e) {
		var $link = $(this);
		var name = $link.attr("name");
		var content = $('.bw-' + name).html();
		
		$("body").prepend('<div id="wall"></div>');
		$("body").prepend('<div id="popup" class="box-content">' + content + '</div>');
		$('#popup').css({
						 position:"absolute",
						 display:"block"
						 });
		$('#popup').append('<p id="close">close</p>');
		$('#popup dt').attr('id', 'titleBar');
		
		$('#close, #wall').click(function() {
			$('#popup').fadeOut("slow");
			$('#popup').remove();
			$('#wall').remove();
		});

		var wx, wy;
		var mx, my;	
		wx = $(this).scrollLeft() + ($(window).width() - $('.bw-' + name).outerWidth()) / 2;
		if (wx < 0) wx = 0;
		wy = $(this).scrollTop() + ($(window).height() - $('.bw-' + name).outerHeight()) / 2;
		if (wy < 0) wy = 0;
		$('#popup').css('top', wy).css('left', wx).fadeIn('slow');

		$('#titleBar').mousedown(function(e) {
			mx = e.pageX;
			my = e.pageY;
			$(this).mousemove(mouseMove).mouseup(mouseUp);
			return false;
		});
		function mouseMove(e) {
			wx += e.pageX - mx;
			wy += e.pageY - my;
			$('#popup').css('top', wy).css('left', wx);
			mx = e.pageX;
			my = e.pageY;
			return false;
		}
		function mouseUp() {
			$(this).unbind('mousemove', mouseMove).unbind('mouseup', mouseUp);
		}
 
		return false;
	});

	
})
/*------------------------------------
	window open
------------------------------------*/
function openwin(url) {
	window.open(url, "popup", "scrollbars=yes,width=740,height=600");
}

