/**
 * Keuze hulp popup
 * 
 */

GlobalArena.Keuzehulp = (function($) {

	var Keuzehulp = {
		initialize:function() {
			var root = $('#keuzehulp');
			if(root.length) {
				this.root = root;
				this.overlay = $('#keuzehulp-overlay');
				$(document).addRelation(/keuzehulp/, this.handleClick.bind(this));

				this.root.find('div.criterium input').each(function(){
					var input = $(this);
					var slider = 
						$('<span class="slider">' + 
							'<span class="value"></span>' + 
							'<span class="indicator"></span>' + 
							'<span class="thumb"></span>' + 
						'</span>');

					input.after(slider);
					input.hide();

					slider.slider({min:0, max:100, increment:10});
				});
			}
		},

		handleClick: function(link, rel) {
			var type = /keuzehulp-?([^ ]+)/.exec(rel)[1];
			switch (type) {
				case 'tab':
					this.triggerTab(link.hash);
				break;
				case 'open':
					this.open();
				break;
				case 'close':
					this.close();
				break;
					
			}
			return true;
		},

		triggerTab:function(hash) {
			var tab = $('.tabs a[href="' + hash + '"]');
			tab.trigger('click');
		},

		open: function() {
			this.overlay.fadeIn();
			this.root.fadeIn();
		},

		close: function() {
			this.overlay.fadeOut();
			this.root.fadeOut();
		}
	}

	$(function() {
		Keuzehulp.initialize();
	});

	return Keuzehulp;

})(jQuery);
