/* Copyright (c) Fluid Creativity, 2007 */

var initMouseOvers = function(){
	var preload = new Image();

	$$('.rollover').each(function(el){
		if (el.src.test(/\.(gif|jpg|jpeg|png)$/i)) {

			// preload images
			preload.src = el.src.replace(/\.(gif|jpg|jpeg|png)/, '-over.$1');

			el.addEvents({
				mouseover: function(){
					this.src = this.src.replace(/\.(gif|jpg|jpeg|png)/, '-over.$1');
				},

				mouseout: function(){
					this.src = this.src.replace(/-over\.(gif|jpg|jpeg|png)/, '.$1');
				}
			});
		}
	});
};

var initAccordion = function () {
	if ($('legislation')) {
		new Accordion($$('#legislation dl dt'), $$('#legislation dl dd'), {
			alwaysHide: true
		});
	}
};

var initNavigation = function(){
	var initial = -1;
	var current = -1;
	
	$$('.navigation li').each(function(el, i) {
		if (el.hasClass("section")) current++;
		if (el.hasClass("selected")) initial = current;
	});

	$('navigation').accordion = new Accordion($$('.navigation span'), $$('.navigation ul'), {
		alwaysHide: true,
		show: initial,
		onActive: function(el) {
			$(el.parentNode).addClass('selected');
		},
		onBackground: function(el) {
			$(el.parentNode).removeClass('selected');
		}
	});
	
	if ($('newsPopupLink') && $('newsPopup')) {
		var isIE = (parseInt($('page').getStyle('padding-bottom'), 10) != 258);
		
		var fx = new Fx.Styles($('page'), {duration: 400});
		var fx2 = new Fx.Styles($('bottom'), {duration: 400});

		var newsSlider = new Fx.Slide('newsPopup', {duration: 400});
		newsSlider.hide();
		
		$('page').setStyle('padding-bottom', '120px');
		$('bottom').setStyle('margin-top', '-120px');

		$('newsPopupLink').addEvent('click', function(e){
			var size = parseInt($('page').getStyle('padding-bottom'), 10) == 120 ? (isIE ? 276 : 258) : 120;
			
			fx.start({'padding-bottom': size + 'px'});
			fx2.start({'margin-top': -size + 'px'});
			
			newsSlider.toggle();
		});
	}
};


window.addEvent("domready", initNavigation);
window.addEvent("domready", initMouseOvers);
window.addEvent("domready", initAccordion);
