﻿/************************************** Splendid *************************************
* Created By:		Steve Doggett
* Creation Date:	22nd July 2009
* Edited ----------------------------------------------------------------------------
*      By:              On:  
* Description -----------------------------------------------------------------------
*      This file handles background colours that change to show selected data for a radio button
*      Uses JQuery.
*      Example: 
*           49_delivery.html
*
* Functions -------------------------------------------------------------------------
*       
* Event Handlers --------------------------------------------------------------------
*       tab_onClick()           // Hides and de-selects the old tab and content and shows the new.
*       
**************************************************************************************/

/********************************** Global Variables *********************************/

/************************************** Functions *************************************/
/****
 * Initialises the background swapper for the radio button selects.
 *
 * On the page it needs:
 *  $(document).ready(function(){
 *      initBkgRadioButton(containerDivID);
 *  });
 ****/
function initBkgRadioButton(containerID) {
    var container = $("#" + containerID);

    $.each($("input:radio", container), function() {
        $(this).click(function() {
            onRadioSelect(this, containerID);
        });
        
        var parentNode = $(this).parent();
        $("label", parentNode).click(function() {
            onRadioSelect(this, containerID);
        });
    });
}


/*********************************** Event Handlers ***********************************/
/****
 * Function to actually change the correct item background.
 ****/
function onRadioSelect(which, containerID) {
    $("#" + containerID + " input:radio").parent().removeClass("selected");
    $(which).parent().addClass("selected");
}