/* メイン処理 */
//	サムネイルの一辺のサイズをセット（正方形が前提）
var	thumbnailSize = 256;

var	positionX;
var	positionY;
var	box = document.createElement('div');		// popup用div要素作成

window.onload = get_links;						// イベントハンドラ設定
document.onmousemove = get_mouse;				// イベントハンドラ設定

/* 関数 */
/* 特定の要素内に存在するa要素について */
/* onmouseoverイベントを追加 */
function	get_links(){
	var	links = document.getElementsByTagName("a");
												// ページ内全てのa要素を抽出

	for(var i=0;i<links.length;i++ ){			// a要素の数だけ繰り返し
		if(
//			links[i].protocol=="http:" &&		// http:なら
			links[i].className!="keyword" &&	// class="keyword"は除外
			links[i].getAttribute("rel")!="nothumbnail"
												// rel="nothumbnail"は除外
		){
			links[i].onmouseover= thumbnail_popup;
			links[i].onmouseout	= thumbnail_close;
			links[i].onclick	= thumbnail_close;
												// 全てのa要素にイベントハンドラ設定
		}
	}
}
/* マウスカーソル座標取得 */
function	get_mouse(e){
	if(window.opera){
		positionX = e.pageX;
		positionY = e.pageY;
		myX = e.clientX;
		myY = e.clientY;
	}
	else
	if(document.all){
		positionX = document.body.scrollLeft+ event.clientX;
		positionY = document.body.scrollTop + event.clientY;
		myX = event.clientX;
		myY = event.clientY;
	}
	else
	if(document.layers||document.getElementById){
		positionX =  e.pageX;
		positionY =  e.pageY;
		myX = e.clientX;
		myY = e.clientY;
	}
	else{
		positionX = -thumbnailSize/2;
		positionY =  thumbnailSize/2;
	}

	with( box.style ){
		if( myY >= GetWindowSize("height")/2 ){
			top = positionY - thumbnailSize + 'px';
		}
		else{
			top = positionY + 'px';
		}

		if( myX >= GetWindowSize("width")/2 ){
			left= positionX - thumbnailSize*1.25 + 'px';
		}
		else{
			left= positionX + thumbnailSize/4 + 'px';
		}
	}
}

function GetWindowSize(type){
	switch(type){
	case "width":
		if(window.opera){
			return( innerWidth );
		}
		else
		if( document.all ){
			return( document.body.clientWidth );
		}
		else
		if(document.layers||document.getElementById){
			return( innerWidth );
		}
		else{
			return(-1);
		}
		break;

	case "height":
		if(window.opera){
			return( innerHeight );
		}
		else
		if( document.all ){
			return( document.body.clientHeight );
		}
		else
		if(document.layers||document.getElementById){
			return( innerHeight );
		}
		else{
			return(-1);
		}
		break;

	default:
		return(-1);
		break;
	}
}
function	thumbnail_popup(){
	if( document.getElementById("thumbnail")!=null ){
		thumbnail_close();
		return	0;
	}

	var	body = document.getElementsByTagName("body")[0];

	box = document.createElement('div');		// エレメント初期化
	box.id = 'thumbnail';
	with( box.style ){
		position = 'absolute';
		display = 'block';
		zIndex = '60';
	}

	body.appendChild(box);

	var	img = document.createElement('img');
	img.id = 'popupImage';
//	どっちのサービスを使う？
//	↓SimpleAPI	IEベース
//	img.src = 'http://img.simpleapi.net/small/' + this.href;
//	↓Mozshot	Mozillaベース
	img.src = 'http://mozshot.nemui.org/shot/large?' + this.href;
	img.alt = this.innerHTML;
	img.title = this.innerHTML;

	box.appendChild(img);

//	this.onmouseout = thumbnail_close;
}
function	thumbnail_close(){
	box.style.display = 'none';

	var	body = document.getElementsByTagName("body")[0];
	body.removeChild(box);
}

/* WEB拍手用 */
function	WebClap(){
	win = window.open("http://webclap.simplecgi.com/clap.php?id=tmfactory","new","width=640,height=480");
}
