/*
# algemene javascript functies
# ###############
# Onderdeel van ONS CMS
# © 2008
# Versie: 1.00
# Module: core
# ###############
*/

function showOverlay(closeElements) {
	// overlay bouwen (als je daar op klikt, worden de popups weer gesloten)
	var overlay = new Element('div', {
		'title': 'Klik om te sluiten',
		'class': 'overlay',
		'id': 'overlay',
		'styles': {
			'position': 'absolute',
			'top': 0,
			'left': 0,
			'height': document.window.getScrollSize().y,
			'width': document.window.getScrollSize().x,
			'z-index': 10
		},
		'events': {
			'click': function() {
				closeElements.each(function(el) {
					el.destroy();
				});
				this.destroy();
			}
		}
	}).inject(document.body);
}

// overlay sluiten
function closeOverlay() {
	if ($defined($('overlay')))
		$('overlay').destroy();
}

function addslashes(str) {
	return str.replace(/(['"\\\x00])/g, "\\$1");
}

// een clear div maken
function clearDiv(where) {
	new Element('div', {
		'class': 'clear'
	}).inject(where);
}

window.addEvent('domready', function() {
	// uitklappen van items in een expandable list
	$$('ul.expandable-list li.expand').each(function(li) {
		var id = li.get('id').split('.');
		// animatie
		$$('.' + id[1]).set('slide', {duration: 'short'}).slide('hide').setStyle('display', 'block');
		// actie
		li.addEvent('click', function(e) {
			e.stop();
			document.body.focus();
			
			var id = this.get('id').split('.');
			$$('.' + id[1]).slide('toggle');
			this.toggleClass('expanded');
		});
	});
	
	// selects die ergens heenleiden
	$$('select.go-to-url').each(function(select) {
		select.addEvent('change', function() {
			var options = JSON.decode(this.get('rel'));
			// niet nul of huidig?
			if (this.get('value') != '' && this.get('value') != options.current_id) {
				location.href = options.url.replace('$id', this.get('value'));
			}
		});
	});
});