﻿if (Array.prototype.move == null) {
    Array.prototype.move = function move(index, direction) {
    ///<summary>Method for moving an object in the array.</summary>
    ///<param name="index">Index of the object to move</param>
    ///<param name="direction">Direction up or down</param>
        if (direction.toLowerCase() == 'up') {
            return this.moveUp(index);
        } else if (direction.toLowerCase() == 'down') {
            return this.moveDown(index);
        }
    }
}

if (Array.prototype.moveUp == null) {
    Array.prototype.moveUp = function moveUp(index) {
    ///<summary>Method used to move the object up in the array</summary>
    ///<param name="index">Index of the object to move</param>
        if (index > 0) {
            var tmp = this[index - 1];
            this[index - 1] = this[index];
            this[index] = tmp;
        } else if (index == 0) {
            this.push(this.shift());
        }
    }
}

if (Array.prototype.moveDown == null) {
    Array.prototype.moveDown = function moveDown(index) {
    ///<summary>Method used to move the object down in the array</summary>
    ///<param name="index">Index of the object to move</param>
        if ((index + 1) < this.length) {
            var tmp = this[index + 1];
            this[index + 1] = this[index];
            this[index] = tmp;
        } else if ((index + 1) == this.length) {
            var tmp = this.pop();
            this.unshift(tmp);
        }
    }
}


