/*
gbAnimate v1.0 mit MooTools v1.2

von gb media (www.gb-media.biz) 2009
Vielen Dank an die MooTools Entwickler
*/

var gbAnimate = new Class({
	
	Implements: Options,
	
    options: {
		fadeEl			: ['main-content-block'],
		href			: 'a',
		durationIn		: 'slow',
		transitionIn	: Fx.Transitions.linear.easeIn,
		durationOut		: 'short',
		transitionOut	: Fx.Transitions.linear.easeOut
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.fadeIn();
		this.clickAction();
	},
	
	fadeIn: function (){
		this.options.fadeEl.each(function (el){
			$(el).setOpacity(0);
			el = new Fx.Morph($(el), {duration: this.options.durationIn, transition: this.options.transitionIn});
			el.start({
				opacity: 1
			});
		}.bind(this));
	},
	
	fadeOut: function (togo){
		this.options.fadeEl.each(function (el){
			$(el).setOpacity(1);
			el = new Fx.Morph($(el), {duration: this.options.durationOut, transition: this.options.transitionOut});
			el.start({
				opacity: 0
			}).chain(function() {
				window.location.href = togo;
			});
		}.bind(this));
	},
	
	clickAction: function (){
		this.bound = {};
		var anchorAr = $$(this.options.href);
		anchorAr.each(function (el){
			this.bound.onClickEvent = this.onClickEvent.bindWithEvent(this, el);
			$(el).addEvent('click', this.bound.onClickEvent);
		}.bind(this));
	},
	
	onClickEvent: function (event, togo){
		el = $(event.target);
		this.fadeOut(togo);
		return false;
	}
	
});
gbAnimate.implement(new Options);

window.addEvent('domready', function(){
	if (typeof gbAnimateOpt == 'undefined'){
		gbAnimateOpt = {}; 
	}
	
	gbAnimate = new gbAnimate(gbAnimateOpt);
});