﻿/*  Systematic - javascript for featurelist By: Steen F. Tøttrup / Illumi a/s */
var PopUp = new Class({ Implements: Options, options: { closeDelay: 100, containerId: '', layerId: '' },
	initialize: function(options) {
		this.setOptions(options);
		if ($(this.options.containerId)) {
			this.container = $(this.options.containerId);
		}
		if ($(this.options.layerId)) {
			this.layerId = $(this.options.layerId);
		}
		this.container.getChildren('a').each(function(item, index) {
			item.addEvent('mouseover', function() { this.Open(); } .bind(this));
			if (index == 1) {
				item.addEvent('mouseleave', function() { this.closeDelay = this.Close.bind(this).delay(this.options.closeDelay); } .bind(this));
			}
		} .bind(this));
		this.layerId.addEvent('mouseleave', function() { this.closeDelay = this.Close.bind(this).delay(this.options.closeDelay); } .bind(this));
		this.layerId.addEvent('mouseover', function() { $clear(this.closeDelay); } .bind(this));
	},
	Open: function() {
		this.layerId.set('style', 'display: block');
		$clear(this.closeDelay);

		this.container.getChildren('a').each(function(item, index) {
			var oldClass = item.get('class');
			if (oldClass.length > 0 && !oldClass.match('selected$')) {
				item.set('class', oldClass + ' selected');
			}
		} .bind(this));
	},
	Close: function() {
		this.layerId.set('style', 'display: none');
		$clear(this.closeDelay);
		this.closeDelay = null;
		this.container.getChildren('a').each(function(item, index) {
			var oldClass = item.get('class');
			if (oldClass.length > 0 && oldClass.match('selected$')) {var newClass = oldClass.replace(' selected', '');item.set('class', newClass);}
		} .bind(this));
	}
});
window.addEvent('domready', function() {if ($('area-defence')) {var popup1 = new PopUp({ containerId: 'area-defence', layerId: 'splash-defence' });}});
window.addEvent('domready', function() {if ($('area-healthcare')) {var popup2 = new PopUp({ containerId: 'area-healthcare', layerId: 'splash-healthcare' });}});
window.addEvent('domready', function() { if ($('area-int')) { var popup3 = new PopUp({ containerId: 'area-int', layerId: 'splash-intelligence' }); } });
window.addEvent('domready', function() { if ($('area-is')) { var popup4 = new PopUp({ containerId: 'area-is', layerId: 'splash-integration' }); } });
