/* moved to configuration */
var wbids_bobprice_timeout = 20;

function wBidsEffect(interval, frames, color) {
    var self = this;

    self.intervalObject = false;
    self.interval = interval;
    self.frames = frames;
    self.color = color;

    /* cache all item data */
    self.cache = new Array();

    self.setOpacity = function(el, opacity) {
        el.style.opacity = opacity / 100;
        el.style.filter = 'alpha(opacity = '+opacity+')';
        el.style.zoom = '1';
    }

    self.start = function(id, price) {
        if(typeof self.cache[id] == 'undefined') {
            try {
                var bobEl = document.getElementById("bob"+id);
                var priceEl = document.getElementById("p_price"+id);
                self.cache[id] = new Object();
                self.cache[id].bobEl = bobEl;
                self.cache[id].priceEl = priceEl;
                bobEl.style.backgroundColor = self.color;
            } catch(e) {
                dprint("Product "+id+" does not have a bob element!");
            }
        }
        self.setOpacity(self.cache[id].bobEl, 100);
        self.cache[id].frame = 0;
        self.cache[id].priceEl.innerHTML = formatPrice(price);

        if(!self.intervalObject)
            self.intervalObject = setInterval(self.iterate, self.interval);
    }

    self.iterate = function() {
        var active = 0;

        for(var id in self.cache) {
            if(self.cache[id].frame < self.frames+1) {
                self.setOpacity(self.cache[id].bobEl, 100-((self.cache[id].frame / self.frames) * 100));
                self.cache[id].frame++;
                active++;
            }
        }

        if(active == 0) {
            clearInterval(self.intervalObject);
            self.intervalObject = false;
        }
    }

    self.reset = function() {
        delete self.cache;
        self.cache = new Array();
    }
}

var wbids_bob = false;

function wbids_bobprice(id, price)
{
    if(typeof wbids_bob == 'object')
        wbids_bob.start(id,price);
    if(typeof wbids_custom_bobprice == 'function')
        wbids_custom_bobprice(id,price);
}
