// jQuery plugin for Prod30 <RADIO_COLLAPSE_MENU> tag.
//
// v1.0 -- 04/27/2010 -- initial version.
// v1.1 -- 04/27/2010 -- changed div.label to div.button.
// v1.2 -- 04/28/2010 -- added hitbox tracking.
// v1.3 -- 04/29/2010 -- BUGFIX: Call to _hbLink had wrong parameter.
// v1.4 -- 05/19/2010 -- BUGFIX: All child menus are now reset when a change link is clicked.

(function($) {

	var self = this;

	$.fn.RadioCollapseMenu = function(params) {
		// Specify default settings here.
		var config = {
		};
 
		if (params)
			$.extend(config, params);

		// Iterate over the selected elements here.
		this.each(function () {

			var id = this.id;

			// Add event handler to radio buttons to SHOW content and HIDE navigation.
			$('div#' + id + ' > div.selection > div.button > input').each(function () {
				$(this).click(function () {
					self.hbxLink(this.id);
					$(this).parent().parent().parent().children('div.title').css('display', 'none');
					$(this).parent().parent().parent().children('div.selection').children('div.button').css('display', 'none');
					$(this).parent().parent().children('div.change, div.content').css('display', 'block');
				});
			});

			// Add event handler to change link to HIDE content and SHOW navigation.
			$('div#' + id + ' > div.selection > div.change > div.change_link > a').each(function () {
				$(this).click(function () {
					self.hbxLink(this.id);
					$(this).parent().parent().parent().parent().find('div.title').css('display', 'block');
					$(this).parent().parent().parent().parent().find('div.button').css('display', 'block');
					$(this).parent().parent().parent().parent().find('div.change, div.content').css('display', 'none');
				});
			});

		});
 
		return this;
 
	};

	this.hbxLink = function (linkId) {
		if ( typeof(_hbLink) !== 'undefined' )
			_hbLink(linkId);
	};
 
})(jQuery);
