

/**************************************
 *	Fadeshow
 **************************************/

var Fadeshow = new Class({
	object: null,
	effect: null,
	periodicalTimer: null,
	
	setOptions: function(options){
		this.options = {
			interval: 2000,
			duration: 1000
		}
		Object.extend(this.options, options || {});
	},
	
	initialize: function(object, options){
		this.object = object;
		this.setOptions(options);
		if (this.options.duration > this.options.interval) { this.options.interval = this.options.duration + 2000 }
		
		this.periodicalTimer = this.transist.periodical(this.options.interval, this);
	},
	
	transist: function(){
		//Fade out
		this.effect = new Fx.Style(this.object, 'opacity', {duration: this.options.duration, onComplete: this.showNew.bind(this)});
		this.effect.start(1,0);
	},
	
	showNew: function(){
		//Fade in
		this.effect = new Fx.Style(this.object, 'opacity', {duration: this.options.duration});
		this.effect.start(0,1);
	}
})

var switchColor = new Class({
	object: null,
	color: 'blue',
	
	initialize: function(object){
		this.object = object;	
		this.changeColor.periodical(1000, this);
	},
	
	changeColor: function(){
		if(this.color == 'blue'){
			this.object.setStyle('color', '#d50714');
			this.color = 'red';
		}else{
			this.object.setStyle('color', '#23408f');
			this.color = 'blue';
		}
	}
})


window.addEvent('domready', function(){
	$$('.flikker').each(function(object){
		new Fadeshow( object, {duration: 500, interval: 1500} );
	});
	$$('.colorswitch').each(function(object){
		new switchColor(object);
	});
});
