/* plugin to create an in-page nav menu from a query */
//dependables: ifxscrollto.js, easing.js, iutil.js

/* scrollTo taken from the Interface plugin for jQuery
 * Copyright (c) 2006 Stefan Petre - http://interface.eyecon.ro
 */
$.fn.contentMenu = function(o){
	o = $.extend({
		"head"		: "<h3>Some handy links to help you navigate this page</h3>",
		"beforeLink": "&raquo; ",
		"divClass"	: "contentMenu",
		"aClass"	: "inPage",
		"insertMethod"	: "insertBefore",
		"insertTarget"	: this.eq(0) }, o || {});
	$.cmCount = $.cmCount+1 || 0;
	var $list = $("<ul>");
	var lastInd = this.length-1;
	var lis = '';
	var menu = $('<div class="'+o.divClass+'"></div>').append(o.head,$list);
	switch (o.insertMethod){
		case "insertAfter":
			menu.insertAfter(o.insertTarget);
			break;
		case "append":
			o.insertTarget.append(menu);
			break;
		case "prepend":
			o.insertTarget.prepend(menu);
			break;
		default :
			menu.insertBefore(o.insertTarget);
	}
	return $(this).each(function(i){
		$(this).attr("id", $(this).attr("id") || "menu"+$.cmCount+"-el"+i);
		lis += '<li><a href="#'+$(this).attr("id")+'" class="'+o.aClass+'">'+o.beforeLink+'<em>'+$(this).text()+'</em></a></li>';
		if (i==lastInd){ $list.append(lis); }
	});
};

/* apply the scroll */
$.fn.scrollToHash = function(){
	return this.each(function(){
		$(this).click(function(){
			$(this.hash).ScrollTo(1500,'easeout')[0].blur();
			return false;
		});
	});
};

$(document).ready(function(){
	$("body").find("#main h3").contentMenu({aClass:"scrolls",divClass:"alert",beforeLink:"&raquo; "});
	$("a.scrolls").scrollToHash();
});
// check http://www.preshil.vic.edu.au/news/diary/

