/*
 * Extension of ExtJs Javascript Library
 * Written by Khashayar Hajian <me@khashayar.me>
 */

Ext.override(Ext.Element, {
    scrollTo : function(side, value, animate){
    	var side = side.toLowerCase();
        var prop;
    	switch (side) {
    		case "left":
    			prop = "scrollLeft";
    			break;
    		case "right":
    			prop = "scrollLeft";
    			value = this.dom.scrollWidth - (value + this.dom.clientWidth);
    			break;
    		case "top":
    			prop = "scrollTop";
    			break;
    		case "bottom":
    			prop = "scrollTop";
    			value = this.dom.scrollHeight - (value + this.dom.clientHeight);
    			break;
    	}
    	if (value < 0) value = 0;
        if(!animate){
            this.dom[prop] = value;
        }else{
            var to = prop == "scrollLeft" ? [value, this.dom.scrollTop] : [this.dom.scrollLeft, value];
            this.anim({scroll: {"to": to}}, this.preanim(arguments, 2), 'scroll');
        }

        return this;
    }
});
