// 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);




/*
* Prototype based TABs (Really really unobtrusive)
* (c) by blueend web:applications
*/
var smartTabs = Class.create();
smartTabs.prototype = {
	initialize: function(tabID, options)
	{
		this.cookie = false;
		this.selected = 0;
		if (this.tab_element = $(tabID))
		{
		  this.tab_element.tabs = this;
		  links = new Array();
		  ajax_hrefs = new Array();
		  this.loaded_tabs = new Array();
		  this.tab_element.addClassName('smartTabs');
			this.options = options;
			this.hidden_tabs = false;
			this.tabs = $$('#'+tabID+' .tab');
			this.tabid_by_name = new Object();
			if (options && options.head_tag) head_tag=options.head_tag; else head_tag='h2';
			if (options && options.selected) selected=options.selected; else selected=this.selected;
			if (options && options.hide_heading) hide_heading=true; else hide_heading=false;
			if (options && options.tab_nav_position) tab_nav_position=options.tab_nav_position; else tab_nav_position='top';
			if (selected<0) selected = 0; else if (selected>this.tabs.length-1) selected = this.tabs.length-1; // Don't run out of bounds
			this.tab_element.addClassName('smartTabs_'+tab_nav_position);
			this.selected = selected;
			var i = 0;

			has_hidden_tabs = false;
			var skeleton = new Element('div',{'class':'tab_nav'});
      this.tabs.each(function(el){
				el.hide();
				el.id = tabID+'_'+i;
				headings = $$('#'+tabID+' #'+el.id+' > '+head_tag);
				my_class_addon = '';
				ajax_href = '';
				try {
					caption = headings[0].innerHTML;
					if (headings[0].down('a'))
					{
						ajax_href = headings[0].down('a').href;
						caption = headings[0].down('a').innerHTML;
					}
					if (hide_heading) headings[0].hide();
					my_class_addon = headings[0].className;

				} catch(e){caption = 'Tab '+i};
				if (i==selected) my_class = 'selected'; else my_class='';

				var link = new Element('a',{href:ajax_href+'#'+el.id, 'class':my_class+' '+my_class_addon}).update(caption);
				if (headings[0].hasClassName('hidden_tab'))
				{
					has_hidden_tabs = true;
					$(link).hide();
				}
				links.push(link);
				skeleton.insert(link);
				ajax_hrefs.push(ajax_href);
				i++;
			});
			this.ajax_hrefs = ajax_hrefs;
			this.links = links;
			this.links.each(function(el){
				el.onclick = function(){this.clickTab(el); return false;}.bindAsEventListener(this);
			}.bind(this));

   		if(has_hidden_tabs){
				link = Builder.node('a', {href:'#'});
				link = $(link);
				link.innerHTML = "&gt;";
				link.addClassName('hidden_tab_link');
				link.onclick = function(){this.showHiddenTabs(); return false;}.bindAsEventListener(this);
				//links.push(link);
				this.hidden_tabs=true;
			};
			if (this.links[selected]) this.links[selected].onclick();
			this.tab_element.insert({top:skeleton});
		}
	},

	clickTab: function(tab_element)
	{
		var tabID = tab_element.href.match(/#(\w.+)/)[1];

		if ((this.options && this.options.collapse==true) && this.selected_el==tab_element){
			// Clicked on current tab --> Collapse
			this.tabs.each(function(el){ el.hide(); });
			this.links.each(function(el){  el.removeClassName('selected');});
			selected = false; selected_el=false;
			this.tab_element.addClassName('collapsed');
		} else {
			// Regular tab click mode
			this.tabs.each(function(el){ if (el.id==tabID) el.show(); else el.hide();});
			i=0;
			this.links.each(function(el){ if (el==tab_element){$(el).addClassName('selected'); selected=i; selected_el = el;} else $(el).removeClassName('selected'); i++;} );
			this.tab_element.removeClassName('collapsed');
		}

		this.selected = selected;
		this.selected_el = selected_el;
		this.loadTab(selected);
		try{
			this.cookie.put(this.cookie_id,selected);
		}catch(e){}
		return false;
	},

	next: function() { this.select(this.selected+1); },
  prev: function() { this.select(this.selected-1); },
  first: function(){ this.select(0); },
  last: function() { this.select(999999); },
  collapse: function(){this.select(this.selected); this.tab_element.addClassName('collapsed');},

	select: function(selected)
	{
		if (isNaN(parseInt(selected))) // is no Integer? -> Get TabID by Name first!
			if (! (selected = (this.getTabIDbyName(selected))))
				return false;

		// Don't run out of bounds
		if (selected<0) selected = 0; else if (selected>this.tabs.length-1) selected = this.tabs.length-1;
		if (this.links[selected].hasClassName('hidden_tab') && this.hidden_tabs) this.showHiddenTabs();
		this.links[selected].onclick();
	},

	getTabIDbyName: function(search_name)
	{
			// Search by name!
			var count = 0;
			var selected = false;
			this.tabs.each(function(el){
				if (el.attributes['name'])
				{
					if (el.attributes['name'].value == search_name)
					{
						selected = count;
					}
				}
				count++;
			});
			return selected;
	},

	loadTab: function(selected, reload)
	{
	  if (typeof(reload)=='undefined') reload = false;;
  	element = this.tabs[selected];
  	if (this.ajax_hrefs[selected] && (reload || !this.loaded_tabs[selected]))
  	{
	  	element.innerHTML = '';
			Element.addClassName(element, 'ajax_loader_large');
	    var options = Object.extend(
    			{
    				onSuccess:function(selected,response,json){
    						Element.update(this.tabs[selected],response.responseText);
    						Element.removeClassName(this.tabs[selected], 'ajax_loader_large');
								this.loaded_tabs[selected] = true;
    					}.bind(this,selected)
    			}
    			, arguments[2] || {});
					new Ajax.Request(this.ajax_hrefs[selected], options);
		}
	},

	showHiddenTabs: function()
	{
		this.links.each(function(el){
			if (el.hasClassName('hidden_tab'))
				try {Effect.Appear(el,{duration:0.5});} catch(e){ el.hide();};
		});
		this.tab_element.getElementsBySelector('.hidden_tab_link').each(function(el){el.hide()});
	}
};