var stretchers = $$('div.accordion');
stretchers.each(function(item){
	item.setStyles({'height': '0', 'overflow': 'hidden'});
});

var stretchers2 = $$('div.accordionCentre');
stretchers2.each(function(item){
	item.setStyles({'height': '0', 'overflow': 'hidden'});
});

window.onload = function(){ //safari cannot get style if window isnt fully loaded
	
	var togglers = $$('h3.toggler');
	var togglers2 = $$('h3.togglerCentre');
	
	var bgFx = [];
	
	togglers.each(function(toggler, i){
		bgFx[i] = new Fx.Color(toggler, '', {wait: false});
	});
	togglers2.each(function(toggler, i){
		bgFx[i] = new Fx.Color(toggler, '', {wait: false});
	});

	var myAccordion = new Fx.Accordion(togglers, stretchers, { opacity: false, start: false, alwaysHide: true, transition: Fx.Transitions.quadOut,
		
		onActive: function(toggler, i){
		    toggler.className = toggleClass(toggler.className);
			toggler.getFirst().setStyle('text-decoration', 'none');
			toggler.getFirst().parentNode.setStyle('padding-bottom', '0px');

			// fix top and bottom images accordingly
			$('top_round').className = (i != 0) ? "top_dark" : "top_light";
			$('bottom_round').className = (i != 4) ? "bottom_dark" : "bottom_light";
		},
		onBackground: function(toggler, i){
		    toggler.className = toggleDeselect(toggler.className);
			bgFx[i].clearTimer();

			if(i != 4) {
				toggler.getFirst().parentNode.setStyle('padding-bottom', '0px'); // reset styles
			} else {
				toggler.getFirst().parentNode.setStyle('padding-bottom', '0px');
			}
			toggler.getFirst().setStyle('text-decoration', 'none');
		}
	});
	
	var myAccordion = new Fx.Accordion(togglers2, stretchers2, { opacity: false, start: false, transition: Fx.Transitions.quadOut,
		
		onActive: function(toggler, i){
//			toggler.getFirst().setStyle('text-decoration', 'none');
//			toggler.getFirst().parentNode.setStyle('padding-bottom', '0px');

			// fix top and bottom images accordingly
			$('top_round').className = (i != 0) ? "top_dark" : "top_light";
			$('bottom_round').className = (i != 4) ? "bottom_dark" : "bottom_light";
		},
		onBackground: function(toggler, i){
			bgFx[i].clearTimer();

			if(i != 4) {
				toggler.getFirst().parentNode.setStyle('padding-bottom', '0px'); // reset styles
			} else {
				toggler.getFirst().parentNode.setStyle('padding-bottom', '0px');
			}
			toggler.getFirst().setStyle('text-decoration', 'none');
		}
		
	});
	
	//anchors
	function checkHash(){
		var found = false;
		$$('h3.toggler a').each(function(link, i){
			if (window.location.hash.test(link.hash)){
				myAccordion.showThisHideOpen(i);
				found = true;
			}
		});
		return found;
	}
	
	function toggleClass(className)
	{
	    var start = className.indexOf('Selected');
	    if (start != -1)
	        return (className.substring(0,start));
        else
            return (className + 'Selected');	    
	}
	
	function toggleDeselect(className)
	{
	    var start = className.indexOf('Selected');
	    if (start != -1)
	        return (className.substring(0,start));
        else
            return className;
	}	

	if (!checkHash()) myAccordion.showThisHideOpen(0);

};

try {
	Window.disableImageCache();
}catch(e){}