$.fn.pager = function(clas, options) {
	
	var settings = {		
		navId: 'episodePager',
		navClass: 'nav',
		height: 'auto'
	}
	if(options) $.extend(settings, options);
	
	return this.each( function () {
		
		var me = $(this);
		var size;
	  	var i = 0;		
		var navid = '#'+settings.navId;
		
		function init() {
			size = $(clas, me).not(navid).size();
			if(settings.height == null) {			
				settings.height = getHighest();
			}
			size > 1 ? show() : hide();
			sizePanel();
		}
		function show() {
			$(me).find(clas).not(navid).hide();
			var show = $(me).find(clas).not(navid).get(i);
			$(show).show();
			
			// hide the prev link if at beginning
			if (i == 0) {
				$(navid + ' a.previous').hide();
				$(navid + ' span.previous').show();
			} else {
				$(navid + ' a.previous').show();
				$(navid + ' span.previous').hide();
			}
			
			// hide the next link if at end
			if (i >= size - 1) {
				$(navid + ' a.next').hide();
				$(navid + ' span.next').show();
			} else {
				$(navid + ' a.next').show();
				$(navid + ' span.next').hide();
			}
		}
		function hide() {
			// hide all next/prev links since there is only one page (no pagination needed)
			$('#episodePager').hide();
		}
		function sizePanel () {
			if($.browser.msie) {
				$(me).find(clas).not(navid).css( {
					height: settings.height
				});	
			} else {
				$(me).find(clas).not(navid).css( {
					minHeight: settings.height
				});
			}
		}
		function getHighest () {
			var highest = 0;
			$(me).find(clas).not(navid).each(function () {
				
				if(this.offsetHeight > highest) {
					highest = this.offsetHeight;
				}
			});
			highest = highest + "px";
			return highest;
		}
		function getNavHeight () {
			var nav = $(navid).get(0);
			return nav.offsetHeight;
		}
		init();
		$(this).find(navid).find("a").click(function () {

			if($(this).attr('rel') == 'next') {
				if(i + 1 < size) {
					i = i+1;
				}
			} else if($(this).attr('rel') == 'prev') { 
				if(i > 0) {	
					i = i-1;
				}
			} else {		
				var j = $(this).attr('rel');	
				i = j-1;		
			}
			show();
			return false;
		});
	});	
}