var LibArray = function () {};
LibArray.prototype.inArray = function (needle, haystack) {
    var i=0,length = haystack.length;
    for (i;i<length;i++) {
        if (haystack[i] == needle) {
            return true;
        }
    }
    return false;
};
window.libArray = new LibArray();

var ArrayA = function () {
    var array;
    if (arguments.length == 1 && arguments[0] instanceof Array) {
        array = arguments[0];
    } else if (arguments.length == 1 && arguments[0] instanceof Object) {
        array = Array.prototype.slice.apply(arguments[0]);
    } else {
        /**
         * Transform the pseudo Array 'arguments' to a real one
         */
        array = Array.prototype.slice.apply(arguments);
    }
    /**
     * Inherit from this.Functions
     * this method does not change the length property
     * of the array. We can use it to check if value is valid
     */
    for (var i in this.Functions) {
        array[i] = this.Functions[i];
    }
    return array;
};

ArrayA.prototype.Functions = {
    index:0,
    /**
     * rewind to index 0 or index add
     */
    rewind:function (add) {
        add=add||0;
        this.index=0+add;
        return this.index;
    },
    /**
     * Iterate one step
     */
    step:function () {
        return this[this.index++];
    },
    /**
     * is ist valid?
     * @param INT subtract valid up to (length - subtract), default 0
     */
    valid:function (subtract) {
        subtract = subtract || 0;
        return this.index < this.length-subtract ? true : false;
    },
    /**
     * return current
     */
    current:function(){
        return this[this.index];
    },
    /**
     * return the sheer Array
     */
    get:function () {
        var a = [];
        this.foreach(function (value) {
            a.push(value);
        });
        return a;
    },
    /**
     * find needle in array
     * @param STRING needle
     */
    inArray:function (needle) {
        var test = false;
        this.foreach(function (value) {
            if (value == needle) {
                test = true;
            }
        });
        return test;
    },
    /**
     * automatically iterate
     * dont forget the Callback
     * that can take up to three arguments:
     * value: current value
     * key: current key
     * this: the ArrayA Object
     * 
     * @param FUNCTION func
     */
    foreach:function(func) {
        if(typeof func=="function") {
            var key=0;
            while(key<this.length) {
                value=this[key];
                if(typeof value!="undefined") {
                    func(value,key,this);
                }
                key++;
            }
        } else {
            throw(new Error("No callback function given."));
        }
    }
};










/**
 *
 * Testen...
Array.prototype.inArray = function (member) {
    return !!this[member];
}

var la = [];
la.push('huhu');
la.push('bla');
la.push('honk');


for (var i in la) {
    if (la.hasOwnProperty(i)) {
        console.log(i, la[i]);
    }
}
 */



