var LOG_WAITTIME = 1000;

function Logger() {
    this.logConstant = {
        ACTION_ROUTING_SEGMENT: "routingSegment",
        ACTION_ROUTING_FROM_BQC: "routingFromBQC",
        ACTION_PROXIMITY_SEARCH: "proximitySearch",
        ACTION_SEARCH_CATEGORY: "searchCategory",
        ACTION_PROXIMITY_SELECT_CATEGORY: "proximitySelectCategory",
        ACTION_ROUTING_FROM_PROXIMITY: "routingFromProximity",
        ACTION_SEARCH_REGION: "searchRegion",
        ACTION_MINIMAP: "displayMinimap",
        ACTION_PROXIMITY: "proximity"
    };
    this.logs = [];
    this.lastLogTime = 0;
}

Logger.prototype.route = function(from, to){
    this.log(null, null, bqc.params.p_mode, bqc.params.p_fromSite, "ACTION_ROUTING_FROM_PROXIMITY", "");
}

Logger.prototype.log = function(addId, tooId, mode, fromSite, action, infos){
    var params = new Object();
    if(addId){
        params.addId = addId;
    }
    if(tooId){
        params.tooId = tooId;
    }
    if(mode){
        params.mode = mode;
    }
    if(fromSite){
        params.fromSite = fromSite;
    }
    if(action){
        params.action = this.logConstant[action];
    }
    if(infos){
        params.infos = infos;
    }
    params.p_lcode = bqc.params.p_lcode;
    this.doLog(params);
}

Logger.prototype.doLog = function(log) {
    var that = this;
    this.logs.push(log);
    var logTime = this.lastLogTime = new Date().getTime();
    window.setTimeout(function() {
        if (logTime == that.lastLogTime) {
            new Ajax.Request("bqc/hitLogger.do", {
                method: 'post',
                parameters: {
                    logs: that.logs.toJSON()
                }
            });
            that.logs = [];
        }
    }, LOG_WAITTIME);
}

