function foreach(f, a, s)
{
    a = ("undefined"==typeof(a) ? [] : a);
    for(var i=0; i<a.length; i++) f(a[i], s);
}

function map(f, a, s)
{
    a = ("undefined"==typeof(a) ? [] : a);
    for(var i=0; i<a.length; i++) a[i] = f(a[i], s);
    return a;
}

function reduce(f, a, s)
{
    var i, r = ("undefined"!=typeof(s) ? s : null);
    a = ("undefined"==typeof(a) ? [] : a);
    for(i=0; i<a.length; i++) r = f(a[i], r);
    return r;
}

function filter(f, a, s)
{
    var i, l = [];
    a = ("undefined"==typeof(a) ? [] : a);
    for(i=0; i<a.length; i++) if(f(a[i], s)) l.push(a[i]);
    return l;
}

function iota(c, b, s)
{
    var i, e, a = [];
    c = parseInt(c);
    b = ("undefined"==typeof(b) || !b) ? 0 : parseInt(b);
    s = ("undefined"==typeof(s) || !s) ? 1 : parseInt(s);
    e = parseInt(b + (c-1) * s);
    for(i=b; i<=e; i+=s) a.push(i);
    return a;
}

function repeat(f, n, s)
{
    for(var i=0; i<n; i++) f(s);
}

function using(w)
{
    var i, a = ["foreach", "map", "reduce", "filter", "iota", "repeat"];
    for(i=0; i<a.length; i++) w[a[i]] = self[a[i]];
    w["$"] = function(id){ return w.document.getElementById(id); };
}

self["$"] = function(id){ return self.document.getElementById(id); };

function position(obj, al, pnt, ox, oy)
{
    var hal = al,
        x = 0,
        y = 0,
        m = 0;
    while(hal.tagName!="BODY") {
        x += hal.offsetLeft;
        y += hal.offsetTop;
        hal = hal.offsetParent;
    }
    x = (pnt=="tr" || pnt=="br") ? x + al.clientWidth : x;
    y = (pnt=="br" || pnt=="bl") ? y + al.clientHeight : y;
    obj.style.top = y + oy + "px";
    obj.style.left = x + ox + "px";
}


