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

        // --------------------------------------------------------------------------------
        //   TRIPOLI RESET - IMPORTANT!!!
        // --------------------------------------------------------------------------------
        //$('head').prepend('<link href="/storage/css/tripoli.simple.css" rel="stylesheet" type="text/css" />');
        // --------------------------------------------------------------------------------
        //   ADDCLASS
        // --------------------------------------------------------------------------------
        // Add 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"
        // page title - PAGENAME
        //$('#modulePageIDNUM #content').prepend('<h1 id="pageTitle">Lifestyle</h1>');

        // --------------------------------------------------------------------------------
        //   REPLACE TEXT - jquery.ba-replacetext.js
        // --------------------------------------------------------------------------------
        // Replace default <title> seperator with straight line
        $('title').replaceText(/\b( - )\b/gi, ' / ');
        $('h3.caption').replaceText(/\b(Post a New Comment)\b/gi, 'Join the Conversation');
        $('#modulePage6181306 h3').replaceText(/\b(Request for Proposal)\b/gi, ' ');
        $('h3.caption').replaceText(/\b(Reader Comments)\b/gi, 'Comments');
        $('.journal-read-more-tag *').replaceText(/\b(Click to read more)\b/gi, 'Read more');
        $('#modulePage5619626 .journal-entry-navigation-main').replaceText('Main', 'Grid');
        $('.footer input#createPostButton').attr({
            value: "Post Comment"
        });
        $('input#formSubmitButton5362139').attr({
            value: "Send"
        });
        $('input#formSubmitButton8635264').attr({
            value: "Send"
        });
		// Newsletter Subscription Form Button
        $('input#formSubmitButton12490698').attr({
            value: "Subscribe"
        });
        $('.tag-element a').widowFix();
        $('.email-item a').replaceText(/\b(">)\b/gi, '" rel="shadowbox"');
        $('h2.document-title').replaceText("(Email)", ' ');


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


        // --------------------------------------------------------------------------------
        //  jFEED
        // --------------------------------------------------------------------------------
        jQuery.getFeed({
            // display news category of blog on home page
            url: '/blog/rss.xml?categoryId=2223710',
            success: function(feed) {
                jQuery('#homepage-news-result').append;
                var html = '<ul class="noList">';
                for (var i = 0; i < feed.items.length && i < 3; i++) {
                    var item = feed.items[i];
                    html += '<li>' + '<a href="' + item.link + '">' + item.title + '</a>' + '</li>';
                }
                jQuery('#homepage-news-result').append(html);
            }
        });


    });
});


// --- 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;
};
