/*******************************************************************************
* @author: Tony
* @date: 21/07/09
*
* @function: hide the FAQs answers if they have JS and browser permits
* @parameters: void
* @return: void
*/
function hideFAQs ()
{
    // drop out if code is unsupported
    if (!document.getElementsByTagName) return;

    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // hide the answers
    hideAnswers ();

    // make the clickyness work
    doTheDo ();
}

/*******************************************************************************
* @author: Tony
* @date: 21/07/09
*
* @function: hide the FAQs answers with a loop (dirty boy!)
* @parameters: void
* @return: void
*/
function hideAnswers()
{
    // hide the answers
    var answers = document.getElementsByTagName("div");
    for (var i = 0, answer; answer = answers[i]; i++)
    {
        // check if it's a FAQ link
        if (answer.className == 'answer')
        {
            answer.style.visibility = 'hidden';
            answer.style.position = 'absolute';
            answer.style.width = '1px';
            answer.style.height = '1px';
            answer.style.textIndent = '-9999px';
        }
    }

    // set the questions to un-highlighted format
    var links = document.getElementsByTagName("a");
    for (var i = 0, link; link = links[i]; i++)
    {
        // check if it's a FAQ link
        if (link.className == 'questionIn') link.className = 'question';
    }
}

/*******************************************************************************
* @author: Tony
* @date: 21/07/09
*
* @function: add click-links to the page to show the answers
* @parameters: void
* @return: void
*/
function doTheDo ()
{
    // drop out if code is unsupported
    if (!document.getElementsByTagName) return;

    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    var links = document.getElementsByTagName("a");
    for (var i = 0, link; link = links[i]; i++)
    {
        // check if it's a FAQ link
        if (link.className == 'question')
        {
            link.title = 'Show the answer to this question';
            link.href = "javascript:void(0);";
            link.onmouseup = function ()
            {
                hideAnswers()

                this.className = 'questionIn';

                var idNum = this.id.substr( this.id.indexOf('_') + 1 );

                var answer = document.getElementById('answer_' + idNum);
                answer.style.visibility = 'visible';
                answer.style.position = 'relative';
                answer.style.width = '700px';
                answer.style.height = 'auto';
                answer.style.textIndent = '0px';
            }
        }
    }
}