// JavaScript Document
$(document).ready(function() {
  $(function() {

    // --------------------------------------------------------------------------------
    //   ADDCLASS
    // --------------------------------------------------------------------------------

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


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

    // -- PAGE TITLES --------------------
    // Add Page Titles to Pages Without Titles or That Don't Allow for "Modify Header"
    $('#modulePage11055168 .single-journal-entry-wrapper').prepend('<h2 class="document-title">Portfolio</h2>');


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

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


    // -- JOURNALS --------------------

    // ________________________________________
    // Modify SysGen "Read More" Links
    // General
    $('.journal-read-more-tag *').replaceText('Click to read more', 'Continue Reading');
    $('.p7EPM54 .journal-read-more-tag *').replaceText('Click to read more', 'See Samples');
    $('#modulePage7103870 .journal-entry-navigation *').replaceText('Main', 'Index');
    $('#modulePage11055168 .journal-entry-navigation').replaceText('Main', 'Index');
    $('#modulePage11055168 .journal-entry-navigation').replaceText('|', ' ');

    // Modify Sysgen Header Journal Filter Tag/Category Text
    $('#modulePage11055168 .journal-filter-header h2').replaceText('Entries in', '');
    $('#modulePage11055168 .journal-filter-header h2').replaceText(/1|2|3|4|5|6|7|8|9|0/gi, '');
    $('#modulePage11055168 .journal-filter-header h2').replaceText('()', '');


    // ________________________________________
    // 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
    // --------------------------------------------------------------------------------

    // -- PAGE NOT FOUND REDIRECT --------------------
    var redirectURL = "http://looselyrelated.com/error/";
    if (document.title == "Page Not Found" + Squarespace.Constants.WEBSITE_TITLE) {
      location = redirectURL;
    };


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


    // --------------------------------------------------------------------------------
    //  jFEED
    // --------------------------------------------------------------------------------

    jQuery(function() {

      jQuery.getFeed({
        url: '/portfolio/rss.xml',
        success: function(feed) {
          jQuery('#result-recent-projects-sb');
          var html = '';
          for (var i = 0; i < feed.items.length && i < 2; i++) {
            var item = feed.items[i];
            html += '<li>' + '<a href="' + item.link + '" title="' + item.title + '">' + item.description + '</a>' + '</li>';
          }
          jQuery('#result-recent-projects-sb').append(html);
        }
      });
    });
  });
});
