var NVAJAX_DEFAULT_TARGET = 'nvAjaxDefaultTarget';
var NVAJAX_ALL_TARGET = 'nvAjaxAllTargets';

/**
 * Loads an url to the specified target element via ajax.
 * If the targetID given is NVAJAX_DEFAULT_TARGET, by default the function will try to search
 * for the first parent of the calling element which has the class NVAJAX_TARGET_CLASS set
 * and load the content in it. If the parent is not found, an element with id
 * NVAJAX_DEFAULT_TARGET is set as target. If that fails also, then the targetID parameter
 * is used as the element id and the content is loaded into that element if found.
 *
 * @param e        the element which triggered the call for this function
 * @param targetID ID of the element in which the url should be loaded
 * @param href     the url to load
 *
 * @return boolean always returns false, so links are not followed when used in onclick - handlers
 */
function nvAjaxLoad(e, targetID, url) {
    var target = null;
    if (targetID == NVAJAX_DEFAULT_TARGET) {
        target = $(e).parents('.nvAjaxContainer:first');
        if (!target || target.length == 0) {
            target = $('#'+NVAJAX_DEFAULT_TARGET);
        }
    } else if (targetID == NVAJAX_ALL_TARGET) {
        target = $('.nvAjaxContainer');
    }
    if (!target || target.length == 0) {
        target = $(targetID);
    }
    if (target && target.length > 0) {
        target.load(url);
    }
//    $.historyLoad(url);
    return false;
}

//function pageload(href) {
//    console.log("Foo: %o", href);
//}

//$(document).ready(function() {
//    $.historyInit(pageload);
//});
