// JQuery helper to get an url parameter
// Usage: getUrlParameter('my-url-parameter');
var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};

// Detect if the current url contains a "open" parameter, it it's the case, open
// the parameter url in a modal
$(document).ready(function(){
    var modalUrl = getUrlParameter('modal-url');
    if (modalUrl) {
        var $modal = buildModal();
        $.get(modalUrl, {}, function(data){
    		$('.modal-content', $modal).html(data);
    		$modal.modal('show');
    	});
    }
});
