var rAccordion = new Class({
	 
	initialize: function(container, toggleClass, elementClass, options){
		this.container = container;
		this.tClass = toggleClass;
		this.eClass = elementClass;
		this.options = options;
		this.selector = '#' + this.container + ' > .';		
		this.makeAccordion();
	},
 
	makeAccordion: function(){
		new Fx.Accordion(
			$$(this.selector+this.tClass),
			$$(this.selector+this.eClass),
			this.options
		).addEvents({
			// The onActive and onComplete events added to the stack here to
			// attempt to address some of the css issues.
			'onActive': function(toggle){
				if(toggle.getParent().getStyle('height') != 0)
					toggle.getParent().setStyle('height', '');
			},
			'onComplete': function(a){
				if ($defined(a)) {
					var height = 0;
					a.getParent().getChildren().each(function(e){
						height = height + e.offsetHeight;
					});
					if(height != a.getParent().offsetHeight && a.getParent().offsetHeight != 0)
						a.getParent().setStyle('height','');
				}
			}
		});
		this.selector += this.eClass + ' > .';
		if($defined($$(this.selector)[0])){
			this.makeAccordion();
		}
	}
});



window.addEvent('domready',function(){
	var toggles, initialDisplay, accordion, toOpen, search, scroller, accordOpts;
	
	$$('#imagenav a').each(function(el){
		el.addEvent('mouseenter',function(){
			el.grab($('navOverlay'));
			$('navOverlay').setStyles({
				display: 'block',
				margin: '-110px 0 0 0'				
			});
		});
		el.addEvent('mouseleave',function(){
			$('navOverlay').setStyle('display','none');
		});
	});
	
	accordOpts = {
		alwaysHide : true,
		initialDisplayFx : false,
		onActive : function (el) {
			var toggler = el.getElement('img');
			if (toggler) {toggler.set('src', '/images/less.png'); };
		},
		onBackground : function (el) {
			var toggler = el.getElement('img');
			if (toggler) {toggler.set('src', '/images/more.png'); };
		}	
	};
	
	toggles = $$('#accordion > .toggle');
	search = window.location.search;
	if (search){
		search = search.substr(1).parseQueryString();
		
		initialDisplay = toggles.get('id').indexOf(search.show) || 0;
		toOpen = search.show;
		
		accordOpts.display = initialDisplay;

	}
	
	if (document.getElement('body').hasClass('experience')){
		accordion = new rAccordion('accordion', 'toggle', 'accordion-text', accordOpts);
	} else {
		
		
		accordion = new Fx.Accordion(toggles, $$('.accordion-text'), accordOpts);

		if (toOpen && toOpen !== 0){
			scroller = new Fx.Scroll(window);
			scroller.toElement($(toOpen));
		}
	}
	
	
});

