What will you use the pagination code for? If it's to link to pages showing data from a database involving server code, e.g. like this forum, an enquiry system, job search results, etc., you might be better off writing this on the server side.
If you still require it in javascript, here are some ideas:
1. Find your total records (whatever they may be).
2. How many will you display per page? 10? 20? Decide.
3. Divide 1 by 2 to get the number of pages. Use the ceil function to get a rounded number upwards.
4. Decide how many numbers to display, e.g. 1 - 5 then ... followed by the last three numbers, etc.
5. The page that you are on should be highlighted. This can be determined by the number that you pass in the URL to determine what page to display.
6. Each page link should begin from 1 + (the number of records per page multiplied by (n-1) with n being the page number, so this will mean for example that page 1 starts from record 1 and page 2 from records 11 (if you're displaying 10 records per page).
See how you get along with that. This should work for any language if you know the basics. There will probably be other ways, but this is worth a try.