function getAbsolutePath() {
    var loc = window.location;
    var pathName = loc.pathname;

    return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
}

$(document).ready(function(){
	// Initialize jQuery Visualize
	$(function(){
		// Get width of graph container
		var graph_width = $('#statsbox').width() - 60;
                         
		$('#stats').visualize({type: 'line', height: '250px', width: graph_width + 'px'});
		$('table[id=poll]').visualize({type: 'pie', pieMargin: 10, height: '200px', width: '590px'}).appendTo('#poll_stats');
	});

	$(window).resize(function() {
		// Get width of graph container
		var graph_width = $('#statsbox').width() - 60;

		$('.visualize').remove();
		$('#stats').visualize({type: 'line', height: '250px', width: '590px'});
		$('#poll').visualize({type: 'pie', pieMargin: 10, height: '200px', width: '590px', title: 'Poll', colors: defaultColorScheme}).appendTo('#visualize_demo2');
	});

    // Uniform checkboxes and radios.
    $('#selection select, :checkbox, :radio, :file').uniform();

    $('#gallery a').lightBox(); // Select all links in object with gallery ID

	// Vaak gestelde vragen
    $('input[name*=faq]').change(function() {
    	// Eerst alles omhoog schuiven, indien zichtbaar
    	$('p.hw:visible').slideUp();

    	$('p#hw-exp-' + $(this).val()).slideDown(200);
    });

	$('#msn,#skype,#hyves,#facebook,#website,#mobile').keyup(function() {
		if ($('#' + $(this).attr('id')).val() != "") {
    		$('input#show_' + $(this).attr('id')).attr('checked', 'true');
    		$('div#uniform-show_' + $(this).attr('id') + ' span').attr('class', 'checked');
		} else {
    		$('input#show_' + $(this).attr('id')).attr('checked', 'false');
    		$('div#uniform-show_' + $(this).attr('id') + ' span').attr('class', '');
		}
    });

    $("div.choice select").change(function () {
    	var query = new Array;
    	$("div.choice select").each(function () {
        	query.push($(this).attr('name') + "=" + $("option:selected", this).val());
        });

		window.location.href = getAbsolutePath() + "?" + query.join("&");
		return true;
	});
});
