var Search = {
	init: function() {
		Search.menu = new UvumiDropdown("mainNav",{
			duration: 500,
			/*duration:Fx.Transitions.Bounce.easeOut,*/
			delay:1000,
			clickToOpen:false,
			transparent: '50%'
		}); 
		Search.setupPanels();
		Search.setupFooterLogos();
	},
	
	setupFooterLogos: function() {
		var accreditationBlock = $('accreditations');
		if (accreditationBlock) {
			new Slidr(accreditationBlock.getElement('ul'), {
				slideWidth: 114,
				canPause: true
			}).start();
		}
	},
	
	setupPanels: function() {
		if(!$('careersBlock')) {
			return;
		}
		Search.buildPanels();
		
		var panels = $$('#careersBlock > div');
		panels.each(function(el) {
			var expand = new Element('span').set('class', 'expand open');
			expand.injectInside(el.getPrevious());
			
			el.store('origHeight', el.getSize().y).set('tween', { duration: 500 });
			
			var title = el.getPrevious().addEvent('click', function(e){
				var elem = this.getNext();
				
				Search.currentItem = elem;
				Search.closePanels();
				elem.tween('height', elem.getStyle('height').toInt() > 0 ? 0 : elem.retrieve('origHeight'));
				
				if (elem.getStyle('height').toInt() > 0) {
					expand.set('class', 'expand open');
				}
				else {
					expand.set('class', 'expand closed');
				}
			});
		});
		Search.closePanels();
	},
	
	buildPanels: function () {
		var h2;
		$('careersBlock').getChildren().each(function(el) {
		    if (el.get('tag') == 'h2') {
		        h2 = new Element('div').inject(el, 'after');
		    } else if (h2) {
		        h2.grab(el);
		    }
		});
	},
	
	closePanels: function() {
		var panels = $$('#careersBlock > div');
		
		panels.each(function(el) {
			if (Search.currentItem != el) {
				el.getPrevious().getElement('span.expand').set('class', 'expand open');
				el.tween('height', 0);
			}
		});
	}
};
window.addEvent('domready', Search.init);
