# linkthumb.rb
# Copyright (C) 2006  Michitaka Ohno <elpeo@mars.dti.ne.jp>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

add_header_proc do
	<<-HTML
<script type="text/javascript"><!--
function linkthumb(){
	var nophoto='http://img.simpleapi.net/img/nophoto.gif';
	var img=document.createElement('img');
	img.src=nophoto;
	img.onmouseout=function(){
		img.src=nophoto;
		img.style.display='none';
	};
	img.style.position='absolute';
	img.style.cursor='pointer';
	img.style.display='none';
	document.body.appendChild(img);
	var d=document.getElementsByTagName('div');
	for(var j=0;j<d.length;j++){
		if(d[j].className!='body') continue;
		var a=d[j].getElementsByTagName('a');
		for(var i=0;i<a.length;i++){
			if(!a[i].href.match(/^http:/)) continue;
			if(a[i].href.match("^#{Regexp.escape( @conf.base_url )}")) continue;
			a[i].onmouseover=function(e){
				var link=this.href;
				var thumb='http://img.simpleapi.net/small/'+link;
				img.onmouseover=function(){
					img.src=thumb;
					img.style.display='block';
				};
				img.onclick=function(){
					location.href=link;
				};
				if(document.all){
					img.style.left=document.documentElement.scrollLeft+event.x+"px";
					img.style.top=document.documentElement.scrollTop+event.y+"px";
				}else{
					img.style.left=e.pageX+"px";
					img.style.top=e.pageY+"px";
				}
				img.src=thumb;
				img.style.display='block';
			};
			a[i].onmouseout=img.onmouseout;
		}
	}
}
if(window.addEventListener){
	window.addEventListener('load',linkthumb,false);
}else if(window.attachEvent){
	window.attachEvent('onload',linkthumb);
}else{
	window.onload=linkthumb;
}
// --></script>
HTML
end
