// AidArena Tips
// By: David Rugendyke
// 2009

// Scan for tips and add them if found
// Special Radio Box version - Leaves tips while current radio is selected
// Works on multiple radio box groups on the same page - damn i'm good!

// Each tip for a radio item must be referenced by the id...  'radioTip_[ID-OF-RADIO-BOX-TIP-IS-FOR]'
// Eg: - The radio button ID 'shipMethod'
//     - The HTML for the tip <div id="radioTip_shipMethod" class="radioTip">Tip Text In Here</div>

// Tips Class
var radioTips = new Class({
	
	// Initialise the class
    initialize: function(){
		
		// Now add the mouseover events
		this.tipEvents();
    },
	
	// Adds events to all the main menu items
	tipEvents: function(){

		var Ob = this;
		var tipItem = $$('.radioText'); 
		var radioUniqueGroup = new Array();
			
		// Get the name of all radio boxs
		var radioGroups = $$('input[type=radio]').get('name');
		
		radioGroups.each(function(name) {
				// Add that radio group to an array so we don't add events to them again - only adds them if not already present
				radioUniqueGroup.include(name);				
		});
		
			
		// Now loop through our radio button groups
		radioUniqueGroup.each(function(radioName) {
		
			// Now get all its radio friends that share the same name
			var radioFriends = $$('input[type=radio][name='+radioName+']');
			
				// Attach an event to the input field
			radioFriends.each(function(radio) {
				
				// The id of the tip for the radio button
				var radioTipID = 'radioTip_'+$(radio).get('id');
				// Hide the tips to start with
				if($(radioTipID)) {
					$(radioTipID).setStyle('display', 'none');
				}
		
				 $(radio).addEvents({	
	
						'click': function(){
							
							// Now hide all the other tips from this group
							radioFriends.each(function(radioHide) { 
									// The id of the tip for the radio button
									var hideTipID = 'radioTip_'+$(radioHide).get('id');
									if($(hideTipID)) { $(hideTipID).setStyle('display', 'none'); }
							});
							
							// Click on the radio, show the tip
							if($(radioTipID)) {
								$(radioTipID).setStyle('display', 'block');
							}
		
						}	
					});
					
			}); // End array loop
			
			
		});
		
	}
	
});
