var $j = jQuery.noConflict();

$j(document).ready(function () {

    $j('.flexslider').flexslider({
        controlsContainer: ".control-container",
        manualControls: ".flex-control-nav",
        pauseOnHover: true,
        slideshow: false,
        animation: "slide"
    });
    $j('.megamenu').megamenu({
        'enable_js_shadow': false,
        width: '772px'
    });

    $j('#carousel').carousel({
        itemsPerPage: 3,
        itemsPerTransition: 3,
        easing: 'linear',
        pagination: false
    });

    $j('#tabs').tabs();


    $j("#events_feed").jGFeed({
        url: "http://www.katytraildallas.org/feed/rss2_0/stories.rss",
        num: 3
    }, function (feed) {
        var htmlOut = "";
        for (var i = 0; i < feed.entries.length; i++) {
            var d = new Date(feed.entries[i].publishedDate);
            var date = (d.getMonth() + 1) + "." + d.getDate() + "." + (d.getFullYear() - 2000);
            var title = feed.entries[i].title;
            var copy = feed.entries[i].contentSnippet;

            // this line replaces the last ... of the snippet with a link to the blog.
            // if it's not needed, just comment it out

            copy = copy.replace(/[.]{3}$/, "<a href=\"" + feed.entries[i].link + "\" target=\"_blank\">...</a>");

            htmlOut += "<span class=\"date\">" + date + "</span>";
            htmlOut += "<span class=\"title\">" + title + "</span>";
            htmlOut += "<span class=\"copy\">" + copy + "</span>";
        }
        $j("#events_feed").html(htmlOut);
    });


    $j("#blog_feed").jGFeed({
        url: "http://katytraildallas.blogspot.com/feeds/posts/default?format=atom",
        num: 3
    }, function (feed) {
        var htmlOut = "";
        for (var i = 0; i < feed.entries.length; i++) {
            var d = new Date(feed.entries[i].publishedDate);
            var date = (d.getMonth() + 1) + "." + d.getDate() + "." + (d.getFullYear() - 2000);
            var title = feed.entries[i].title;
            var copy = feed.entries[i].contentSnippet;

            // this line replaces the last ... of the snippet with a link to the blog.
            // if it's not needed, just comment it out

            copy = copy.replace(/[.]{3}$/, "<a href=\"" + feed.entries[i].link + "\" target=\"_blank\">...</a>");

            htmlOut += "<span class=\"date\">" + date + "</span>";
            htmlOut += "<span class=\"title\">" + title + "</span>";
            htmlOut += "<span class=\"copy\">" + copy + "</span>";
        }
        $j("#blog_feed").html(htmlOut);
    });

    $j("#twitter_feed").jGFeed({
        url: "http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=katytrail",
        num: 3
    }, function (feed) {
        var htmlOut = "";
        for (var i = 0; i < feed.entries.length; i++) {
            var d = new Date(feed.entries[i].publishedDate);
            var date = (d.getMonth() + 1) + "." + d.getDate() + "." + (d.getFullYear() - 2000);
            var title = feed.entries[i].title;
            var copy = feed.entries[i].contentSnippet;

            title = title.split(/:/)[0];


            // this line replaces the last ... of the snippet with a link to the blog.
            // if it's not needed, just comment it out
            copy = copy.replace(/^.*^(.*?):/i, "");
            copy = copy.replace(/[.]{3}$/, "<a href=\"" + feed.entries[i].link + "\" target=\"_blank\">...</a>");
            copy = copy.replace(/^\s\s*/, '').replace(/\s\s*$/, '');

            htmlOut += "<span class=\"date\">" + date + "</span>";
            htmlOut += "<span class=\"title\">" + title + "</span>";
            htmlOut += "<span class=\"copy\">" + copy + "</span>";
        }
        $j("#twitter_feed").html(htmlOut);
    });

});
