$(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
        $('div#canvas').addClass('content');

		// Lifestyle and Press "you are here" classes
		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
        // --------------------------------------------------------------------------------

        // page title - LIFESTYLE
        $('#modulePage9883139 #content').prepend('<h1 id="pageTitle">Lifestyle</h1>');

        // page title - PRESS
        $('#modulePage9672669 #content').prepend('<h1 id="pageTitle">Press</h1>');

        // page title - ABOUT
        $('#modulePage8800016 #content').prepend('<h1 id="pageTitle">Meet the Chef / <span>Behind the Scenes</span></h1>');

		// page title - CHEF LALA HOMEMADE
        $('#modulePage13549202 #content').prepend('<h1 id="pageTitle">Chef LaLa Homemade</h1>');

        // Tooltip Arrow - PARTNERS
		// $('#modulePage8796962 .link-group-list .link-list .description').prepend('<span><img src="/storage/images/bg-ttp-arrow-right.png" /></span>');
		
		// --------------------------------------------------------------------------------
        //   APPEND
        // --------------------------------------------------------------------------------

        // LinkWithin Widget - LIFESTYLE
        $('#modulePage9883139 .single-journal-entry-wrapper').after('<div class="linkwithin_div"></div> <script type="text/javascript">var linkwithin_site_id = 738991;</script> <script src="http://www.linkwithin.com/widget.js"></script> <div class="clearer"></div>');

        // LinkWithin Widget - PRESS
        $('#modulePage9672669 .single-journal-entry-wrapper').after('<div class="linkwithin_div"></div> <script type="text/javascript">var linkwithin_site_id = 738983;</script><script src="http://www.linkwithin.com/widget.js"></script><div class="clearer"></div>');
        



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

        $('title').replaceText(' - ', ' | ');

        // correct misspelling of LaLa's name
        $('#pageBody *').replaceText(/\bLala\b/gi, 'LaLa');
        $('#pageBody *').replaceText(/\bChef LaLa Homemade\b/gi,'CHEF\xA0LALA\xA0HOMEMADE');

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

        // modify journal nav text
        $('#modulePage9883139 .journal-entry-navigation-main').replaceText('Main', 'Lifestyle');
        $('#modulePage9672669 .journal-entry-navigation-main').replaceText('Main', 'Press');
		$('#modulePage13549202 .journal-entry-navigation-main').replaceText('Main', 'Products');

        // modify sysGen header text - PRESS
        $('#modulePage9672669 .journal-filter-header h2').replaceText('Entries in', 'Press /');
        $('#modulePage9672669 .journal-filter-header h2').replaceText(/1|2|3|4|5|6|7|8|9|0/gi, '');
        $('#modulePage9672669 .journal-filter-header h2').replaceText('()', '');
        $('#modulePage9672669 .journal-filter-header h2').replaceText(/(Community)/gi, "<span>Community<\/span>");
        $('#modulePage9672669 .journal-filter-header h2').replaceText(/(Events)/gi, "<span>Events<\/span>");
        $('#modulePage9672669 .journal-filter-header h2').replaceText(/(In the News)/gi, "<span>In the News<\/span>");

        // modify sysGen header text - LIFESTYLE
        $('#modulePage9883139 .journal-filter-header h2').replaceText('Entries in', 'Lifestyle / ');
        $('#modulePage9883139 .journal-filter-header h2').replaceText(/1|2|3|4|5|6|7|8|9|0/gi, '');
        $('#modulePage9883139 .journal-filter-header h2').replaceText('()', '');
        $('#modulePage9883139 .journal-filter-header h2').replaceText(/(Articles)/gi, "<span>Articles<\/span>");
        $('#modulePage9883139 .journal-filter-header h2').replaceText(/(On Health)/gi, "<span>On Health<\/span>");
        $('#modulePage9883139 .journal-filter-header h2').replaceText(/(Quick Tips)/gi, "<span>Quick Tips<\/span>");
        $('#modulePage9883139 .journal-filter-header h2').replaceText(/(Recipes)/gi, "<span>Recipes<\/span>");
        $('#modulePage9883139 .journal-filter-header h2').replaceText(/(Videos)/gi, "<span>Videos<\/span>");
		
		// modify sysGen header text - CHEF LALA HOMEMADE
        $('#modulePage13549202 .journal-filter-header h2').replaceText('Entries in', 'Chef LaLa Homemade / ');
        $('#modulePage13549202 .journal-filter-header h2').replaceText(/1|2|3|4|5|6|7|8|9|0/gi, '');
        $('#modulePage13549202 .journal-filter-header h2').replaceText('()', '');
        $('#modulePage13549202 .journal-filter-header h2').replaceText(/(Marinades)/gi, "<span>Marinades<\/span>");
        $('#modulePage13549202 .journal-filter-header h2').replaceText(/(Flavored Oils)/gi, "<span>Flavored Oils<\/span>");
        $('#modulePage13549202 .journal-filter-header h2').replaceText(/(Sauces)/gi, "<span>Sauces<\/span>");

		// COOKBOOKS
        $('#amazonItem191526 .title').replaceText('Chef LaLa Presents Best Loved Mexican Cooking (Best Loved)', 'Best Loved Mexican Cooking');

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

        // Articles / On Health
        $('#modulePage9883139 .category-recipes .journal-read-more-tag *').replaceText('Continue Reading', 'Get the Recipe');

        // Recipes
        $('#modulePage9883139 .category-recipes .journal-read-more-tag *').replaceText('Continue Reading', 'Get the Recipe');

        // Videos
        $('#modulePage9883139 .category-recipes.category-videos .journal-read-more-tag *').replaceText('Get the Recipe', 'Watch the Video');
        $('#modulePage9883139 .category-videos .journal-read-more-tag *').replaceText('Continue Reading', 'Watch the Video');

        // Chef LaLa Homemade
        $('#modulePage13549202 .journal-read-more-tag *').replaceText('Continue Reading', 'Learn more');


        // modify "send email"
        $('h2.document-title').replaceText("(Email)", ' ');

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

        // Journal Tags Archive Page Titles
        $('h2.document-title').replaceText(/(Press Archive)/gi, "Press / <span>Archive<\/span>");
        $('h2.document-title').replaceText(/(Lifestyle Archive)/gi, "Lifestyle / <span>Archive<\/span>");
        $('h2.document-title').replaceText(/(Press Tags)/gi, "Press / <span>Tag Listing<\/span>");
        $('h2.document-title').replaceText(/(Lifestyle Tags)/gi, "Lifestyle / <span>Category Listing<\/span>");


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

        // remove the word "contact" from  titles in folder module
        $('.folder-item-list h3 *').replaceText('Contact', '  ');

        // modify HTML of form titles for styling in form pages
        $('h2.document-title').replaceText(/(Contact Management & Bookings)/gi, "Contact / <span>Management & Bookings<\/span>");
        $('h2.document-title').replaceText(/(Contact Public Relations)/gi, "Contact / <span>Public Relations<\/span>");
        $('h2.document-title').replaceText(/(Contact Tech Support)/gi, "Contact / <span>Tech Support<\/span>");
        $('h2.document-title').replaceText(/(Contact Chef LaLa)/gi, "Contact / <span>Chef LaLa<\/span>");

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



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

        // -- TOGGLE SECTION --------------------

	    function togglecomments (postid) {
		  var whichpost = document.getElementById(postid);   
		    if (whichpost.className=="showThis") { 
		      whichpost.className="hideThis"; 
		    }     
		    else { whichpost.className="showThis"; }
		}


        // -- NO WIDOWS (jquery.widowFix-1.2.js) --------------------
        $(".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()


		// --- PAGE NOT FOUND / 404 --------------------

		// var redirectURL = "http://cheflala.squarespace.com/404/";
		//   if(document.title == "Page Not Found | " + Squarespace.Constants.WEBSITE_TITLE){
		//     location = redirectURL;
		//   };

    });
});


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


