// Aon mainmenu
// Created by Juda van Mourik, 2008
// Only to be used in Aon Products


function trim(value) {
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  return value;
}

// options are not implemented in this release
jQuery.fn.aonmainmenu = function(options) {
		
	this.find("li").each(function() {

			// Get target
			var loc, id;
			loc = new String(trim($(this).html()));
			var locations = loc.split("/");
			var overruleId = $(this).attr("id");

			// Generate class
			var bodyid = $("body").attr("id");
			if(loc.substring(loc.length - 1) == "/") id = locations[locations.length - 2];
			else id = locations[locations.length - 1];

			if(overruleId != null && overruleId != "") id = overruleId;

			// IE Fix :) 
			id = trim(id);
			
			// If first part of bodyId equals the link of this menu, it must be made active.
			var bodyIdParts = bodyid.split("_");
			if(bodyIdParts[0] == id) {
				$(this).addClass("mainmenu_active");
			}
			
			//Only change menuitems containing a link
			var title = $(this).attr("title");
			if(title != null && title != "" && title != "undefined") {
				// Generate html
				$(this).html("<a href='" + loc + "'>" + title + "</a>");
			}
		});
}