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

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



        // --------------------------------------------------------------------------------
        //   ADDCLASS
        // --------------------------------------------------------------------------------
        // Activate Tripoli CSS Reset
        $('#bannerArea').addClass('content');
        $('#navigationBottom').addClass('content');
        $('#sidebar1').addClass('content');
        $('#content').addClass('content');
        $('#pageFooter').addClass('content');

        // Apply 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(/\/$/, '') + "$");
        $('#ioConnect-navigation a').each(function() {
            if (urlRegExp.test(this.href.replace(/\/$/, ''))) {
                $(this).addClass('active');
            }
        });


        // --------------------------------------------------------------------------------
        //   PREPEND
        // --------------------------------------------------------------------------------
        $('#modulePage10750067 #content').prepend($('.body'));
        $('#modulePage10750067 #body-text').prepend($('#login-form'));


        // --------------------------------------------------------------------------------
        //   REPLACE TEXT - jquery.ba-replacetext.js
        // --------------------------------------------------------------------------------
        // Replace default <title> seperator with straight line
        $('title').replaceText('-', '|');


        // -- LOGIN --------------------
        // Change 'login' to 'username'
        $('#modulePage10750067 #login-form .fieldTitle').replaceText('Login', 'Username');


        // -- JOURNALS --------------------
        // Modify Journal Nav Text
        $('#modulePage10814420 .journal-entry-navigation-main').replaceText('Main', 'All News');

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


        // ________________________________________
        // Modify SysGen "Read More" Links
        // General
        $('.journal-read-more-tag *').replaceText('Click to read more', 'Learn more');


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


        // ________________________________________
        // Modify Journal Comment Area
        // Captions
        $('h3.caption').replaceText(/\b(Reader Comments)\b/gi, 'Comments');
        $('h3.caption').replaceText(/\b(Post a New Comment)\b/gi, 'Leave a Comment');

        // Submit Buttons
        $('.journal-add-comment-area-wrapper input#createPostButton').attr({
            value: "Submit"
        });

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


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

        // FORM ERRORS
        $('.error-text').replaceText('[ Required field missing. ]', '[Required field missing]');
        $('.formErrorMessage').replaceText('  Navigate above to correct these errors, then click below to re-submit your form', 'Make corrections as indicated and re-submit your form');

        // FORM ERRORS
        $('.error-text').replaceText('[ Required field missing. ]', '[Required field missing]');


        // --  USER PROFILE --------------------
        // MEMBER MANAGEMENT CONTROLS
        $('#member-management-strip-inner .section-title').replaceText('Membership Management', 'Manage Account');

        // MEMBER PROFILE PAGE
        $('div.body').replaceText('This is your author profile page, which contains some details about your account on this website.  You can update your profile details using the buttons below.  Profile details are never made available to the public.', 'You can update your profile information using the buttons below. Profile details are never made available to the public.');
        $('#informationArea .caption').replaceText('Author Information', 'Account Information');



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

        // -- WIDOW RIX --------------------
        $('h3').widowFix();


        // -- EQUAL HEIGHT COLUMNS --------------------
        // iO Connect Landing Page
        $('#modulePage12654764 #bottom-row .column').equalHeightColumns();

    });
});



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

