$(document).ready(
    function()
    {  
        
        // replace headings with flash alternatives
        sIFR.replaceElement("h1", named( 
                                        {
                                         sFlashSrc: "/tpl/flash/calibri.swf",
                                         sBgColor:  "#ffffff",
                                         sColor:    "#313131",
                                         sCase:     "upper",
                                         sWmode:    "opaque"
                                        }
                                       )
                           );
        /*
        // replace headings with flash alternatives
        sIFR.replaceElement("h2", named( 
                                        {
                                         sFlashSrc: "/tpl/flash/calibri.swf",
                                         sBgColor:  "#ffffff",
                                         sColor:    "#313131",
                                         sCase:     "upper",
                                         sWmode:    "opaque"
                                        }
                                       )
                           );
                                        
        // replace headings with flash alternatives
        /*sIFR.replaceElement("h3", named( 
                                        {
                                         sFlashSrc: "/tpl/flash/calibri.swf",
                                         sBgColor:  "#ffffff",
                                         sColor:    "#313131",
                                         sCase:     "upper",
                                         sWmode:    "opaque"
                                        }
                                       )
                           );*/
        /**
         * Open any link with rel="window" in a new window
         */
        $('a[rel="window"]').click(
            function()
            {
                window.open( this.href );
                return false;
            }
        );
         
        /**
        * The following lines add the css class 'fill' to all form text elements.
        * Needed because IE6 sucks
        */
        if( $.browser.msie == true && $.browser.version < 7 )
        {
            // deal with input text and passwords
            $('.formStyle input').each(
                function()
                {
                    // get input type
                    var inputType = $(this).attr( 'type' );
                    
                    // if it is one of the correct types
                    if( inputType == 'text' || inputType == 'password' )
                    {
                        $(this).addClass( 'fill' );
                    }
                }
            );
            
            // deal with textareas
            $('.formStyle textarea').each(
                function()
                {
                    $(this).addClass( 'fill' );
                }
            );
        }
        
        
        /**
         * The following lines of code append 'jscript/true/' to any anchor with the 'quickPanel'
         * class set.
         *
         * If javascript is disabled this parameter will not be present, and the view pages will display
         * the full navigation.
         */
        $('a.quickPanel').each(
            function()
            {
                // get needed vars
                var uri      = $(this).attr( "href" );
                var uriParts = uri.split("?");
                
                // append javascript flag to uri
                uri = uriParts[0] + "jscript/true/";
                
                // second element of uri parts will be any query string crap - should only be added by thickbox
                if( uriParts[1] != undefined )
                {
                    uri = uri + "?" + uriParts[1];
                }
                
                // replace uri on target anchor
                $(this).attr( "href", uri );
            }
        );
        
        /**
         * Code for left hand navigation menu
         */
        // hide deepest layer of navigation
        $('#leftPanel li ul li ul').hide();
        
        if( insideCoordinatorMenu )
        {
            $('#coordinatorMenu').show();
        }
        if( insideProfileMenu )
        {
            $('#profileMenu').show();
        }
        if( insideMessageMenu )
        {
            $('#messageMenu').show();
        }
        if( insideForumMenu )
        {
            $('#forumMenu').show();
        }
        if( insideFriendsMenu )
        {
            $('#friendsMenu').show();
        }
        if( insideAdviceMenu )
        {
            $('#adviceMenu').show();
        }
        if( insideDocumentsMenu )
        {
            $('#documentsMenu').show();
        }
        if( insideHeadMenu )
        {
            $('#headMenu').show();
        }
        if( insideTasksMenu )
        {
            $('#tasksMenu').show();
        }
        if( insideTrainingMenu )
        {
            $('#trainingMenu').show();
        }
        if( insideChatMenu )
        {
            $('#chatMenu').show();
        }
        if( insideDiaryMenu )
        {
            $('#diaryMenu').show();
        }
        // for each nqt area link
        $('#leftPanel li ul li a').click(
            function()
            {                
                // get rel attribute from link
                var linkRel = $(this).attr( 'rel' );
                                
                // don't do anything if rel is empty
                if( linkRel != undefined )
                {   
                    // remove open icons from all menus   
                    $('#leftPanel li ul li a.leftMenuOpen').each(
                        function()
                        {
                            $(this).removeClass("leftMenuOpen");
                            $(this).addClass("leftMenuClosed");
                        }
                    );
                    
                    // clicking on a hidden menu?
                    if( $('#' + linkRel).is(":hidden") )
                    {
                        $(this).removeClass("leftMenuClosed");
                        $(this).addClass("leftMenuOpen");
                    }
                    else
                    {
                        $(this).removeClass("leftMenuOpen");
                        $(this).addClass("leftMenuClosed");
                    }
                                  
                    // hide deepest layer of navigation for other menu options
                    $('#leftPanel li ul li ul[id!="' + linkRel + '"]').slideUp( 'slow' );
                                       
                    // display appropriate menu
                    $('#' + linkRel).slideToggle( 'slow' );
                }
            }
        );
        
        // assign empty function to sub links
        $('#navMenu li ul li ul li a').unbind( "click" );
        
        //
        $('#addNqt').click(
            function()
            {
                // get current nqt count and increment
                nqtCount = parseInt( $('#nqtcount').val() );
                nqtCount = nqtCount + 1;
                
                // add a new panel
                nqtContent = "<div>" +
                             "<label for='nqt" + nqtCount + "'>Full Name</label>" +
                             "<input type='text' name='nqt" + nqtCount + "' id='nqt" + nqtCount + "' value='' />" +
                             "</div>";
                $('#nqtPanel').append( nqtContent );
                
                // update nqt count
                $('#nqtcount').val( nqtCount );
            }
        );
    }
);
