function scrollTo(url, speed, easing, redirect){

url = url || "#";
speed = speed || "fast";
easing = easing || null;
redirect = (redirect === true || redirect == null) ? true : false;

if(url){

    if(url.indexOf("#") != -1){

        var aParts = url.split("#",2);
        var anchor = $("a[id='"+aParts[1]+"']");

        if(anchor){

            if($(document).height()-anchor.offset().top >= $(window).height()
            || anchor.offset().top > $(window).height()
            || $(document).width()-anchor.offset().left >= $(window).width()
            || anchor.offset().left > $(window).width()){

            $('html, body').animate({
            scrollTop: anchor.offset().top,
            scrollLeft: anchor.offset().left
            }, speed, easing, function(){
                if(redirect){
                window.location = url
                }
                });

            }
            return false;
            }
        }
    }
}(jQuery);  
