
var common = {

    init: function() {

        //help toggling
        //////////////////////////////////

        jQuery('.questionHelpButton').click(function() {

            var parentElement = jQuery(this).parent();

            var shortElement = parentElement.find('.helpShort');
            var longElement = parentElement.find('.helpLong');

            if(shortElement.is(':visible')) {

                longElement.slideDown('fast');

                shortElement.slideUp('fast');

                if (jQuery('body.lang-en').length > 0) {

                    jQuery(this).html('Less');

                } else if (jQuery('body.lang-ct').length > 0) {

                    jQuery(this).html('減少');

                } else if (jQuery('body.lang-cs').length > 0) {

                    jQuery(this).html('减少');

                }

            } else {

                shortElement.slideDown('fast');

                longElement.slideUp('fast');

                if (jQuery('body.lang-en').length > 0) {

                    jQuery(this).html('More');

                } else if (jQuery('body.lang-ct').length > 0) {

                    jQuery(this).html('更多');

                } else if (jQuery('body.lang-cs').length > 0) {

                    jQuery(this).html('更多');

                }

            }

        });

        //top nav line switcher
        ///////////////////////

        jQuery('#topNav a').mouseenter(function() {

            common.topNavHighlightOn(this);

        });

        jQuery('#topNav a').mouseleave(function() {

            common.topNavHighlightOff();

        });

        //Set the underline off immediately
        jQuery('#topNav a.active').mouseenter();

        //collapsible text content
        //////////////////////////////////

        jQuery('body.lang-en div.collapsible')
            .hide()
            .append('<button class="closeCollapsibleText">Close</button>');


        jQuery('body.lang-ct div.collapsible')
            .hide()
            .append('<button class="closeCollapsibleText">關閉</button>');


        jQuery('body.lang-cs div.collapsible')
            .hide()
            .append('<button class="closeCollapsibleText">关闭</button>');



        jQuery('.uncollapse').click(function() {

            jQuery(this)
                .parents('p').first()
                .nextAll('div.collapsible').first()
                .slideToggle('fast');

            jQuery('button.closeCollapsibleText').click(function() {

                jQuery(this).parents('div.collapsible').first().slideUp('fast');

            });

        });

    },

    topNavHighlightOn: function(el) {

        var left = jQuery(el).position().left;
        var width = jQuery(el).width();

        left = left - 25;
        width = width + 10;

        jQuery('#topNavBarHighlight').show();
        jQuery('#topNavBarHighlight').css('left', left + 'px');
        jQuery('#topNavBarHighlight').css('width', width + 'px');

    },

    topNavHighlightOff: function() {

        jQuery('#topNavBarHighlight').hide();

        jQuery('#topNav a.active').mouseenter();

    }

};

function getThrobber()
{

    return '<img class="throbber" src="' + BASE + 'img/frontend/throbber.gif" width="16" height="16" alt="Loading" />';

}

function removeThrobber()
{

    jQuery('img.throbber').remove();

}
