(function($){
    var featuresScroll = {
        backToTop: function(){
            if(navigator.userAgent.indexOf('MSIE') != -1){
                document.location.hash = "master_container";
                document.location.hash = "";
            } else {
                $(window)._scrollable().scrollTo(document.getElementById('master_container'), 500, function(){
                    document.location.hash = "";
                });
            }
        },
        
        scroll: function(hash){
            var self = this;
            
            if(navigator.userAgent.indexOf('MSIE') != -1){
                document.location.hash = hash;
                this.highlight(hash);
            } else {
                $(window)._scrollable().scrollTo('#' + hash, 500, {
                    onAfter: function(){
                        self.highlight(hash);
                    }
                });
            }
        },
        
        highlight: function(hash){
            document.location.hash = hash;
            
            if($('#' + hash + ' .featureGradient').length == 0){
                var featureGradient = document.createElement('DIV');
                    featureGradient.className = "featureGradient";
                    featureGradient.style.display = "none";
                $('#' + hash+ ' .featureBlockInner')[0].appendChild(featureGradient);
            }
            
            var theGradient = $('#' + hash + ' .featureGradient');
            theGradient.fadeIn(500, function(){
                setTimeout(function(){
                    theGradient.fadeOut(1000, function(){
                        theGradient.remove();
                    });
                }, 750);
            });
        },
        
        init: function(){
            var self = this;
            $('#feature_index a').click(function(event){
                event.preventDefault();
                self.scroll(this.href.split('#')[1]);
            });
            $('.featureBlock a.backToTop').click(function(event){
                event.preventDefault();
                self.backToTop();
            });
        }
    };
    $(document).ready(function(){
        featuresScroll.init();
    });
})(jQuery); 