
/* - showcase.js - */
/*
 *
 */

jQuery(document).ready(function(){	

    // remove the 2nd search box from the library/search papers
    jQuery('#bibSearchForm').remove();
    
    // relocate the search/recent activity links on the discussion boards
    // then delete the 2nd search box from the same
    jQuery('label[for="boardSearch"]').parent().parent().parent().remove().appendTo('#review-history');
    jQuery('label[for="boardSearch"]').parent().parent().remove();

    // remove the 'log in to add software project' button
    jQuery('input[value="Log in to add Software Project"]').parent().remove();

    // jQuery("div.scrollable").scrollable();
    
    jQuery('#searchGadget').attr('value','');
    addBackgroundColor();

    jQuery('.navTree > li').addClass('navTreeHeading');

    // this is index number of the currently active node relative to .navTree
    var numListItems = jQuery('.navTree > li').length;
    var numItemsAfterCurrent;
    var openKwick;
    var noNavOpen = false; 

    if( jQuery('body.section-front-page').length == 1 ) {
        // this is the home page
        // alert( numListItems -1 );
        openKwick = 0;
        noNavOpen = true;
    } else {    
        // not the home page.
        if( jQuery('li[class="navTreeCurrentNode navTreeHeading"]').length == 1 ) {
            // is this one of the main categories selected
            numItemsAfterCurrent = jQuery('ul li[class="navTreeCurrentNode navTreeHeading"]').nextAll().length;
        } else {
            // no, one of the sub-categories is selected
            // numItemsAfterCurrent = jQuery('.navTree li:has(ul li.navTreeCurrentNode)').nextAll( ).length;
            currentNavTreeNode = jQuery('.breadcrumbSeparator:first').next().find('a').text();
            if( currentNavTreeNode.length > 0 ) {  // other than 0, contains the name of the correct navTreeCurrentNode
                numItemsAfterCurrent = jQuery( '.navTree li:contains(' + currentNavTreeNode + ')' ).nextAll().length;
                // jQuery('#viewlet-above-content').html(    "#breadcrumbs = '" + currentNavTreeNode + "' " + numItemsAfterCurrent      );
            } else {
                // this is not the home page, but it sit outside the navigation, so open the 1st item
                numItemsAfterCurrent = jQuery('ul li[class="navTreeHeading"]').nextAll().length;
                noNavOpen = true;
            }
            // and don't forget to highlight the parent li.navTreeHeading
            jQuery('.navTree li:has(ul li.navTreeCurrentNode)').parent('.navTreeHeading').addClass('navTreeCurrentNode');
        }
        openKwick =  (numListItems - numItemsAfterCurrent) -1;
    }

    // navTree Stuffs
    jQuery('.portletNavigationTree .navTree').kwicks({
            min : 30,
            spacing : 2,
            isVertical : true,
            sticky : true,
            event : 'click',
            defaultKwick: openKwick, // open the current menu
            duration: 500
    });

    // prevent the kwick from moving if the user click in the link in the parent li
    jQuery('.navTree > li a').click(function(){
       url = jQuery(this).attr('href');
       window.location = url;
       return false;
    });

    if( noNavOpen ) {
        jQuery('.navTree li.active').removeClass('active');        
        jQuery('.navTreeHome li').addClass('active');        
    }
    // end navTree Stuffs
}); // end: document.ready

function addBackgroundColor() {
    body_classes = jQuery('body').attr('class');
    if( /template-/.test(body_classes) ) {
        // alert( body_classes );
        jQuery('body').attr('class', body_classes + ' withtemplate');
    }
} // end: addBackgroundColor()

