﻿/************************************** Splendid *************************************
* Created By:		Steve Doggett
* Creation Date:	22nd July 2009
* Edited ----------------------------------------------------------------------------
*      By:              On:  
* Description -----------------------------------------------------------------------
*      This file handles tabbed information panels functionality
*      Uses JQuery.
*      Example: 
*           14-product-detail.html
*
* Functions -------------------------------------------------------------------------
*       
* Event Handlers --------------------------------------------------------------------
*       tab_onClick()           // Hides and de-selects the old tab and content and shows the new.
*       
**************************************************************************************/

/********************************** Global Variables *********************************/
$(document).ready(function() {
    $(".tab").click(function() {
        tab_onClick(this);
        return false;
    });

    // They all show by default, so hide all but the first one on the page...
    $(".withTab ul:gt(0)").hide();
});

/************************************** Functions *************************************/


/*********************************** Event Handlers ***********************************/

/****
 * Handles the click event on a tab link
 * Hides and de-selects the old tab and content and shows the new.
 ****/
function tab_onClick(which) {
    /* Assumes the structure is:
        <div>
            <ul>
                <li>Tab 1</li>
                <li>Tab 2</li>
            </ul>
        </div>
    */
   
    var oldTab = $(".withTab", $(which).parent().parent())
    $(oldTab).removeClass('selected');
    $("ul", oldTab).hide();

    var newTab = $(which).parent();
    $(newTab).addClass('selected');
    $("ul", newTab).show();
}