/*
 * jQuery navigation bar for FWN
 */
(function($) {

// extend the functality
$.fn.extend( {
	
	// add a function to setup the navigation bar
	fwnNavigation: function(options) {
		// setup default options
		var options = $.extend({
			select: '__FIRST__'
		}, options);
		// run for each item
		return this.each( function() {
			
			// get a jQuery object for the element
			var elem = $(this);
			// get the subnavbar
			var subnav = $(elem.find('.sub_navigation'));

			// add a mouseover action for every element
			elem.find('.main_navigation a').mouseover( function() {
				var e = $(this);
				// deselect/hide items
				elem.find('.main_navigation a').removeClass('selected');
				subnav.find('ul').hide();

				// select this item
				e.addClass('selected');

				// name computation - modified 2010-12-02

				// get the tabs menu name
				var name = e.attr('id');
				if(!name)
					name = $.url.setUrl(e.attr('href')).param('mytabsmenu');
				if(!name)
					name = e.text();
				// if the name exists and the subnav exists, show it
				if(name) {
					name = '#subnav_' + name;
					if($(name).length < 1)
						name = name.toLowerCase();
					if($(name).length > 0)
						$(name).show();
				}
			} );
			
			// if the option is set to select a section, emulate that
			if(options.select)
			{
				// if we want to select the first element
				if(options.select == '__FIRST__')
					elem.find('.main_navigation a:first').mouseover();
				// for others, use ID
				else
					elem.find('.main_navigation ' + options.select).mouseover();
			}
		} );
	}

} );

})(jQuery);

