/////////////////////////////////////////////////////////////////////////////////
// あひあひ for Web Ver0.1b
//    Copyright(C) all rights reserved, 2007 がぁも研究員
/////////////////////////////////////////////////////////////////////////////////

// 変数宣言
var nPosX		= 100 ;
var nPosY		= 100 ;
var	nFlag		= 0 ;
var nItemCount	= 6 ;
//var nGaxamo		= 0 ;
var nWidth		= 48 ;
var nHeight		= 48 ;
var nScreenWidth = 0 ; 	// 070822
var nScreenHeight = 0 ;	// 070823

// ボタンの表示
//document.write( '<img src="http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/LogoIroIroAhi.gif" onClick="GaxamoAhiAhiInit()">' ) ;
// 自動起動
window.onload = GaxamoAhiAhiInit ;

function GaxamoAhiAhiInit()
{
// 変数宣言
	var nTimeSpan	= 5000 ;
// 起動中フラグの確認
	if ( 0 != nFlag ) {	return ; }
	nFlag	= 1 ;
// 新しいオブジェクトを作成
	var oAhiahi 	= document.createElement( "img" ) ;
	oAhiahi.setAttribute( "id",  "AhiAhi" ) ;
	oAhiahi.setAttribute( "src", "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/OshaberiAhi.gif" ) ;
	document.body.appendChild( oAhiahi ) ;
// スクリーン幅の獲得 //070822
	nScreenWidth 	= document.documentElement.clientWidth ;
	if ( 0 == nScreenWidth ) {
		nScreenWidth = document.body.clientWidth ;
	}
// スクリーン幅の獲得 //070822
	nScreenHeight	= document.documentElement.clientHeight ;
	if ( 0 == nScreenHeight ) {
		nScreenHeight	= document.body.clientHeight ;
	}
// デバッグ用
//window.status= "Pos :  (" + document.documentElement.clientWidth + "," + document.body.clientWidth + ")-(" + document.documentElement.clientHeight + "," + document.body.clientHeight + ")"  ; 
// 表示
	nPosY		= document.documentElement.scrollTop ;
	if ( 0	== nPosY ) {	//070823
		nPosY		= document.body.scrollTop ;
	}
	nPosX		= document.documentElement.scrollLeft ;
	if ( 0	== nPosX ) {	// 070823
		nPosX		= document.body.scrollLeft ;
	}
//070823	nPosY		+= Math.random() * ( document.documentElement.clientHeight - nHeight ) ;
	nPosY		+= Math.random() * ( nScreenHeight - nHeight ) ;
//070822	nPosX		+= Math.random() * ( document.documentElement.clientWidth  - nWidth ) ;
	nPosX		+= Math.random() * ( nScreenWidth  - nWidth ) ;
	document.getElementById( "AhiAhi" ).style.position	= "absolute" ;
	document.getElementById( "AhiAhi" ).style.left		= nPosX ;
	document.getElementById( "AhiAhi" ).style.top		= nPosY ;
// タイマーのセット
	setInterval( "GaxamoAhiAhiChangeImage()", nTimeSpan );
}

function GaxamoAhiAhiChangeImage()
{
// 次の表示アイテムを設定
	var nGaxamo	;
	nGaxamo		= Math.floor( nItemCount * Math.random() ) ;
	if ( nItemCount	<= nGaxamo ) { nGaxamo = 0 ; }
// 新しい場所に画像を表示
	switch ( nGaxamo ) {
		case 0 : document.getElementById( "AhiAhi" ).src = "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/OshaberiAhi.gif" ;	break ;
		case 1 : document.getElementById( "AhiAhi" ).src = "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/ZzzAhi.gif" ;		break ;
		case 2 : document.getElementById( "AhiAhi" ).src = "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/FuriFuriAhi.gif" ;	break ;
		case 3 : document.getElementById( "AhiAhi" ).src = "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/KaikaiAhi.gif" ;		break ;
		case 4 : document.getElementById( "AhiAhi" ).src = "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/KuuAhi.gif" ;		break ;
		case 5 : document.getElementById( "AhiAhi" ).src = "http://homepage2.nifty.com/gaxamo/WebAhi/AhiAhi/Images/MoguAhi.gif" ;		break ;
	}
// 表示位置の作成
	nPosY		= document.documentElement.scrollTop ;
	if ( 0	== nPosY ) {	//070823
		nPosY		= document.body.scrollTop ;
	}
	nPosX		= document.documentElement.scrollLeft ;
	if ( 0	== nPosX ) {	// 070823
		nPosX		= document.body.scrollLeft ;
	}
//070823		nPosY		+= Math.random() * ( document.documentElement.clientHeight - nHeight ) ;
	nPosY		+= Math.random() * ( nScreenHeight - nHeight ) ;
//070822	nPosX		+= Math.random() * ( document.documentElement.clientWidth  - nWidth ) ;
	nPosX		+= Math.random() * ( nScreenWidth  - nWidth ) ;

	document.getElementById( "AhiAhi" ).style.position	= "absolute" ;
	document.getElementById( "AhiAhi" ).style.left		= nPosX + "px";
	document.getElementById( "AhiAhi" ).style.top		= nPosY + "px" ;
// デバッグ用
//window.status= "Pos :  (" + nPosX + "," + nPosY + "," + nGaxamo + ")-" ; 
//	window.status= "Pos :  (" + document.body.clientWidth + "," + document.body.clientHeight + ")-(" + document.documentElement.clientWidth + "," + document.documentElement.clientHeight +")-(" + document.body.scrollLeft + "," + document.body.scrollTop +")-(" + nPosX + "," + nPosY +")" ; 
//window.status= "Pos :  (" + document.documentElement.clientWidth + "," + document.body.clientWidth + ")-(" + document.documentElement.clientHeight + "," + document.body.clientHeight + ")"  ; 
}

