// Cache, author cp, 15.08.2006
function Cache(capacity) {
    this.capacity  = capacity || 10;
    this.numHits    = 0;
    this.numMisses  = 0;
}
Cache.prototype = {
    get: function (key) {},
    put: function (key, value) {},
    getHitRatio: function () {
        if (this.numMisses==0) {
            return this.numHits;
        }
        var ratio = (this.numHits * 100) / (this.numMisses + this.numHits);
        return ratio.toPrecision(2);
    },
    getCapacity: function () {
        return this.capacity
    }
}
function HashMap() {
    this.hashMap = new Object();
    this.size    = 0;
}
HashMap.prototype = {
    get: function (key) {
        return this.hashMap[key];
    },
    put: function (key, value) {
        if (key == null || typeof key == 'undefined') {
            throw new Error("Key is null or undefined!");
        } else {
            if (!this.keyExists(key)) {
                this.size++;
                this.hashMap[key] = value;
            }
        }
    },
    remove: function (key) {
        try {
            delete this.hashMap[key];
            this.size--;
        } catch (e) {}
    },
    shift: function () {
        try {
            for (key in this.hashMap) {
                var value = this.hashMap[key];
                delete this.hashMap[key];
                this.size--;
                return value;
            }
        } catch (e) {}
        return null;
    },
    keyExists: function (key) {
        var value = this.hashMap[key];
        if (typeof value == 'undefined') {
            return false;
        }
        return true;
    },
    getMap: function () {
        return this.hashMap;
    },
    getSizeOf: function () {
        return this.size;
    }
}

// CachedMap, dekoriert die HashMap
function CachedMap(CacheStrategy) {
    this.cache = CacheStrategy;
}
CachedMap.prototype = {
    get: function (key) {
            return this.cache.get(key);
    },
    put: function (key, value) {
        if (value != null && typeof value != 'undefined') {
            this.cache.put(key, value);
        }
    },
    remove: function (key) {
        this.cache.map.remove(key);
    },
    getMap: function () {
        return this.cache.map.getMap();
    },
    getSizeOf: function () {
        return this.cache.map.getSizeOf();
    },
    getHitRatio: function () {
        return this.cache.getHitRatio();
    }
}

function FiFoCache(capacity) {
    this.map   = new HashMap();
    this.base  = Cache;
    this.base(capacity);
}
FiFoCache.prototype = new Cache;
FiFoCache.prototype =  {
    get: function (key) {
        var value = this.map.get(key);
        if (typeof value != 'undefined') {
            this.numHits++;
            return value;
        }
        this.numMisses++;
        return null;
    },
    put: function (key, value) {
        if (this.capacity == this.map.getSizeOf()) {
            if (!this.map.keyExists(key)) {
                this.map.shift();
            }
        }
        this.map.put(key, value);
    }
}


// Start Class LayerSwitch
function LayerSwitch() {
    // Fields
    this.layer=[];
    this.isDOM=document.getElementById?true:false;
}
LayerSwitch.prototype.laysw_registerLayerByID = function (id) {
    if (!this.isDOM) {
        return false;
    }
    var layerId=""+id;
    this.layer[layerId]=document.getElementById(layerId);
    return true;
}
LayerSwitch.prototype.laysw_switchLayer = function (activeLayerId) {
    if (!this.isDOM) {
        return false;
    }
    for (var layerId in this.layer) {
      if (layerId.indexOf('ay_')>0 || layerId.indexOf('ontent')>0)
      {
        if (activeLayerId == layerId) {
            this.layer[layerId].style.visibility = "visible";
            this.layer[layerId].style.display = "inline";
            continue;
        }
        this.layer[layerId].style.visibility = "hidden";
        this.layer[layerId].style.display = "none";
      }
    }
    return true;
}
// Ende Class LayerSwitch

// counter
function OfferCounter(counterElement, countingSpeed) {
    this.numOffers      = 0;
    this.counterElement = counterElement;
    this.countingSpeed  = countingSpeed || 500;
    this.showNumOffers();
}
OfferCounter.prototype = {
    showNumOffers: function () {
        if (this.counterElement) {
            this.counterElement.innerHTML = this.numOffers;
        }
    },
    run: function () {
        this.numOffers++;
        this.showNumOffers();
        var self = this;
        window.setTimeout(
            function() {
                self.run();
            },
            this.countingSpeed
        );
    }
}
