var fader = new Class({
	Implements: Options,
	options: {
		speed: '1000',
		activeclass: 'current',
		elementtag: 'a',
		counter: 1
	},
	initialize: function(parent,options){
		this.parent = $(parent);
		this.setOptions(options);
		this.currentitem = this.parent.getFirst(this.options.elementtag);
		this.currentitem.set('class','current');
		

	},
	fade: function() {
		this.next = null;
		this.current = null;
		this.current = this.parent.getChildren(this.options.elementtag+'.'+this.options.activeclass);
		this.next = this.current.getNext(this.options.elementtag);
		if (this.next == '') this.next = this.currentitem;
		this.next.addClass('current');
		this.current.removeClass('current');
	},
	start: function() {
		this.fade.periodical(this.options.speed,this);
	}
});


/*//////////////////////////////////////////////////////////////
//	Set Up Crossfade images
/////////////////////////////////////////////////////////////*/
function startFader() {
/*
	var banners = new imageFader($('banners'), {
			sleep: 5000,
			fade: 0.2
		});
	
*/
	var largefeatureone = new imageFader($('largefeatureone'), {
			sleep: 4500,
			fade: 0.2
	});

	var smallfeatureone = new imageFader($('smallfeatureone'), {
			sleep: 5000,
			fade: 0.2
	});

	var smallfeaturetwo = new imageFader($('smallfeaturetwo'), {
			sleep: 6000,
			fade: 0.2
	});

	var smallfeaturetwo = new imageFader($('largepromo'), {
			sleep: 6000,
			fade: 0.2
	});	
}

window.addEvent('domready', startFader);

/*//////////////////////////////////////////////////////////////
//	Set Up Acordion
/////////////////////////////////////////////////////////////*/
window.addEvent('domready',function(){
	var accordion = new Accordion('h3.toggler', 'div.element', {
		opacity: false //we dont want opacity as it's too slow for the user
	}, $('accordion'));
	
	
	var form = $$('.subscribe')[0];
	var subscribe = $$('.find-us')[0];
	
	/* Subscribe Click -> Swap to the Form */
	$('subscribe-to-newsletter').addEvent('click', function() {
		subscribe.setStyles({opacity: 1});
		form.setStyles({display:'block',opacity:0});	
		
		new Fx.Style(subscribe, 'opacity', {duration: 750}).start(0);
		new Fx.Style(form, 'opacity', {duration: 500}).start(1);	
	});
	
	if(
		$$('#header .quicksignupform').hasClass('done')[0] ||
		$$('#header p.required').hasClass('error')[0] || 
		$$('#header p.required').hasClass('error')[1]
	) {
		subscribe.setStyles({opacity: 1});
		form.setStyles({display:'block',opacity:0});
	
		new Fx.Style(subscribe, 'opacity').set(0);
		new Fx.Style(form, 'opacity').set(1);
	}
});