/*
link-preview v1.4 by frequency-decoder.com

Released under a creative commons Attribution-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-sa/2.5/)

Please credit frequency-decoder in any derivative work - thanks.

You are free:

* to copy, distribute, display, and perform the work
* to make derivative works
* to make commercial use of the work

Under the following conditions:

by Attribution.
--------------
You must attribute the work in the manner specified by the author or licensor.

sa
--
Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

* For any reuse or distribution, you must make clear to others the license terms of this work.
* Any of these conditions can be waived if you get permission from the copyright holder.

References:
        
mythumbshot: http://www.mythumbshot.com
Dustan Diaz: http://www.dustindiaz.com/sweet-titles-finalized
Arc90: http://lab.arc90.com/2006/07/link_thumbnail.php
*/
var mythumbshot = {
x:0,
y:0,
obj:{},
img:null,
lnk:null,
timer:null,
opacityTimer:null,
errorTimer:null,
hidden:true,
linkPool: {},
baseURI: "./",
imageCache: [],
init: function() {
var lnks = document.getElementsByTagName('a');
var i = lnks.length || 0;
var cnt = 0;
while(i--) {
if(lnks[i].className && lnks[i].className.search(/mythumbshot/) != -1) {
mythumbshot.addEvent(lnks[i], ["focus", "mouseover"], mythumbshot.initThumb);
mythumbshot.addEvent(lnks[i], ["blur",  "mouseout"],  mythumbshot.hideThumb);
mythumbshot.linkPool[lnks[i].href] = cnt++;
}
}
if(cnt) {
mythumbshot.preloadImages();
mythumbshot.obj = document.createElement('div');

mythumbshot.ind = document.createElement('div');
mythumbshot.ind.className= "imageLoaded";
mythumbshot.img = document.createElement('img');
mythumbshot.img.alt = "preview";
mythumbshot.img.id = "fdImage";
mythumbshot.addEvent(mythumbshot.img, ["load"], mythumbshot.imageLoaded);
mythumbshot.addEvent(mythumbshot.img, ["error"], mythumbshot.imageError);
mythumbshot.obj.id = "fdImageThumb";
mythumbshot.obj.style.visibility = "hidden";
mythumbshot.obj.style.top = "0";
mythumbshot.obj.style.left = "0";
mythumbshot.addEvent(mythumbshot.img, ["mouseout"],  mythumbshot.hideThumb);
mythumbshot.obj.appendChild(mythumbshot.ind);
mythumbshot.obj.appendChild(mythumbshot.img);
mythumbshot.addEvent(mythumbshot.obj, ["mouseout"], mythumbshot.hideThumb);
document.getElementsByTagName('body')[0].appendChild(mythumbshot.obj);
}
},
preloadImages: function() {
var imgList = ["lt.png", "lb.png", "rt.png", "rb.png", "error.gif", "loading.gif"];
var imgObj  = document.createElement('img');

for(var i = 0, img; img = imgList[i]; i++) {
mythumbshot.imageCache[i] = imgObj.cloneNode(false);
mythumbshot.imageCache[i].src = mythumbshot.baseURI + img;
}
},
imageLoaded: function() {
if(mythumbshot.errorTimer) clearTimeout(mythumbshot.errorTimer);
if(!mythumbshot.hidden) mythumbshot.img.style.visibility = "visible";
mythumbshot.ind.className= "imageLoaded";
mythumbshot.ind.style.visibility = "hidden";
},
imageError: function(e) {
if(mythumbshot.errorTimer) clearTimeout(mythumbshot.errorTimer);
mythumbshot.ind.className= "imageError";
mythumbshot.errorTimer = window.setTimeout("mythumbshot.hideThumb()",2000);
},
initThumb: function(e) {
e = e || event;

mythumbshot.lnk       = this;
var positionClass  = "left";

var heightIndent;
var indentX = 0;
var indentY = 0;
var trueBody = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;

if(String(e.type).toLowerCase().search(/mouseover/) != -1) {
if (document.captureEvents) {
mythumbshot.x = e.pageX;
mythumbshot.y = e.pageY;
} else if ( window.event.clientX ) {
mythumbshot.x = window.event.clientX+trueBody.scrollLeft;
mythumbshot.y = window.event.clientY+trueBody.scrollTop;
}
indentX = 10;
heightIndent = parseInt(mythumbshot.y-(mythumbshot.obj.offsetHeight))+'px';
} else {
var obj = this;
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
}
curtop += this.offsetHeight;

mythumbshot.x = curleft;
mythumbshot.y = curtop;

heightIndent = parseInt(mythumbshot.y-(mythumbshot.obj.offsetHeight)-this.offsetHeight)+'px';
}
                
if ( parseInt(trueBody.clientWidth+trueBody.scrollLeft) < parseInt(mythumbshot.obj.offsetWidth+mythumbshot.x) + indentX) {
mythumbshot.obj.style.left = parseInt(mythumbshot.x-(mythumbshot.obj.offsetWidth+indentX))+'px';
positionClass = "right";
} else {
mythumbshot.obj.style.left = (mythumbshot.x+indentX)+'px';
}
if ( parseInt(trueBody.clientHeight+trueBody.scrollTop) < parseInt(mythumbshot.obj.offsetHeight+mythumbshot.y) + indentY ) {
mythumbshot.obj.style.top = heightIndent;
positionClass += "Top";
} else {
mythumbshot.obj.style.top = (mythumbshot.y + indentY)+'px';
positionClass += "Bottom";
}

mythumbshot.obj.className = positionClass;
mythumbshot.timer = window.setTimeout("mythumbshot.showThumb()",500);
},
showThumb: function(e) {
mythumbshot.hidden = false;
mythumbshot.obj.style.visibility = mythumbshot.ind.style.visibility = 'visible';
mythumbshot.obj.style.opacity = mythumbshot.ind.style.opacity = '0';
mythumbshot.img.style.visibility = "hidden";
                
var addy = String(mythumbshot.lnk.href);

mythumbshot.errorTimer = window.setTimeout("mythumbshot.imageError()",15000);
mythumbshot.img.src = 'http://www.oa-amstelveen.nl/get?url='+ encodeURIComponent(addy)+'&size=m&rndm='+parseInt(mythumbshot.linkPool[mythumbshot.lnk.href]);

/*@cc_on@*/
/*@if(@_win32)
return;
/*@end@*/
                
mythumbshot.fade(10);
},
hideThumb: function(e) {
// Don't mouseout if over the bubble
e = e || window.event;

// Check if mouse(over|out) are still within the same parent element
if(e.type == "mouseout") {
var elem = e.relatedTarget || e.toElement;
if(elem.id && elem.id.search("fdImage") != -1) return false;
}

mythumbshot.hidden = true;
if(mythumbshot.timer) clearTimeout(mythumbshot.timer);
if(mythumbshot.errorTimer) clearTimeout(mythumbshot.errorTimer);
if(mythumbshot.opacityTimer) clearTimeout(mythumbshot.opacityTimer);
mythumbshot.obj.style.visibility = 'hidden';
mythumbshot.ind.style.visibility = 'hidden';
mythumbshot.img.style.visibility = 'hidden';
mythumbshot.ind.className= "imageLoaded";
},
fade: function(opac) {
var passed  = parseInt(opac);
var newOpac = parseInt(passed+10);
if ( newOpac < 90 ) {
mythumbshot.obj.style.opacity = mythumbshot.ind.style.opacity = '.'+newOpac;
mythumbshot.opacityTimer = window.setTimeout("mythumbshot.fade('"+newOpac+"')",20);
} else {
mythumbshot.obj.style.opacity = mythumbshot.ind.style.opacity = '1';
}
},
addEvent: function( obj, types, fn ) {
var type;
for(var i = 0; i < types.length; i++) {
type = types[i];
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else obj.addEventListener( type, fn, false );
}
}
}

mythumbshot.addEvent(window, ['load'], mythumbshot.init);



