var mooFader = new Class({

	Implements: [Events, Options],

	options:{
		duration: 2000,
		fade: 1000,
		ps : [
			[3,3],
			[306,3],
			[3,250],
			[306,250]
		]
	},

	initialize: function(options) {
		var self = this;
		this.setOptions(options);
		this.images = $$('#fader img[src$=.jpg]');
		[0,1,2,3].each(function(i){
			new Asset.image(self.images[i].src);
			self.images[i].setStyles({position:'absolute',left:self.options.ps[i][0],top:self.options.ps[i][1]}).removeClass('none');
		});
		this.counter = 4;
		this.p = 0;
		this.change.periodical(this.options.duration,this);
	},
	
	reset: function(){
		var self = this;
		this.counter = 4;
		this.p = 0;
		var total = this.images.length;
		this.images.each(function(el,k){
			if(k>3 ) new Fx.Tween(el,{duration:self.options.fade}).start('opacity', 1, 0);
		});
	},

	change: function(){
		if(this.images[this.counter]) {
			this.images[this.counter].setStyles({position:'absolute',left:this.options.ps[this.p][0],top:this.options.ps[this.p][1],visibility:'hidden'}).removeClass('none');
			new Fx.Tween(this.images[this.counter],{duration:this.options.fade}).start('opacity', 0, 1);
			this.counter++;
			this.p++;
			if(this.images[this.counter]) new Asset.image(this.images[this.counter]);
			if(this.p>3) this.p=0;
		} else this.reset();
	}
});

window.addEvent('domready',function(){
	
	$$('img.roll').each(function(el){
		if(el.src.match('_off.')){
			el.addEvent('mouseover',function(e){ el.src=el.src.replace('_off.','_on.'); });
			el.addEvent('mouseleave',function(e){ el.src=el.src.replace('_on.','_off.'); });
		}
	});

	$$('#searchform').getElement('input').addEvents({
		'focus': function(e){ if(this.value=='search...') this.value=''; },
		'blur': function(e){ if(this.value=='') this.value='search...'; }
	});
	
	Slimbox.scanPage;
	
	if($('accordion')){
		var accordion = new Accordion($$('.toggler'),$$('.element'), {
			opacity: 0,
			onActive: function(toggler) { toggler.setStyles({'color':'#FCDB00','font-weight':'bold'}); },
			onBackground: function(toggler) { toggler.setStyles({'color':'#ffffff','font-weight':'normal'}); }
		});
	}
	
	if($('langselect')) {
		$('langselect').addEvent('change',function(e){
			if(this.options[this.selectedIndex].value==defaultlang) location.href = urlpath+currentpath;
			else location.href = urlpath+'/'+this.options[this.selectedIndex].value+currentpath;
		
		});
	}
	
	var myImages = new Asset.images(banners);
	$('bannerimg').set('src',banners.getRandom()).removeClass('none');
	(function(){
		var index = banners.indexOf($('bannerimg').get('src'));
		index = (index<banners.length-1) ? ++index : 0;
		$('bannerimg').set('src',banners[index]).removeClass('none');
	}).periodical(6000)
	
	if($('fader')){
		new mooFader();
	}
	
});
