/*
  Name: FED scripts
  Description: Javascript file for FED functionality
  Version: 1.4
  Author: Rolled Limited
  Author URI: http://www.rolled.at
*/

window.addEvent('domready', function(){
	// Accordion
	var accordion = new Accordion('span.question', 'div.answer', {
		opacity: true,
		show: -1,
		alwaysHide: true,
		onActive: function(toggler, element){
			toggler.addClass('expanded');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('expanded');
		}
	}, $('faq'));
  
	var scroll = new SmoothScroll({duration: 1000});
	faqaccord.attachexternals();
	inputfade.init();
});

// External Accordion Links
faqaccord = {
	attachments: Array(//[0]Id, [1]Accordion Button Selector, [2]Selector Offset
		Array('javascript-frameworks-link', '#faq span.question', 2),
		Array('partners-link'             , '#faq span.question', 0),
		Array('multiple-files-link'       , '#faq span.question', 3),
		Array('cms-integration-link'      , '#faq span.question', 4)
	),
	attachexternals: function(){
		attachments = this.attachments;
		attachments.each(function(attach){
			if($(attach[0]) != null)
			{
				$(attach[0]).$accord = {}; 
				$(attach[0]).$accord.selector = attach[1];
				$(attach[0]).$accord.index = attach[2];
				$(attach[0]).addEvent('click', function(){
					faqaccord.expand.delay(1000, 0, this); 
				});
			}
		});
		$$('#faq .back-to-top').each(function(other){
			other.addEvent("click", function(){
				$$('#faq span.expanded')[0].fireEvent('click');
			});
		});
	},
	expand: function(object){ //Basically clicks the accordion button that $object is assigned to.
		if(!$$(object.$accord.selector)[object.$accord.index].hasClass('expanded')){
			$$(object.$accord.selector)[object.$accord.index].fireEvent('click');
		}
	}
}

// Input Form error handling
inputfade = {
	init: function(){
		$$('#contact-us .error').each(inputfade.makefade);
	},
	makefade: function(other){
		other.addEvent('click', function(e){
			new Event(e).stop();
			var myEffects = new Fx.Styles(this, {duration: 1000, transition: Fx.Transitions.Sine});
			other.setStyle("border-color", "#BFBFBF");
			myEffects.start({
				'background-color': "#FFFFFF"
			});

		});
	}
}