var Site = {
	start: function() {
		if ($('news_scroller')) new NewsScroller('news_scroller', 'NewsData/');
		
		var panels = ($(document.body).getElement('div.expandablepanels'))
		if (panels) Site.addExpandablePanels();
		
		$$('a.ext').each(function(a) {
			a.addEvent('click', function(e) {
				e.stop();
				window.open(a, '_blank');
			});
		});
		$$('a.ext-icon').each(function(a) {
			new Element('img', {'src':'images/externallink.gif', 'styles':{'margin-left':'4px'}}).inject(a, 'after');
		});
		$$('a.alert').each(function(a) {
			a.addEvent('click', function(e) {
				e.stop();
				Site.redirectBox('<p>You are leaving the web domain of the Government of Newfoundland and Labrador. The Government of Newfoundland and Labrador is not responsible for the content of external sites</p>', a);
			});
		});
	},
	addExpandablePanels: function() {
		var togglers = $$('div.expandablepanels div.summary');
		var elements = $$('div.expandablepanels div.details');
		var accordion = new Fx.Accordion(togglers, elements, {
			alwaysHide: true,
			display: -1,
			onActive: function(tog, el) {
				tog.addClass('expanded');
			},
			onBackground: function(tog, el) {
				tog.removeClass('expanded');
			}
		});
		$$('div.summary').each(function(el) {
			el.addEvents({
				mouseenter: function() { el.addClass('highlight'); },
				mouseleave: function() { el.removeClass('highlight'); }
			});
		});
	},
	redirectBox: function(html, href) {
		var overlay = new Element('div', {
			'class':'redirect-overlay',
			'styles': {
				'display':'block',
				'position':'absolute',
				'top':0,
				'left':0,
				'z-index':10000,
				'opacity':.5,
				'width':'100%',
				'height':$(document.body).getScrollSize().y
			}
		});
		var box = new Element('div', {
			'class':'redirect-box',
			'styles': {
				'display':'block',
				'position':'absolute',
				'top':(window.getSize().y/2)+window.getScroll().y-200,
				'left':(window.getSize().x/2)-300,
				'z-index':10001,
				'width':600,
				'height':250
			}
		});
		new Element('div', {'class':'redirect-content', 'html':html}).inject(box);
		new Element('a', {
			'class':'redirect-ok',
			'events': {
				'click': function(e) {
					e.stop();
					this.getParent().getPrevious().destroy();
					this.getParent().destroy();
					window.open(href, '_blank');
				}
			},
			'href':'#',
			'text':'OK'
		}).inject(box);
		new Element('a', {
			'class':'redirect-cancel',
			'events': {
				'click': function(e) {
					e.stop();
					this.getParent().getPrevious().destroy();
					this.getParent().destroy();
				}
			},
			'href':'#',
			'text':'Cancel'
		}).inject(box);
		overlay.inject($(document.body));
		box.inject($(document.body));
	}
};

window.addEvent('domready', function(){
	Site.start();
});