/*
 * common.js
 * depends jquery.js (v1.3.2) + jquery.easing.js;
 *
 */


// セレクタ拡張
$.extend($.expr[':'], {

	// 外部リンク
	external: function(a,i,m) {
		if (!a.href) {
			return false;
		}
		return a.hostname && a.hostname !== window.location.hostname;
	}

});


// メソッド拡張
$.fn.extend({

	// 新規ウィンドウを開く
	openWindow: function() {
		$(this).click(function() {
			window.open(this.href);
			return false;
		});
	},

	tooltip: function () {
		return this.each(function () {
			var container = $(this);
			var tooltip = $(this).attr('href');
			$(tooltip).prepend(
				$('<p/>').addClass('close').append(
					$('<img/>').attr({
						src: '/common/img/close.gif',
						alt: '閉じる',
						width: 90,
						height: 31
					})
				)
			);
			var w = $(tooltip).width();
			var h = $(tooltip).height();
			$(this).click(function (e) {
				$(tooltip).show().css({
					position: 'absolute',
					left: e.pageX + (- w - 50),
					top: e.pageY + (- h - 30)
				});
				return false;
			});
			$(tooltip).find('.close').click(function () {
				$(tooltip).hide();
			});
		});
	}

});

$(function() {

	$('.help_tooltip').tooltip();

	// JavaScript 有効判定
	$('body').addClass('js-enabled');

	// ブラウザ判別
	var browserName;
	var browserVer;
	if ($.browser.msie) {
		browserName = 'msie';
		switch ($.browser.version) {
			case '6.0': browserVer = 'v6'; break;
			case '7.0': browserVer = 'v7'; break;
			case '8.0': browserVer = 'v8'; break;
			default: browserVer = 'v5';
		}

		$('body').addClass(browserVer);
	} else if ($.browser.mozilla) {
		browserName = 'mozilla';
	} else if ($.browser.safari) {
		browserName = 'safari';
	} else if ($.browser.opera) {
		browserName = 'opera';
	} else {
		browserName = 'unknown';
	}
	$('body').addClass(browserName);

	// リンク
	$('a:external').addClass('external').openWindow();
	$('a[href$=".pdf"]').addClass('pdf').openWindow();
	$('a[href$=".zip"]').addClass('zip');
	$('a[href$=".exe"]').addClass('exe');
	$('a[href^="https:"]').addClass('https');
	$('a[href^="ftp:"]').addClass('ftp');
	$('a[href^="mailto:"]').addClass('mailto');

	// ロールオーバー
	$('.over').each(function() {
		this.defaultSrc = $(this).attr('src');
		this.hoverSrc = this.defaultSrc.replace(/(\.gif|\.jpg|\.png)/, '_on$1');
		this.hoverImg = new Image;
		this.hoverImg.src = this.hoverSrc;
	}).hover(function() {
		$(this).attr('src', this.hoverSrc);
	}, function() {
		$(this).attr('src', this.defaultSrc);
	});

	// スクロール
	if (!$.browser.opera) {
		$('.pageTOP > a').click(function() {
			$('html, body').animate({scrollTop: 0}, 600, 'easeOutExpo');
			return false;
		});
		$('.way01 > a').click(function() {
			$('html, body').animate({scrollTop: 396}, 600, 'easeOutExpo');
			return false;
		});
		$('.way02 > a').click(function() {
			$('html, body').animate({scrollTop: 2659}, 600, 'easeOutExpo');
			return false;
		});

		$('[href^="#"]:not(.pageTOP > a):not(.stepOther > a):not(.help_tooltip)').click(function() {
			if ($.browser.msie && $.browser.version == 7.0) return; // IE7では処理しない*不具合がある為
			var targetOffset = $(this.hash).offset().top;
			var documentHeight = $(document).height();
			var windowHeight = $(window).height();
			if ((documentHeight - targetOffset) < windowHeight) {
				targetOffset = (documentHeight - windowHeight);
			}
			$('html, body').animate({scrollTop: targetOffset}, 600, 'easeOutExpo');
		});
	}

});





// ポップアップ

function print01(strURL){
win=window.open(strURL,"NewsRelease","menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,width=640,height=500");
win.focus();
}
