<!--// <![CDATA[
/**************************************************
 *
 *	@name			base.js
 *	@facility		ウェブサイト用基本処理
 *	@created date	2009/12/16
 *	@copyright (c) 2009 COCONOE inc.
 *
 *	[更新履歴]
 *	@v1.0		:	2009/12/16	:	基本処理用に独立させました
 *	@v1.1		:	2009/12/22	:	setGoogleAnalytics追加
 *	@v1.2		:	2010/02/08	:	openWindow追加
 *
 *	[使用方法]
 *	・func.jsが必要です
 *
 **************************************************/
var VER				= 1.1;

var HOST_REG		= new RegExp( "^http(?:s)?:\/\/([^\/]*)", "gi" );
var computedStyle;

var nowX = 0;
var nowY = 0;
var scrollTimer;
var stageHeight;

function getComptedStyle()
{
	if( window.getComputedStyle )
	{
		computedStyle = function( elm, prop )
		{
			return window.getComputedStyle( elm, null )[ prop ];
		}
	}
	else if( document.body.currentStyle )
	{
		computedStyle = function( elm, prop )
		{
			return elm.currentStyle[ prop ];
		}
	}
}

/**************************************************
 *
 *	アンカーのhrefを別ドメインなら別ウィンドウで表示させる(ウィンドウ名もドメイン毎に作る)。
 *
**************************************************/
function replaceAnchor()
{
	var aNodes = document.getElementsByTagName( 'a' );
	var node;
	
	for( var i=0, l=aNodes.length; i<l; i++ )
	{
		node = aNodes[i];
		
		if( node.className == "totop" || node.id == "totop" )
		{
			node.onclick = function()
			{
				toTop();
				return false;
			}
		}
		else if( node.className == "ext" || ( node.href.match( HOST_REG ) && RegExp.$1 != HOST_NAME ))
		{
			node.onclick = function()
			{
				openWindow( this.href );
				return false;
			}
		}
	}
}

function openWindow( url )
{
	url.search( HOST_REG );
	var hostName = ( RegExp.$1 ).replace( /(?:-|\.)/g, "" );
	window.open( url, hostName );
	return false;
}

/**************************************************
 *
 *	Google Analyticsのタグを挿入する
 *
 * id : GoogleAnalyticsのID		ex) UA-749000-1
 *
**************************************************/
function setGoogleAnalytics( id )
{
	if ( id == undefined || LOCAL )
	{
		return;
	}
	
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); 
	var jsA = document.createElement( 'script' );
	jsA.src = gaJsHost + "google-analytics.com/ga.js";
	jsA.type = "text/javascript";
	document.body.appendChild( jsA );
	
	startGoogleAnalytics( id );
}

function startGoogleAnalytics( id )
{
	try
	{
		var pageTracker = _gat._getTracker( id );
	//	pageTracker._initData();
		pageTracker._trackPageview();
	}
	catch( e )
	{
		setTimeout( function(){ startGoogleAnalytics( id ); }, 100 );
	}
}

/**************************************************
 *
 *	トゥイーンでページの先頭にもどる
 *
**************************************************/
function toTop()
{
	frameScroll( 0, 0.3 );
	return false;
}

function frameScroll( toY, a )
{
	var view_area = getViewportArea();
	var doc_area = getDocumentArea();

	nowX = view_area.x;
	nowY = view_area.y;
	nowH = view_area.h;
	docH = doc_area.h;

	if(toY.isNaN) toY = nowY;

	toY = (toY > (docH - nowH)) ? (docH - nowH) : toY;

	if(!toY || toY < 0) toY = 0;

	toY = Math.ceil(toY);

	frameScrollEvent( toY, a );
}

function stopFrameScroll()
{
	clearTimeout(scrollTimer);
}

function frameScrollEvent( toY, a )
{
	var num = 0;
	if( scrollTimer ) clearTimeout( scrollTimer );
	
	nowY += (toY - nowY) * a;
	
	if((((toY - nowY) > 0) ? (toY - nowY) : (nowY - toY)) < 2)
	{
		nowY = toY;
		clearTimeout(scrollTimer);
	}
	else
	{
		scrollTimer = setTimeout("frameScrollEvent( "+toY+", "+a+" )", 10);
	}
	
	window.scroll( nowX, nowY );
}

//]]>-->

