// ##################################################################
function get_rss_feed(feedTitle, outputFeedDiv, rssURL) {
    //clear the content in the div for the next feed.
    $("#" + outputFeedDiv).empty();

    //use the JQuery get to grab the URL from the selected item, put the results in to an argument for parsing in the inline function called when the feed retrieval is complete
    $.get(rssURL, function(d) {

        //find each 'item' in the file and parse it
        $(d).find('item').each(function() {

            //name the current found item this for this particular loop run
            var $item = $(this);
            // grab the post title
            var title = $item.find('title').text();
            // grab the post's URL
            var link = $item.find('link').text();
            // next, the description
            var description = $item.find('description').text();
            //don't forget the pubdate
            var pubDate = $item.find('pubDate').text();

            // now create a var 'html' to store the markup we're using to output the feed to the browser window
            var html = "<div class=\"entry\"><div class=\"postTitle\">" + title + "<\/div>";
            html += "<div class=\"date\"><em>" + pubDate + "</em></div>";
            html += "<div class=\"description\">" + description + "</div>";
            html += "<a href=\"" + link + "\" target=\"_blank\">Read More >><\/a><\/div><br/>";

            //put that feed content on the screen!
            $("#" + outputFeedDiv).append($(html));
        });
    });
};

// ##################################################################
$().ready(function() {

    // make html divs into tabs
    $('.wtTabs').tabs();

    // load home page
    get_rss_feed("CNN Companies", "feedCompanies", "http://rss.cnn.com/rss/money_news_companies.rss");
    get_rss_feed("Yahoo Business", "feedBusiness", "http://in.news.yahoo.com/myyahoo/rss/business-ani.xml");
    get_rss_feed("CNN World", "feedEconomy", "http://rss.cnn.com/rss/cnn_world.rss");
    
    // setup modal dialogs
    //$("#companyFormDiv").jqm();

    // date picker elements
    //$('#FinancialStatusDate').datepicker({ changeYear: true });
    //$('#editFinancialStatusDate').datepicker({ changeYear: true });

    // Set up the navigate controls
    //$("#accordion").accordion({ header: "h5", collapsible: true, autoHeight: false });

});
