// (C) Stefan Liebenberg //

var timeout = 0.1, margin_top = 20;

window.onerror = function () { return true }
function extend (source) { for (var i = 1, l = arguments.length; i < l ; i++ ) for ( var a in arguments[i] ) source[a] = arguments[i][a]; return source }
function $A ( object, array ) { array = array || [];  for ( var i = 0, l = object.length; i <l ; i++ ) array.push( object[i] ); return array }
function $H ( obj, array ) { array = array || []; for ( var a in obj ) {array.push( [obj[a], a] ) }; return array }

extend( Array.prototype, { each: function (block) { for ( var i = 0, length = this.length; i < length; i ++ ) void block.call( this, this[i], i ); return this },
	select: function (block, results) { results = results || []; this.each( function (value) { if( block.apply( this, arguments ) ) results.push( value ) } ); return results },
	collect: function (block, results) { results = results ||  [];	this.each( function () { results.push( block.apply( this, arguments ) ) }); return results } } )

function recursiveAttribute( el, attr, parent ) {return el ? parseInt(el[attr]) + parseInt( recursiveAttribute( el[parent], attr, parent ) ) : 0 }
function posOffset( el ) { return ['Top','Left'].collect(function(st){ return recursiveAttribute( el, 'offset'+st, 'offsetParent') }) }

 var activeBalloon = null;
 function displayBalloon ( element, e) {
	if( activeBalloon != null ) hideBalloon(); 
	activeBalloon = element.ref || document.getElementById( element.getAttribute( 'rel' ) )
	activeBalloon.style.left = activeBalloon.style.top = '-500px';
	if( e.type == 'mouseover' ) activeBalloon.style.visibility = 'visible';
	var offset = posOffset( element );
        if( element.getAttribute('right') ) {
          offset[0] = offset[0] - 90;
          offset[1] = offset[1] + 90;
        };
	extend( activeBalloon.style, {top: offset[0] + element.offsetHeight + margin_top + 'px', left:offset[1] + 'px' } )
 }
 
 function hideBalloon () {
	if(!activeBalloon) return;
	if (activeBalloon.clearTime ) activeBalloon.clearTime();
	activeBalloon.style.visibility='hidden'
	activeBalloon.onmouseover = activeBalloon.onmouseout = activeBalloon.clearTime = null;
	activeBalloon = null; 
 }
 
 function delayhide( ) {
	if( !activeBalloon ) return;	
	var t = window.setTimeout( function () { hideBalloon() }, timeout * 1000); 
	extend(activeBalloon,{onmouseover:function () { activeBalloon.clearTime(); activeBalloon.onmouseout = delayhide }, clearTime : function () { try {window.clearTimeout( t ) } catch (e) { } } } )
 }
 
 
window._load = window.onload || new Function();
window.onload = function () {
	window._load.apply( this, arguments );
	$A(document.getElementsByTagName('a'))
		.select( function (element, rel, relEl) {rel=element.getAttribute('rel'); return rel && rel != "" && (relEl = document.getElementById(rel )) && relEl.className=="balloonstyle" && ((element.ref = relEl ).style.visibility = 'hidden' )})
		.each( function (el) {
			
			extend( el, { onmouseover: function (ev) { displayBalloon( el, window.event || ev ) }, onmouseout: function () { delayhide( ) } } )
		})	
 }