function Resizeable(obj){

    obj.minWidth = 165;
    obj.minHeight = 120;

    obj.setWidth = function(value){
        if(value < obj.minWidth){
            obj.width = obj.minWidth;
            obj.style.width = obj.minWidth + "px";
            return false;
        }
        obj.width = value;
        obj.style.width = value + "px";
        return true;
    };

    obj.setHeight = function(value){
        if(value < obj.minHeight){
            obj.height = obj.minHeight;
            obj.style.height = obj.minHeight + "px";
            return false;
        }
        obj.height = value;
        obj.style.height = value + "px";
        return true;
    };

    var addResize = function(){
        var rFunc = function(){ resize(obj);};
        var vFunc = function(){ obj.validate();};
        document.addSubscriber("onmousemove",rFunc);
        document.addSubscriber("onmousemove",vFunc);
        var removeFunc = function(){
            document.removeSubscriber(rFunc,"onmousemove",false);
            document.removeSubscriber(vFunc,"onmousemove",false);
            document.removeSubscriber(removeFunc,"onmouseup",false);
        };
        document.addSubscriber("onmouseup",removeFunc);
    };

    var resize  = function(obj){
        var objWidth = System.display.getObjectWidth(obj);
        var mouseDiffs = System.display.getMouseChange();
        var objHeight = System.display.getObjectHeight(obj);
        var objLeft = obj.offsetLeft;
        var objTop = obj.offsetTop;
        var direction = obj.direction;
        var result;
        if(direction !== undefined){
            switch(direction){
                case "n":
                    if(obj.setHeight(objHeight - mouseDiffs[1])){
                        result = obj.setTop(objTop + mouseDiffs[1]);
                    }
                    break;
                case "ne":
                    if( obj.setWidth(objWidth + mouseDiffs[0])){
                        result = obj.setLeft(objLeft);
                    }
                    if(obj.setHeight(objHeight - mouseDiffs[1])){
                        result = obj.setTop(objTop + mouseDiffs[1]);
                    }
                    break;
                case "e":
                    if(obj.setWidth(objWidth + mouseDiffs[0])){
                        result = obj.setLeft(objLeft);
                    }
                    break;
                case "se":
                    if(obj.setWidth(objWidth + mouseDiffs[0])){
                        result = obj.setLeft(objLeft);
                    }
                    if (obj.setHeight(objHeight + mouseDiffs[1])){
                        result = obj.setTop(objTop);
                    }
                    break;
                case "s":
                    if(obj.setHeight(objHeight + mouseDiffs[1])){
                        result = obj.style.top = objTop + "px";
                    }
                    break;
                case "sw":
                    if(obj.setHeight(objHeight + mouseDiffs[1])){
                        result = obj.setTop(objTop);
                    }
                    if(obj.setWidth(objWidth - mouseDiffs[0])){
                        result = obj.setLeft(objLeft + mouseDiffs[0]);
                    }
                    break;
                case "w":
                    if(obj.setWidth(objWidth - mouseDiffs[0])){
                        result = obj.setLeft(objLeft + mouseDiffs[0]);
                    }
                    break;
                case "nw":
                    if (obj.setHeight(objHeight - mouseDiffs[1])){
                        result = obj.setTop(objTop + mouseDiffs[1]);
                    }
                    if (obj.setWidth(objWidth - mouseDiffs[0])){
                        result = obj.setLeft(objLeft + mouseDiffs[0]);
                    }
                    break;
            }
            return result;
        }
        return false;
    };
    
    obj.addOnResize = function(action){ obj.addSubscriber("resize", action); };
    obj.addOnResize(addResize);

    return obj;

}

