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 largefeatureone = new imageFader($('smallpromoone'), {
			sleep: 4500,
			fade: 0.2
	});

	var smallfeatureone = new imageFader($('smallpromotwo'), {
			sleep: 5000,
			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'));
});



/*//////////////////////////////////////////////////////////////
//	Subscribe
/////////////////////////////////////////////////////////////*/
window.addEvent('domready',function(){
	
	
	var header = $$('#header')[0];
	var form = $$('.subscribe')[0];
	
	/* Subscribe Click -> Swap to the Form */
	$('subscribe-to-newsletter').addEvent('click', function() {
		form.setStyles({display:'block',opacity:0});	
		
		new Fx.Style(form, 'opacity', {duration: 500}).start(1);
		
		header.setStyles({height:'60px'});	
		
		$('subscribe-to-newsletter').setStyles({display:'none'});
		
	});
	
	if(
		$$('#header p.required').hasClass('error')[0] || 
		$$('#header p.required').hasClass('error')[1]
	) {
		form.setStyles({display:'block',opacity:0});
		
		header.setStyles({height:'60px'});
		
		new Fx.Style(form, 'opacity').set(1);
		
		$('subscribe-to-newsletter').setStyles({display:'none'});

	}
	
	if(
		$$('#header .quicksignupform').hasClass('done')[0]
		) {
		form.setStyles({display:'block',opacity:0});
		
		header.setStyles({height:'auto'});
		
		$('subscribe-to-newsletter').setStyles({display:'none'});
		
		new Fx.Style(form, 'opacity').set(1);

	}
});

 
