// JavaScript Document

$(document).ready(function() {
  $(function() {

    // --------------------------------------------------------------------------------
    //   TRIPOLI RESET - IMPORTANT!!!
    // --------------------------------------------------------------------------------

    $('head').prepend('<link href="/storage/css/tripoli.simple.css" rel="stylesheet" type="text/css" />');
    
    
            
    // --------------------------------------------------------------------------------
    //   ADDCLASS
    // --------------------------------------------------------------------------------

    // Apply ClearFix
    $('#canvasWrapper').addClass('clearfix');
	$('#pageBody').addClass('clearfix');
    $('#contentWrapper').addClass('clearfix');
    $('#pageFooterWrapper').addClass('clearfix');

    // Add class to manual subnav for "you are here"
    var url = window.location.pathname,
    urlRegExp = new RegExp(url.replace(/\/$/, '') + "$");
    // create regexp to match current url pathname and 
    // remove trailing slash if present as it could collide 
    // with the link in navigation in case trailing slash wasn't present there
    // then grab every link from the navigation
    $('.archive-item-list-pt a').each(function() {
      // and test its normalized href against the url pathname regexp
      if (urlRegExp.test(this.href.replace(/\/$/, ''))) {
        $(this).addClass('you-are-here');
      }
    });


    // --------------------------------------------------------------------------------
    //   PREPEND
    // --------------------------------------------------------------------------------



    // --------------------------------------------------------------------------------
    //   REPLACE TEXT - jquery.ba-replacetext.js
    // --------------------------------------------------------------------------------

    // Replace default <title> seperator with straight line
    $('title').replaceText(' - ', ' | ');


    // ________________________________________
    // Modify SysGen "Read More" Links 

    // General
    $('.journal-read-more-tag *').replaceText('Click to read more', 'Continue Reading');

    // Modify "Send Email" Title
    $('h2.document-title').replaceText("(Email)", ' ');


    // ________________________________________ 
    // Modify Journal Archives Titles 

    // Lifestyle
    // $('#modulePageIDNUM .journal-archive-set').replaceText('Entries', 'Archives');
    // $('#modulePageIDNUM .journal-archive-set').replaceText('Entries', 'Archives');
    $('#content h3 *').replaceText(/\bEntries\b/gi, 'Archives');

    // ________________________________________ 
    // Modify Journal Comment Area

    // Captions
    $('h3.caption').replaceText(/\b(Reader Comments)\b/gi, 'Comments');

    // Submit Buttons
    $('.footer input#createPostButton').attr({
      value: "Comment"
    });

    $('.footer input#previewPostButton').attr({
      value: "Preview"
    });


    // -- CONTACT FORMS --------------------

    // modify submit button
    $('.notice-box input.submit-button').attr({
      value: "Send"
    });



    // --------------------------------------------------------------------------------
    //  MISCELLANY
    // --------------------------------------------------------------------------------


    // -- NO WIDOWS (jquery.widowFix-1.2.js) --------------------
    
    // Be careful with this… it F's up lots of things
    // $(".standard thead th, .standard th").each(function() {
    //   var wordArray = $(this).text().split(" ");
    //   var finalTitle = "";
    //   for (i = 0; i <= wordArray.length - 1; i++) {
    //     finalTitle += wordArray[i];
    //     if (i == (wordArray.length - 2)) {
    //       finalTitle += " ";
    //     } else {
    //       finalTitle += " ";
    //     }
    //   }
    //   $(this).html(finalTitle);
    // });


    // -- TRIM EMPTY PARAGRAPH TAGS --------------------
    $("p").filter(function() {
      return $.trim($(this).html()) == '';
    }).remove()


  });
});


// --- EQUAL HEIGHT COLUMNS --------------------
// http://www.cre8ivecommando.com/equal-height-columns-using-jquery-6164/
// $.fn.sameHeights = function() {
// 
//   $(this).each(function() {
//     var tallest = 0;
// 
//     $(this).children().each(function(i) {
//       if (tallest < $(this).height()) {
//         tallest = $(this).height();
//       }
//     });
//     $(this).children().css({
//         'height': tallest
//     });
//   });
//   return this;
// };

