This function will be called every time a scroll event will occur. Try using throttle pattern to improve preformance and reduce function calls.

example:
https://github.com/cowboy/jquery-throttle-debounce

simpler without jQuery:
http://remysharp.com/2010/07/21/throttling-function-calls/