(function($) {
	$.fn.pages = function(options) {		
		// Default Settings
		var settings = jQuery.extend({
			target: ''
		}, options);		
		
		
		
		this.each(function() {
			var id = $(this).attr("id");
			var nid = id + "pageNav";
			
			var title = $(this).attr("title");
			var div = $("<div id='title'><h2>"+title+"</h2></div>");
			$(this).prepend(div);

			var html = "<ul class='pageNav' id='"+nid+"'></ul>";
			$(div).append(html);
			
			var previous = $("<a href='#' id='first'>&laquo</a>").attr('href','#').click(function() {
				$("ul#"+nid).children("li.selected").prev().click();
				return false;
			});
			$("ul#"+nid).append(previous);
			
			var i=0;
			var parent = this;
			$(parent).children("li.page").each(function() {
				i++;
				$(this).hide();
				$(this).attr("id", id+"page"+i);
				var title = ($(this).attr("title")) ? $(this).attr("title"): "Page "+i;
				var li = $("<li class='"+id+"page"+i+"'>"+title+"</li>").attr('href','#').click(function() {
					$(this).removeClass("over");
					// Hide all Tabs
					$(parent).children("li.page").hide();
					$("ul#"+nid).children("li").removeClass("selected");
					// Get Class for the clicked tab
					var tab = $(this).attr("class");
					$(this).addClass("selected");
					$("li#"+tab).fadeIn();
				});
				$("ul#"+nid).append(li);
			});	
			
			var next = $("<a href='#' id='last'>&raquo</a>").attr('href','#').click(function() {
				$("ul#"+nid).children("li.selected").next().click();
				return false;
			});
			$("ul#"+nid).append(next);
			// Trigger First Click
			$("ul#"+nid).children("li:first").click();
			
			$("ul#"+nid).children("li").hover(
			  function () {
			    $(this).addClass("over");
			    return false;
			  }, 
			  function () {
			    $(this).removeClass("over");
			    return false;
			  }
			);

		});
		
		return;
	}
})(jQuery);
