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

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

var scrolli = Class.create();	// Create class 'scrolli'
scrolli.prototype = {
	initialize:function(el){
		this.el = $(el);	// Get element by Id
		this.clones = []; // Clones of the original banner
		this.frameWidth = this.el.up().offsetWidth;	// Outer-div-width
		this.imageWidth = this.el.offsetWidth;	// Imagewitdh
		var clones = (this.frameWidth / this.imageWidth).ceil();	// Needed clones
		this.duration = this.frameWidth/64;	// Pixel per second
		this.margin = 20;	// Margin between banners in px
		for(i=1;i<=clones;i++)
			this.clone(i);
		this.move();	// start function
	},
	reset:function(){
		this.el.setStyle({left:(this.el.offsetLeft+this.imageWidth)+'px'});	// Set imagepositon for original
		this.clones.each(function(el){
			el.setStyle({left:(el.offsetLeft+this.imageWidth)+'px'});	// Set imageposition for all clones
		}.bind(this));
	},
	move:function(){
  	this.clones.each(function(el){
  		new Effect.Move(el, { x: (0-this.imageWidth), y: 0, mode: 'relative', duration: this.duration, transition: Effect.Transitions.linear, fps: 30.0});	// Create effect for clones
		}.bind(this));
		new Effect.Move(this.el, { x: (0-this.imageWidth), y: 0, mode: 'relative', duration: this.duration, transition: Effect.Transitions.linear, fps: 30.0, afterFinish:this.loop.bind(this)});	// Create effect for original, start function loop
	},
	loop:function(){	// start functions
		this.reset();
		this.move();
	},
	clone:function(count){
		var new_element = this.el.cloneNode(true);	// Clone child-div
		this.el.up().appendChild (new_element);	// Add clone to parent-div
		new_element.writeAttribute('id','');	// Delete id
		new_element.setStyle({left: ((this.imageWidth + this.margin) * count)+'px'});	// Set position
		this.clones.push(new_element);	// Add clone to clones-array
	}
}

// start after loading all content
Event.observe(window,'load',function(){
	new scrolli('banner');
});	// Call DomReady at least once
