var globalFunctions = {

    // Apply correct class if the realted content exists
    contentWidthAsRelatedContent: function()
    {
    var relatedContent = jQuery('#content_related .related_text').text().length;
    if (relatedContent === 0) {
        jQuery('#content_main').addClass('content_main_fullWidth');
    } else if (relatedContent !== 0) {
        jQuery('#content_main').addClass('content_main_halfWidth');
        jQuery('#content_related').removeClass('hide');
    } //end else

    }, // End contentWidthAsRelatedContent


    attachGoogleAnalyticsDownloadEvent: function()
    {    
      // get the link attribute and find the filename of the PDF  
      jQuery('[href$="pdf"]').live("click", function()
      {        
         var pdfLink = $(this).attr("href"), pdfLocation = pdfLink.substr(pdfLink.lastIndexOf("/")).replace("/","");
         _gaq.push(['_trackPageview', pdfLocation]); 
      }); 
    }, //End attachGoogleAnalyticsDownloadEvent


    // Remove the doctype option from publication search
    publicaionSearch: function()
    {
    if($('#search_page_13137').length) {
        jQuery('#queries_type_query option').each(function () {
            if ($(this).text() === 'docType') {
                $(this).remove();
            }
        });
    }//end if
    }, //End publicaionSearch





    // Place all the small JS opertaions here
    otherSmallFunctions: function()
    {
      // For Report Planning section, if Glossary table exists then add class to second column
      if(jQuery('.glossaryTable').length){
          jQuery('.glossaryTable tr').each(function() {
              jQuery(this).find('td:eq(1)').addClass('abbr');
          });
      }

      // If pagination has only one child hide it
        if($("#pagination").length){
            if($("#pagination ul li").length == 1)
            {
               $("#pagination").hide();
            }
            else {
            //Do Nothing
            }
            //Hide the pagination link if they are empty
            jQuery('#pagination a').each(function() {
                if(jQuery(this).attr('href').length === 0) {
                    jQuery(this).hide();
                }
            });
        }//End If #pagination exists

    } //End otherSmallFunctions

}; //End globalFunctions JSON



jQuery(document).ready( function(){

    globalFunctions.contentWidthAsRelatedContent();
  //  globalFunctions.attachGoogleAnalyticsDownloadEvent();
    globalFunctions.publicaionSearch();
    globalFunctions.otherSmallFunctions();


}); // End Document Ready
