function InitCrossFade() {
	// replacement for code below the class	
	if(InitCrossFade.arguments) {
		var container = InitCrossFade.arguments[0];
		for(i=1;i<InitCrossFade.arguments.length;i++) {
			string = InitCrossFade.arguments[i];
			result = string.match(/url\((.+)\)/);
			if (result) url = result[0];
			var new_img = new Element('div', {
				'class' : 'img',
				'styles' : {
					'border' : '0px',
					'position': 'absolute',
					'background' : url,
					'background-position' : 'center'
				}
			});
			//new_img.set('src', url);
			$(container).appendChild(new_img);
		}
		new ctSlideshow({'container' : $('crossfade_side'), 'fadetime' : 1000, 'interval' : 3000});
	}
	
};


/* 
	ctSlideshow - Slideshow Class
	Christopher Tazreiter (2009)

	takes all images of links inside the container and plays them one by one

	usage: var s = new ctSlideshow({container : $('container'), fadetime : 1000, interval : 3000});

	ATTENTION - MODIFIED VERSION: uses <div> instead of <img> for backwards-compatibility

*/
var ctSlideshow = new Class({

	Implements: [Options, Events],

	options : {
		container: null,	// container element containing the slideshow images
		fadetime : 500,	// time the transition takes, 1000 = 1 second
		interval : 5000		// time one image stays on screen, 3000 = 3 seconds
	},

	slides : [],	// array containing all slides detected in the container
	index : 0,		// local counter (points to image to be faded next)

	// initialize class and start
	initialize : function(options){
		this.setOptions(options); // set local options to given parameters
		
		this.options.container.setStyles({
			overflow: 'hidden'
		});
		if(this.options.container.getStyle('position') == "static") {
			this.options.container.setStyle('position', 'relative');
		}

		this.options.container.getElements('div').each(function(img) {
			this.slides.include(img);
			img.set('tween', {duration: this.options.fadetime});
			img.setStyles({
				display: 'block',
				position: 'absolute',
				top: 0,
				left: 0,
				opacity: 1,
				margin: 0
			});
		}, this); // second this binds 'this' to current instance of object, for use inside the function

		this.index = this.slides.length-1;		
		if(this.index <= 0) {
			// do nothing, not enough images to cycle	
		} else {
			// start periodical fade of images
			this.fadenext.periodical(this.options.interval, this);
		}
		
	},
	
	// fade the next image
	fadenext : function() {
		//this.resetOpacity.delay(this.options.fadetime + (this.options.fadetime/2), this);

		if(this.index == 0) {
			this.index = this.slides.length-1;
			this.slides[this.index].fade('in');
			this.resetOpacity.delay(this.options.fadetime + (this.options.fadetime/2), this);
		} else {
			this.slides[this.index].fade('out');
			this.index--;
		}
	},
	
	// reset opacity of all images
	resetOpacity : function() {
		this.slides.each(function(element, index) {
			element.setStyle("opacity", 1);
		});
	}

});

/*
function addEventToObject(obj, evt, func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}

function bindWithArguments(object){
    var __method = this;
    var args = [];
    for (var i=0,len=arguments.length-1; i<len; i++) args[i] = arguments[i+1];
    return function(){ __method.apply(object, args); }
}
Object.prototype.bindWithArguments = bindWithArguments;

function CrossFade() {
	this.interval = 40; // initial interval
	this.setOpacity = function (obj, o) {
	    obj.style.opacity = (o / 101);
	    obj.style.MozOpacity = (o / 100);
	    obj.style.KhtmlOpacity = (o / 100);
	    obj.style.filter = "alpha(opacity=" + o + ")";
	}
	for(j=0;j<this.length;j++) {
		this[j].style.position='absolute';
		this[j].style.top=0;
		this[j].style.zIndex=0;
		this.setOpacity(this[j],0);
	}
	this.opacity = 100;
	this.setOpacity(this[0].parentNode,this.opacity);
	this.currentDiv = 0;
	this.previousDiv = this.length-1;
	//this[0].parentNode.style.display = 'block';
	this[0].parentNode.style.visibility = 'visible';
	this.initOpacity = function (div, startOpacity, endOpacity) {
		if (startOpacity <= endOpacity) {
			this.setOpacity(div, startOpacity);
			startOpacity += 10;
				window.setTimeout(this.initOpacity.bindWithArguments(this,div,startOpacity,endOpacity),this.interval);
		}
	}
	this.initOpacity(this[this.currentDiv],0,100);
	this.changeOpacity = function (opac) {
		if(opac < 100) {
			this.setOpacity(this[this.currentDiv],opac);
			this.setOpacity(this[this.previousDiv],100-opac);
			opac += 10;
			window.setTimeout(this.changeOpacity.bindWithArguments(this,opac),80);
		} else {
			this.setOpacity(this[this.currentDiv],100);
			this.setOpacity(this[this.previousDiv],0);
			this.previousDiv = this.currentDiv;
			this.currentDiv = (this.currentDiv>=this.length-1) ? 0 : this.currentDiv + 1;
			this[this.previousDiv].style.zIndex = 100;
			this[this.currentDiv].style.zIndex = 0;
			opac = 0;
			window.setTimeout(this.changeOpacity.bindWithArguments(this,opac),(this.interval*100));
		}
	}
	this.olen = this[0].className.length;
	this.onum = this[0].className.charAt(this.olen-1);
	if(!isNaN(this.onum) && this.onum > 1) {window.setTimeout(this.changeOpacity.bindWithArguments(this,this.opacity),(80*this.interval)/this.onum);
	//} else if(this.onum == 3) { 
	//	window.setTimeout(this.changeOpacity.bindWithArguments(this,this.opacity),300*this.interval);
	}else {
		this.changeOpacity(this.opacity);
	}
}
Object.prototype.CrossFade = CrossFade;

var currentImg;
var previousImg;
var fadedivs = [];

function isA(o,klass){ if(!o.className) return false; return new RegExp('\\b'+klass+'\\b').test(o.className) }

// get elements by class name, eg $c('post', document, 'li')
function $c(c,o,t) { o=o||document;
	if (!o.length) o = [o]
	var elements = []
	for(var i = 0, e; e = o[i]; i++) {
		if(e.getElementsByTagName) {
			var children = e.getElementsByTagName(t || '*');
			for (var j = 0, child; child = children[j]; j++) {
				if(isA(child,c)) elements.push(child);
			}
		}
	}
	return elements
}

function InitCrossFade() {
	if(InitCrossFade.arguments) {
		var fadecontainer = document.getElementById(InitCrossFade.arguments[0]);
		for(i=1;i<InitCrossFade.arguments.length;i++) {
			fadecontainer.innerHTML+=InitCrossFade.arguments[i];
		}
		var fade = fadecontainer.lastChild;
		var fadeclass = fade.className;
		fadedivs = $c(fadeclass,'','*');
		fadedivs.CrossFade();
	}
}

//addEventToObject(window,'onload',InitCrossFade);

*/