// JS function for uncrypting spam-protected emails:
function UnCryptMailto(s) {	//
	var n=0;
	var r="";
	for(var i=0; i < s.length; i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(2));
	}
	return r;
}
  // JS function for uncrypting spam-protected emails:
function linkTo_UnCryptMailto(s)	{	//
	location.href='mailto:'+UnCryptMailto(s);
}


/* Examples for onLoad */
Object.extend(Event, {
  _domReady : function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (this._timer)  clearInterval(this._timer);

    this._readyCallbacks.each(function(f){ if (typeof f == 'function') f(); });
    this._readyCallbacks = 'done';
},
  onDOMReady : function(f) {
    if (Event._readyCallbacks == 'done' &&  typeof f == 'function'){
    	f();
    	return;
		}

    if (!this._readyCallbacks) {
      var domReady = this._domReady.bind(this);

      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false);

        /*@cc_on @*/
        /*@if (@_win32)
        		var dummy = location.protocol == "https:" ?  "https://javascript:void(0)" : "javascript:void(0)";
            document.write("<script id=__ie_onload defer src='" + dummy + "'><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") domReady();
            };
        /*@end @*/

        if (/WebKit/i.test(navigator.userAgent)) {
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady();
          }, 10);
        }

        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
  }
});
Event.onDOMReady(function(){
	/*
	//Flash Replacements
	if(typeof sIFR == "function"){
		// Navigation
		// BSP:sIFR.replaceElement(named({nWidth:150,nHeight:40,sSelector:"body h1", sFlashSrc:"includes/vandenkeere.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"body #header #primary li span", sFlashSrc:"includes/willow.swf", sColor:"#FFFFFF", sLinkColor:"#FFFFFF", sBgColor:"#000000", sHoverColor:"#5C83A7", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"body #main h1", sFlashSrc:"includes/willow.swf", sColor:"#7F7F7F", sLinkColor:"#5C83A7", sBgColor:"#FFFFFF", sHoverColor:"#890000", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
		sIFR.replaceElement(named({sSelector:"body #main h2", sFlashSrc:"includes/willow.swf", sColor:"#7F7F7F", sLinkColor:"#5C83A7", sBgColor:"#FFFFFF", sHoverColor:"#890000", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
	};
	*/
}); // Call DomReady at least once

//Fire Script as soon as Window Loads
//Event.observe(window,'load',wbt_init);



// easyCMS Tooltip
var ecTooltip = Class.create();
var ecTooltipRegistry = Class.create();

ecTooltip.prototype = {
  initialize: function(el){
    this.el = $(el);
    this.r = ecTooltipRegistry;
    this.r.add(this.el);
    
    this.TooltipContainer = $(Builder.node('div', {width: '100%', style: 'position: absolute; z-index: 99999; display: none; top: 0px; left: 0px;', className:'ecTooltip'}));
    Event.onDOMReady(function(){$$('body').first().appendChild(this.TooltipContainer); }.bindAsEventListener(this));
    this.TooltipContainer.innerHTML = this.el.select('.tooltip').first().innerHTML; 
    Event.observe(this.el, 'mouseover', this.show.bind(this)); 
    Event.observe(this.el, 'mouseout', this.hide.bind(this)); 
    this.visible = false;
    this.timer = false;
  },
  show: function(){
    //this.timer = window.setTimeout(this._show.bindAsEventListener(this), 10);
    this._show();
  },
  hide: function(){
    this.timer = window.setTimeout(this._hide.bindAsEventListener(this), 10);
  },
  _show: function(){
    if (this.timer) window.clearInterval(this.timer);
    if (this.visible) return true;
    this.visible = true;
    var c = this.TooltipContainer;
    var p = this.el.cumulativeOffset();
    Event.observe(c, 'mouseover', this.show.bind(this)); 
    Event.observe(c, 'mouseout', this.hide.bind(this)); 
    c.appear({duration: 0.3});
    c.setStyle({left: (p.left+this.r.offsetX)+'px', top: (p.top+this.r.offsetY)+'px'});
    this.el.addClassName('selected');
    this.r.Tooltips.without(this.el).each(function(el){el.addClassName('unselected')})
  }, 
  _hide: function(){
    this.TooltipContainer.stopObserving();
    if (!this.visible) return true;
    this.visible = false;
    this.TooltipContainer.hide();
    this.el.removeClassName('selected');
    this.r.Tooltips.without(this.el).each(function(el){el.removeClassName('unselected')})
  }
}

ecTooltipRegistry.prototype = {
   initialize: function(){
     this.Tooltips = [];
     this.offsetX = 165;
     this.offsetY = 65;
   },
   add: function(el){
     this.Tooltips.push(el);
   }
}
ecTooltipRegistry = new ecTooltipRegistry();
