// Aon submenu
// 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.aonsubmainmenu = 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(trim(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 second part of bodyId equals the link of this submenu, it must be made active.
			var bodyIdParts = bodyid.split("_");
			if(bodyIdParts[1] == id) {
				$(this).addClass("submainmenu_active");
			}
			
			// Generate html
			$(this).html("<a href='" + loc + "'>" + $(this).attr("title") + "</a>");
	});
}
