Hiding btns

i am trying to hide my prev and next btns when they are not needed.
example at beginning no prev is needed and at end no next btn is needed.

any help my code is below.


stop();
var loc = 30;
//hide btn
prevBtn = function () {
    if (loc<30) {
        loc += 335;
        _root.prevMC._visible = false;
    }else{
        _root.prevMC._visible = true;
    }
};

prevMC.onRelease = function() {
    if (loc<30) {
        loc += 335;
        prevBtn();
    }
};

nextMC.onRelease = function() {
    if (loc>30-(slider_mc._width-335)) {
        loc -= 335;
    }
};
//hide btn
nextBtn = function () {
    if (loc>slider_mc._width-335) {
        _root.nextMC._visible = false;
    }else{
        _root.nextMC._visible = true;
    }
};

slider_mc.onEnterFrame = function() {
    this._x = (loc+this._x)/2;
};