/*
** Last Minute Leiden ~ lml.js
** Author:    Lodewijk Schutte ~ Low
** Last edit: 20100517
*/

var LML = new Object;

LML.SelectStudie = {
	init: function() {
		var select = $('selectstudie');
		var form = $('selectstudieform');
		if (!select || !form) return;
		form.getElement('button').dispose();
		select.addEvent('change', function() {
			//form.submit();
			var val = this.get('value');
			var act = form.get('action');
			location.href = act + val + '/#middag';
		});
	}
};

LML.Popups = {

	init: function() {
		var els = $$('table div.more');
		if (!els.length) return;

		els.each(function(el){
			var cell = el.getParent();
			var row = cell.getParent();
			var title = el.getPrevious();
			var text = '<h2>'+title.get('text')+'</h2>'+el.get('html');
			
			cell.addClass('popup');
			cell.addEvent('click', function(){LML.LowBox.open(text, row.className);return false;});
		});
	}
};

LML.Toggle = {
	init: function() {
		var els = $$('#primary div.item');
		if (!els.length) return;
		
		els.each(function(el){
			var trigger = el.getElement('h3 a');
			var target = el.getElement('div.hidden');
			if (!trigger || !target) return;
			trigger.addEvent('click',function(e){
				e.stop();
				target.toggleClass('hidden');
			});
		})
	}
};

LML.LowBox = {
	// --- Start aanpasbare instellingen
	closeText	: 'Sluit venster',
	loadingText	: 'Laden...',
	nextText	: 'Volgende',
	prevText	: 'Vorige',
	suffix		: '_snippet',
	opacity		: 2,
	offset		: 75,
	prevImg		: '/images/icon_lt.gif',
	nextImg		: '/images/icon_gt.gif',
	useNames	: false, 
	loop		: false, 
	debug		: true,
	setClass: function(str) {
		this.box.className = str;
	},
	open: function(txt, clas) {
		// turn on overlay and box
		this.overlay.style.display = this.box.style.display = 'block';
		this.box.style.top = (window.getScroll().y + this.offset) + 'px';
		this.content.innerHTML = txt;
		this.box.className = clas;
		this.status = true;
	},
	opened: function() {this.box.removeClass('loading');},
	closeBox: function() {
		this.overlay.style.display = 'none';
		this.box.style.display = 'none';
		this.content.innerHTML = '';
		this.status = false;
		return false;	
	},
	init: function() {
		// transparent overlay
		this.overlay = new Element('div',{
			id: 'lowover',
			styles: {
				display: 'none',
				opacity: this.opacity/10,
				filter: 'alpha(opacity=' + this.opacity*10 + ')'
			},
			events: {
				click: this.closeBox.bind(this)
			}
		});
		document.body.appendChild(this.overlay);

		this.box = new Element('div',{
			id: 'lowbox',
			styles: {display: 'none'}
		});
		document.body.appendChild(this.box);
		
		this.content = new Element('div');
		this.content.set('load',{onComplete:this.opened.bind(this)});
		this.box.appendChild(this.content);
				
		this.closeLink = document.createElement('a');
		this.closeLink.id = 'closebox';
		this.closeLink.href = '#';
		this.closeLink.onclick = this.closeBox.bind(this);
		this.closeLink.appendChild(document.createTextNode('Sluiten'));
		this.box.appendChild(this.closeLink);
	}
};

// ----- INITIATE HASH 

for (var i in LML) {
	if (typeof LML[i].init == 'function') {
		window.addEvent('domready', LML[i].init.bind(LML[i]));
	}
}
